call me stupid-Vertex/Face Normals

This topic is 5415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

ok so i know to get a face normal i use the N = U x V but im having trouble actually looping through and getting all the triangles in my array so i can grab two vectors from a triangle to compute this is the array im using float Verts[][3] = { -10.0f,0.0f,20.0f, -10.0f,5.0f,20.0f, -10.0f,0.0f, 0.0f, -10.0f,5.0f, 0.0f, 10.0f,0.0f, 0.0f, 10.0f,5.0f, 0.0f, 10.0f,0.0f,20.0f, 10.0f,5.0f,20.0f, 5.0f,0.0f,20.0f, 5.0f,5.0f,20.0f, 5.0f,0.0f,25.0f, 5.0f,5.0f,25.0f, -5.0f,0.0f,25.0f, -5.0f,5.0f,25.0f, -5.0f,0.0f,20.0f, -5.0f,5.0f,20.0f, -10.0f,0.0f,20.0f, -10.0f,5.0f,20.0f,}; and im using the D3DPT_TRIANGLESTRIP type when i draw it any help would be appreciated.

Share on other sites
what does your loop look like now?

To calculate the normal you basically take three vertices and use these to create two vectors for which the cross product is calculated.

A,B,C are vertices

  A /|/ |C-B

N=(A-B)x(C-B)

Using your code this means Verts[k],Verts[k+1],Verts[k+2] represents A,B,C.

This yields 1 normal for each triangel.

Share on other sites
Note that for a tri-strip the winding order changes every second triangle. You'll have to take this into account to correct normals.

For for even numbered triangles you'd do:
N=(A-B)x(C-B)

and for odd numbered triangles you'd do:
N=(A-C)x(B-C) ;(ie: I swapped two verts... B and C)

The whole code would be something like:
for (i=0; i< numverts; i++)  n = 0,0,0;numfaces = numverts - 2;for (i=0; i < numfaces; i++){  a = verts;  // swap for odd triangles  if (i&1)  {    c = verts[i+1];    b = verts[i+2];  }  else  {    b = verts[i+1];    c = verts[i+2];  }  d = a-c;  e = b-c;  n += d cross e}for (i=0; i< numverts; i++)  n = n.Normalize()

Share on other sites
ok i think i should be able to figure it out

what i wasnt to sure of was the number of loops needed but reading another post in the openGL section i see that im going to need
a loop for getting face normals
then a loop through all the verts
then a loop through all the faces

then check all the verts to see if they are used in the face

correct?
didnt realize it needed so many loops..figured this would be to slow for advanced models

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 12