Im not knowledgable in hardware accelerated graphics, however with my software rendering experience, I can tell you that a surface normal is calculated by
private Vector calcNormal() {
Vector normal = new Vector();
Vector temp0 = new Vector();
Vector temp1 = new Vector();
// vertices3D is the array containing the vertices of each polygon/triangle (Vectors)
temp0.set(vertices3D[1]); // Make actual Vectors from the vertices by doing end vertex minus start vertex
temp0.subtract(vertices3D[0]); // temp0 is now the vector between the first vertex and the second.
temp1.set(vertices3D[2]);
temp1.subtract(vertices3D[0]); // temp1 is now the vector between the first vertex and the third.
normal.setToCross(temp0, temp1); // find the vector orthogonal to the two vectors that represent the surface of the polygon/tri.
normal.unit(); // make it a unit vector since you don't want a magnitude greater than 1 for a normal which is a direction vector.
return normal;
}
// these are in the Vector class
public Vector subtract(Vector v) {
x -= v.x;
y -= v.y;
z -= v.z;
return this;
}
public Vector unit() {
float invMag = 1 / magnitude();
x *= invMag;
y *= invMag;
z *= invMag;
return this;
}
public float magnitude() {
return (float) Math.sqrt(dot(this));
}
public float dot(Vector v) {
return x * v.x + y * v.y + z * v.z;
}
public void setToCross(Vector a, Vector b) {
this.x = a.y * b.z - a.z * b.y;
this.y = a.z * b.x - a.x * b.z;
this.z = a.x * b.y - a.y * b.x;
}
EDIT: is this spoon feeding? :persecutioncomplex: ???