#### Archived

This topic is now archived and is closed to further replies.

# Face normals?

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

## Recommended Posts

I''ve searched the forums for this already but got no results... What is the math for calculating the normal of a triangle that is being drawn counter-clockwise? I know it has to do with cross-product and normalizing or somthing... but, can someone give me an example?

##### Share on other sites
The answer is in the question. If your triangle has vertices A, B, C (in anti-clockwise order) form the vectors A->B, and B->C. Take the cross-product of those two vectors. Normalize it. Ta-da!

##### Share on other sites
what does the symbol - > mean?

Can you give an example?

[edited by - colinisinhere on October 9, 2003 7:02:02 PM]

##### Share on other sites
The vector A->B just means the vector between points A and B

##### Share on other sites
how do you find that?

##### Share on other sites
Er. you subtract one point from the other.

##### Share on other sites
Colin, some light reading may be useful to you in your current level of learning.

How appropriate. You fight like a cow.

##### Share on other sites
VEC3D p1,p2,p3;
VEC3D v1,v2;

v1.x = p1.x - p2.x;
v1.y = p1.y - p2.y;
v1.z = p1.z - p2.z;

v2.x = p2.x - p3.x;
v2.y = p2.y - p3.y;
v2.z = p2.z - p3.z;

//Find the cross product of v1 and v2
//Then normalize the result

[edited by - starboarder on October 9, 2003 7:28:25 PM]

##### Share on other sites
Ok, i did some extra reasearch and I wrote this code for Calculating the normals:

void calcNorms(cMesh mesh){	fVector v1, v2;	float  length;	for(int i = 0; i < mesh.nFaces; i++)	{		v1.x = mesh.pVertices[mesh.pFaces[i].nIndices[0]].x - mesh.pVertices[mesh.pFaces[i].nIndices[1]].x;		v1.y = mesh.pVertices[mesh.pFaces[i].nIndices[0]].y - mesh.pVertices[mesh.pFaces[i].nIndices[1]].y;		v1.z = mesh.pVertices[mesh.pFaces[i].nIndices[0]].z - mesh.pVertices[mesh.pFaces[i].nIndices[1]].z;		v2.x = mesh.pVertices[mesh.pFaces[i].nIndices[1]].x - mesh.pVertices[mesh.pFaces[i].nIndices[2]].x;		v2.y = mesh.pVertices[mesh.pFaces[i].nIndices[1]].y - mesh.pVertices[mesh.pFaces[i].nIndices[2]].y;		v2.z = mesh.pVertices[mesh.pFaces[i].nIndices[1]].z - mesh.pVertices[mesh.pFaces[i].nIndices[2]].z;		mesh.pFaces[i].pNormal.x = v2.y*v1.z - v2.z*v1.y;		mesh.pFaces[i].pNormal.y = v2.z*v1.x - v2.x*v1.z;		mesh.pFaces[i].pNormal.z = v2.x*v1.y - v2.y*v1.x;		length = sqrtf(mesh.pFaces[i].pNormal.x * mesh.pFaces[i].pNormal.y + mesh.pFaces[i].pNormal.y * mesh.pFaces[i].pNormal.y + mesh.pFaces[i].pNormal.y * mesh.pFaces[i].pNormal.y);		mesh.pFaces[i].pNormal.x /= length;		mesh.pFaces[i].pNormal.y /= length;		mesh.pFaces[i].pNormal.z /= length;	}}

but they are Not calculated correctly because I get weird results!

What did i do wrong?!?

[edited by - colinisinhere on October 9, 2003 11:21:40 PM]

##### Share on other sites
length?
x*y + y*y + y*y ???

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632650
• Total Posts
3007645
• ### Who's Online (See full list)

There are no registered users currently online

×