## Vertex Normals

SummerLand
Unregistered

Post: #1
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
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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 back-to-front, 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
henryj
Unregistered

Post: #3
FAQ that sucker!!
Member
Posts: 142
Joined: 2002.11
Post: #4
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:
Member
Posts: 164
Joined: 2002.04
Post: #5
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.
Member
Posts: 177
Joined: 2002.08
Post: #6
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.
henryj
Unregistered

Post: #7
Try to avoid GL_NORMALIZE if you can help by normalising your normals yourself. It is really slow, mainly because it will kick you off the fast path.