pgraphicsopengl.java

来自「This is processing for java examples.」· Java 代码 · 共 2,167 行 · 第 1/5 页

JAVA
2,167
字号
    /**     * Implementation of the GLU_TESS_COMBINE callback.     * @param coords is the 3-vector of the new vertex     * @param data is the vertex data to be combined, up to four elements.     * This is useful when mixing colors together or any other     * user data that was passed in to gluTessVertex.     * @param weight is an array of weights, one for each element of "data"     * that should be linearly combined for new values.     * @param outData is the set of new values of "data" after being     * put back together based on the weights. it's passed back as a     * single element Object[] array because that's the closest     * that Java gets to a pointer.     */    public void combine(double[] coords, Object[] data,                        float[] weight, Object[] outData) {      //System.out.println("coords.length = " + coords.length);      //System.out.println("data.length = " + data.length);      //System.out.println("weight.length = " + weight.length);      //for (int i = 0; i < data.length; i++) {      //System.out.println(i + " " + data[i].getClass().getName() + " " + weight[i]);      //}      double[] vertex = new double[coords.length];      vertex[0] = coords[0];      vertex[1] = coords[1];      vertex[2] = coords[2];      //System.out.println("combine " +      //                 vertex[0] + " " + vertex[1] + " " + vertex[2]);      // this is just 3, so nothing interesting to bother combining      //System.out.println("data length " + ((double[]) data[0]).length);      // not gonna bother doing any combining,      // since no user data is being passed in.      /*      for (int i = 3; i < 6; i++) {        vertex[i] =          weight[0] * ((double[]) data[0])[i] +          weight[1] * ((double[]) data[1])[i] +          weight[2] * ((double[]) data[2])[i] +          weight[3] * ((double[]) data[3])[i];      }      */      outData[0] = vertex;    }  }  //////////////////////////////////////////////////////////////  // MATRIX MATH  //public void pushMatrix()  //public void popMatrix()  //public void translate(float tx, float ty)  //public void translate(float tx, float ty, float tz)  //public void rotate(float angle)  //public void rotateX(float angle)  //public void rotateY(float angle)  //public void rotateZ(float angle)  //public void rotate(float angle, float vx, float vy, float vz)  //public void scale(float s)  //public void scale(float sx, float sy)  //public void scale(float x, float y, float z)  //public void resetMatrix()  //public void applyMatrix(PMatrix2D source)  //public void applyMatrix(float n00, float n01, float n02,  //                        float n10, float n11, float n12)  //public void applyMatrix(PMatrix3D source)  //public void applyMatrix(float n00, float n01, float n02, float n03,  //                        float n10, float n11, float n12, float n13,  //                        float n20, float n21, float n22, float n23,  //                        float n30, float n31, float n32, float n33)  //public getMatrix(PMatrix2D target)  //public getMatrix(PMatrix3D target)  //public void setMatrix(PMatrix2D source)  //public void setMatrix(PMatrix3D source)  //public void printMatrix()  //public void beginCamera()  //public void endCamera()  //public void camera()  //public void camera(float eyeX, float eyeY, float eyeZ,  //                   float centerX, float centerY, float centerZ,  //                   float upX, float upY, float upZ)  //public void printCamera()  //public void ortho()  //public void ortho(float left, float right,  //                  float bottom, float top,  //                  float near, float far)  //public void perspective()  //public void perspective(float fov, float aspect, float near, float far)  //public void frustum(float left, float right,  //                    float bottom, float top,  //                    float near, float far)  //public void printProjection()  //public float screenX(float x, float y)  //public float screenY(float x, float y)  //public float screenX(float x, float y, float z)  //public float screenY(float x, float y, float z)  //public float screenZ(float x, float y, float z)  //public float modelX(float x, float y, float z)  //public float modelY(float x, float y, float z)  //public float modelZ(float x, float y, float z)  //////////////////////////////////////////////////////////////  // STYLES  //public void pushStyle()  //public void popStyle()  //public void style(PStyle)  //public PStyle getStyle()  //public void getStyle(PStyle)  //////////////////////////////////////////////////////////////  // COLOR MODE  //public void colorMode(int mode)  //public void colorMode(int mode, float max)  //public void colorMode(int mode, float mx, float my, float mz);  //public void colorMode(int mode, float mx, float my, float mz, float ma);  //////////////////////////////////////////////////////////////  // COLOR CALC  //protected void colorCalc(int rgb)  //protected void colorCalc(int rgb, float alpha)  //protected void colorCalc(float gray)  //protected void colorCalc(float gray, float alpha)  //protected void colorCalc(float x, float y, float z)  //protected void colorCalc(float x, float y, float z, float a)  //protected void colorCalcARGB(int argb, float alpha)  //////////////////////////////////////////////////////////////  // STROKE CAP/JOIN/WEIGHT  public void strokeWeight(float weight) {    this.strokeWeight = weight;  }  public void strokeJoin(int join) {    if (join != DEFAULT_STROKE_JOIN) {      showMethodWarning("strokeJoin");    }  }  public void strokeCap(int cap) {    if (cap != DEFAULT_STROKE_CAP) {      showMethodWarning("strokeCap");    }  }  //////////////////////////////////////////////////////////////  // STROKE, TINT, FILL  //public void noStroke()  //public void stroke(int rgb)  //public void stroke(int rgb, float alpha)  //public void stroke(float gray)  //public void stroke(float gray, float alpha)  //public void stroke(float x, float y, float z)  //public void stroke(float x, float y, float z, float a)  //protected void strokeFromCalc()  //public void noTint()  //public void tint(int rgb)  //public void tint(int rgb, float alpha)  //public void tint(float gray)  //public void tint(float gray, float alpha)  //public void tint(float x, float y, float z)  //public void tint(float x, float y, float z, float a)  //protected void tintFromCalc()  //public void noFill()  //public void fill(int rgb)  //public void fill(int rgb, float alpha)  //public void fill(float gray)  //public void fill(float gray, float alpha)  //public void fill(float x, float y, float z)  //public void fill(float x, float y, float z, float a)  protected void fillFromCalc() {    super.fillFromCalc();    calcColorBuffer();    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE,                    colorBuffer, 0);  }  //////////////////////////////////////////////////////////////  // MATERIAL PROPERTIES//  public void ambient(int rgb) {//    super.ambient(rgb);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, colorBuffer, 0);//  }//  public void ambient(float gray) {//    super.ambient(gray);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, colorBuffer, 0);//  }//  public void ambient(float x, float y, float z) {//    super.ambient(x, y, z);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, colorBuffer, 0);//  }  protected void ambientFromCalc() {    super.ambientFromCalc();    calcColorBuffer();    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, colorBuffer, 0);  }//  public void specular(int rgb) {//    super.specular(rgb);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, colorBuffer, 0);//  }//  public void specular(float gray) {//    super.specular(gray);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, colorBuffer, 0);//  }//  public void specular(float x, float y, float z) {//    super.specular(x, y, z);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, colorBuffer, 0);//  }  protected void specularFromCalc() {    super.specularFromCalc();    calcColorBuffer();    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, colorBuffer, 0);  }  public void shininess(float shine) {    super.shininess(shine);    gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, shine);  }//  public void emissive(int rgb) {//    super.emissive(rgb);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, colorBuffer, 0);//  }//  public void emissive(float gray) {//    super.emissive(gray);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, colorBuffer, 0);//  }//  public void emissive(float x, float y, float z) {//    super.emissive(x, y, z);//    calcColorBuffer();//    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, colorBuffer, 0);//  }  protected void emissiveFromCalc() {    super.emissiveFromCalc();    calcColorBuffer();    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, colorBuffer, 0);  }  //////////////////////////////////////////////////////////////  // LIGHTING  // We're not actually turning on GL lights right now  // because our home-grown ones work better for now.//  public void lights() {//    super.lights();//    gl.glEnable(GL.GL_LIGHTING);//  }//  public void noLights() {//    super.noLights();//    gl.glDisable(GL.GL_LIGHTING);//  }  public void ambientLight(float r, float g, float b) {    super.ambientLight(r, g, b);    glLightEnable(lightCount - 1);    glLightAmbient(lightCount - 1);    glLightPosition(lightCount - 1);    glLightFalloff(lightCount - 1);  }  public void ambientLight(float r, float g, float b,                           float x, float y, float z) {    super.ambientLight(r, g, b, x, y, z);    glLightEnable(lightCount - 1);    glLightAmbient(lightCount - 1);    glLightPosition(lightCount - 1);    glLightFalloff(lightCount - 1);  }  public void directionalLight(float r, float g, float b,                               float nx, float ny, float nz) {    super.directionalLight(r, g, b, nx, ny, nz);    glLightEnable(lightCount - 1);    glLightNoAmbient(lightCount - 1);    glLightDirection(lightCount - 1);    glLightDiffuse(lightCount - 1);    glLightSpecular(lightCount - 1);    glLightFalloff(lightCount - 1);  }  public void pointLight(float r, float g, float b,                         float x, float y, float z) {    super.pointLight(r, g, b, x, y, z);    glLightEnable(lightCount - 1);    glLightNoAmbient(lightCount - 1);    glLightPosition(lightCount - 1);    glLightDiffuse(lightCount - 1);    glLightSpecular(lightCount - 1);    glLightFalloff(lightCount - 1);  }  public void spotLight(float r, float g, float b,                        float x, float y, float z,                        float nx, float ny, float nz,                        float angle, float concentration) {    super.spotLight(r, g, b, x, y, z, nx, ny, nz, angle, concentration);    glLightNoAmbient(lightCount - 1);    glLightPosition(lightCount - 1);    glLightDirection(lightCount - 1);    glLightDiffuse(lightCount - 1);    glLightSpecular(lightCount - 1);    glLightFalloff(lightCount - 1);    glLightSpotAngle(lightCount - 1);    glLightSpotConcentration(lightCount - 1);  }  public void lightFalloff(float constant, float linear, float quadratic) {    super.lightFalloff(constant, linear, quadratic);    glLightFalloff(lightCount);  }  public void lightSpecular(float x, float y, float z) {    super.lightSpecular(x, y, z);    glLightSpecular(lightCount);  }  protected void lightPosition(int num, float x, float y, float z) {    super.lightPosition(num, x, y, z);    glLightPosition(num);  }  protected void lightDirection(int num, float x, float y, float z) {    super.lightDirection(num, x, y, z);    glLightDirection(num);  }  private void glLightAmbient(int num) {//    lightBuffer.put(lightDiffuse[num]);//    lightBuffer.rewind();//    gl.glLightfv(GL.GL_LIGHT0 + num,//                 GL.GL_AMBIENT, lightBuffer);    gl.glLightfv(GL.GL_LIGHT0 + num,                 GL.GL_AMBIENT, lightDiffuse[num], 0);  }  private void glLightNoAmbient(int num) {    if (zeroBuffer == null) {      // hopefully buffers are filled with zeroes..

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?