Jump to content
  • Advertisement
Sign in to follow this  
hzzhouqq

OpenGL Problem of triangle mesh normal caculating.

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

Hi, all: I have wrote a program, which will parse *.3ds file, and display 3d object using opengl. I save 3ds object in triangle mesh, according 3ds format. My algorithm of caculating normal vector is : 1. Calculating every triangle surface normal. 2. Averaging triangle normals to compute vertex normals Ok, diplay some box object like blow. You can see obviously black line at top of box.
"Averaging normal not work very well." Now what can I do?

Share this post


Link to post
Share on other sites
Advertisement
I cant see your images.

Are you normalizing the normals? You should normalize the normals of each triangle before averaging and also normalize the normals of each vertex.

Share this post


Link to post
Share on other sites
Quote:
Original post by xissburg
Are you normalizing the normals? You should normalize the normals of each triangle before averaging and also normalize the normals of each vertex.


Actually it's often considered better not to normalize your face normals before averaging. That way faces with a larger surface area contribute more to a vertex's normal. It also has the added bonus of simplifying your code:

Set all vertex normals to (0,0,0)
For each face (a, b, c)
{
face_normal = Cross(b-a, c-a)
vertex[a].normal += face_normal
vertex.normal += face_normal
vertex[c].normal += face_normal
}
For each vertex v
v.normal = Normalize(v.normal)


Here's another explanation, because I tend to suck at explaining things

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!