Jump to content
• Advertisement

#### Archived

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

# Calculate surface normal?

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

Is there a function in DirectX8 to calculate the surface normal for a polygon? The only one I can find works for models only.

#### Share this post

##### Share on other sites
Advertisement
There''s no function to do it, but the formula to calculate the normal of a polygon is pretty simple: Normal = Crossproduct of V and W, where V is a vector representing one side of the polygon and W is a vector representing another side.

Calculating surface normals at each vertex is a little more complex and involves averaging normalised polygon normals for each polygon the vertex is a part of.

--------------------

Never eat anything bigger than your own head.

#### Share this post

##### Share on other sites
Just to clarify, if you have a triangle composed of points represented by vectors a,b,c, then you need to get 2 edges of the triangle (p,q) by:

p=b-a;
q=c-a;

Then take the Cross Product:

n = p cross q;

Then normalize the vector (if you need a unit vector):

normalize ( n );

This gives you the unit vector normal to the surface of the triangle.

If you want the vertex normal of a given vertex just sum up the triangle face normals of every triangle surrounding the given vertex, average them, and normalize the result.

for each vertex{  vertex_normal = 0,0,0;  number_of_surrounding_faces = 0;  for each triangle  {       if vertex is part of triangle       {          vertex_normal += triangle_normal;           number_of_surrounding_faces++;       }  }   vertex_normal /= number_of_surrounding_faces;   normalize ( vertex_normal );}

Forgive the pseudo code, since I am at home for Thanksgiving without my computer. Of course if you are using the IDirect3dMesh class, it can do the vertex normal calculations for you.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633379
• Total Posts
3011570
• ### Who's Online (See full list)

There are no registered users currently online

×

## 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!