Jump to content
  • Advertisement


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


Calculating Normals

This topic is 5748 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

\ / First of all, I wish everybody a Merry X-mas / \ Ok.. Now back to my problem. How do I calculate Normals?? I''m not sure.

Share this post

Link to post
Share on other sites
OK, although this is covered *many* times across the internet (try googling):

The normal to a triangle or some other polygon can be calculated by taking the cross product of two adjacent edges.

Say the triangle is represented by three (3D) points Pi.

Edge 1 can be E1 = P2 - P1
Edge 2 can be E2 = P3 - P1

Now normal N is

N = E1 X E2

Where X is the cross product, defined like this in a function:

inline Vector3 Cross(const Vector3& v1,const Vector3& v2)
double c0 = ( v1.c[1] * v2.c[2] ) - ( v1.c[2] * v2.c[1] );
double c1 = ( v1.c[2] * v2.c[0] ) - ( v1.c[0] * v2.c[2] );
double c2 = ( v1.c[0] * v2.c[1] ) - ( v1.c[1] * v2.c[0] );

return Vector3(c0,c1,c2);

Now if you want normals for a smooth mesh (ie normal per vertex), you need to accumulate the normals for each triangle for each vertex and then average them together (and renormalize if necessary).

[edited by - JuNC on December 26, 2002 3:14:34 PM]

Share this post

Link to post
Share on other sites
I would suggest gametutorials.com they have a nice tutorial on normals and all that. This is where i learned. also, i do beleive that NeHe has a tut on them too.

IT Administrator / Software Engineere

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!