Sign in to follow this  

call me stupid-Vertex/Face Normals

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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[i] = 0,0,0;

numfaces = numverts - 2;
for (i=0; i < numfaces; i++)
{
a = verts[i];
// 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[i] += d cross e
}

for (i=0; i< numverts; i++)
n[i] = n[i].Normalize()

Share this post


Link to post
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
add them and average them

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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this