Is this what you’re looking for ?
Pass in a 3d point to CalcNormal, it’ll get the normal and put it in the out variable. Then use this normal vector in your call to glNormal();
Hope this helps.
CalcNormal(Point3D a, Point3D b, Point3D c, Point3D *out)
// Calculate two vectors from the three points
v1.x = a.x - b.x;
v1.y = a.y - b.y;
v1.z = a.z - b.z;
v2.x = b.x - c.x;
v2.y = b.y - c.y;
v2.z = b.z - c.z;
// Take the cross product of the two vectors to get
// the normal vector which will be stored in out
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;
// Normalize the vector (shorten length to one)
void GLElement::GLReduceToUnit(Point3D *vector)
// Calculate the length of the vector
length = (float)sqrt( (vector->x * vector->x ) +
(vector->y * vector->y ) +
(vector->z * vector->z ) );
// Keep the program from blowing up by providing an exceptable
// value for vectors that may calculated too close to zero.
if (length == 0.0f) length = 1.0f;
// Dividing each element by the length will result in a
// unit normal vector.
vector->x /= length;
vector->y /= length;
vector->z /= length;
Originally posted by eckiller:
[b]Can someone give me a way to find the normal for each primitive using my class structure. My fragmented structure:
Object: holds an array of verts and an array of primitives that make up object.
Primitive: holds indices that make up this primitive.
VERTEX: x, y, z coordinates
I’ve been coding for quite awhile today and i just can’t think how to get this w/ my class structure. I’d like to have a method in my Primitive class that calculates the normal for that particular primitive, it it possible to do so with just indices and no verts? Ideas and suggestionns please!!??