Vertex Normals
There is a way to calculate the vertex normals of a triangle? Like Meshwork? GL_NORMALIZE seems to not work... I need them for my little modelling app. Thanks
Face normals are easy:
If the vertices of your triangle are A, B, C, the face normal is something like (A  B) x (C  B). (That might be backtofront, should be easy to fix by changing the order of the subtractions).
For vertex normals, average the face normals of the surrounding triangles.
This has all been discussed before, search the forum and you shall find
If the vertices of your triangle are A, B, C, the face normal is something like (A  B) x (C  B). (That might be backtofront, should be easy to fix by changing the order of the subtractions).
For vertex normals, average the face normals of the surrounding triangles.
This has all been discussed before, search the forum and you shall find
I had the very same problem, and being a beginner at OpenGL I looked it up. I hope this helps:
<code snippet>
triNormal[0] = vec1[1] * vec2[2]  vec1[2] * vec2[1];
triNormal[1] = vec1[2] * vec2[0]  vec1[0] * vec2[2];
triNormal[2] = vec1[0] * vec2[1]  vec1[1] * vec2[0];
glNormal3fv(triNormal);
</code snippet>
vec1[0] would be the x difference between a first point and a second.
vec1[1] would be the y difference for the same thing
vec1[2] would be the z difference
vec2[0] would be the x difference between the same first point and another point on the triangle
vec2[1] would be the y diff...ect.
This normal that results isn't the correct length, however (it must be 1), but theres a few ways to fix this like dividing each component by the total length or using OpenGL's normalize functions.
Now I'm a beginner, and I'm trying to help, so if I'm wrong (talking to you advanced people!), correct me.
The original document I found this at is here:
http://www.cs.csustan.edu/~rsc/SDSU/Shading.Models.pdf
<code snippet>
triNormal[0] = vec1[1] * vec2[2]  vec1[2] * vec2[1];
triNormal[1] = vec1[2] * vec2[0]  vec1[0] * vec2[2];
triNormal[2] = vec1[0] * vec2[1]  vec1[1] * vec2[0];
glNormal3fv(triNormal);
</code snippet>
vec1[0] would be the x difference between a first point and a second.
vec1[1] would be the y difference for the same thing
vec1[2] would be the z difference
vec2[0] would be the x difference between the same first point and another point on the triangle
vec2[1] would be the y diff...ect.
This normal that results isn't the correct length, however (it must be 1), but theres a few ways to fix this like dividing each component by the total length or using OpenGL's normalize functions.
Now I'm a beginner, and I'm trying to help, so if I'm wrong (talking to you advanced people!), correct me.
The original document I found this at is here:
http://www.cs.csustan.edu/~rsc/SDSU/Shading.Models.pdf
I'm not sure if this is what you're doing, but if you loop through all your faces and calculate their normals you can just add each face normal to its component vertices' normals and then go through all the vertices and normalise their normals.
That sounds kinda confusing now that I read through it but should work.
That sounds kinda confusing now that I read through it but should work.
What GL_NORMALIZE really does is it scales all the normals you send with the glNormal commands such that they are 1 unit long (some transformations will change their length). But if you aren't sending normals at all or the normals you send are incorrect, GL_NORMALIZE won't help you.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
glNormal  Surface/Vertex normals  Jones  19  15,880 
Jul 18, 2006 12:45 PM Last Post: imikedaman 

Normals  Nick  20  9,336 
Mar 25, 2005 09:31 AM Last Post: tigakub 

Normals?  Quicksilver  3  3,277 
Jan 13, 2003 05:31 PM Last Post: henryj 