Face normals?

Started by
13 comments, last by colinisinhere 20 years, 6 months ago
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?
Advertisement
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!
what does the symbol - > mean?

Can you give an example?

[edited by - colinisinhere on October 9, 2003 7:02:02 PM]
The vector A->B just means the vector between points A and B
how do you find that?
Er. you subtract one point from the other.
Colin, some light reading may be useful to you in your current level of learning.

How appropriate. You fight like a cow.
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]
- - - - - - - - - - - - - - - -www.Vision-Software.org
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]
length?
x*y + y*y + y*y ???
Abnormal behavior of abnormal brain makes me normal...

This topic is closed to new replies.

Advertisement