PDA

View Full Version : Calculate normal of a triangle



Eddy
04-22-2000, 05:29 AM
A simple question:
I draw a triangle under OpenGL:
glBegin(GL_TRIANGLES);
glVertex3f( 4.0f,2.0f,0.0f);
glVertex3f( 2.0f,4.0f,-2.0f);
glVertex3f(0.0f,3.0f,-1.0f);
glEnd();
How to make to calculate the normal of this triangle?

Guy
04-22-2000, 10:38 AM
Cross Product.

Lord Chaos
04-22-2000, 10:04 PM
Yup, crossproduct is the way to go. Take (v2-v1) x (v2-v3) to get the normal (you might have to switch order of the vectors to end up with a normal pointing in the correct direction, based on the system you use, left or right-handed)

Of course, you must normalize the vector you get out of the cross product.