public void quad(GL gl, float[][] v) { float[] out = new float[3]; calcNormal(v, out); gl.glBegin(GL.GL_QUADS); gl.glNormal3f(out[0], out[1], out[2]); for (int i=0; i < 4; i++) { gl.glVertex3d(v[i][0], v[i][1], v[i][2]); } gl.glEnd(); } public void calcNormal(float[][] v, float[] out) { float[] v1 = new float[3]; float[] v2 = new float[3]; int x = 0; int y = 0; int z = 0; //point-difference formula (finds vector) v1[x] = v[0][x] - v[1][x]; v1[y] = v[0][y] - v[1][y]; v1[z] = v[0][z] - v[1][z]; //calculate vector from point 1 to point 0 v2[x] = v[1][x] - v[2][x]; v2[y] = v[1][y] - v[2][y]; v2[z] = v[1][z] - v[2][z]; //cross product to give surface normal out[x] = v1[y]*v2[z] - v1[z]*v2[y]; out[y] = v1[z]*v2[x] - v1[x]*v2[z]; out[z] = v1[x]*v2[y] - v1[y]*v2[x]; reduceToUnit(out); } public void reduceToUnit(float[] vector) { float length; length = (float)Math.sqrt((vector[0]*vector[0]) + (vector[1]*vector[1]) + (vector[2]*vector[2])); if (length == 0.0) { length = 1.0f; } vector[0] /= length; vector[1] /= length; vector[2] /= length; }