//
you're reading...
Tech

Calculating Normals of Triangles and Quads

An .OBJ file without normal information is painful: you cannot do any material stuff with it. In this situation, we need to calculate the normals by hand. This article shows a extremely straightforward method. And what happens when the object does not consists of triangles but quads ( > 3 vertices per face)? If we assume (and it always is) that the vertices are coplanar, we could simply calculate the normal of any triangle on the plane and regard it as the normal of the face.

Above is the theory of calculating normals. Practically, there are two steps:

1. Calculate the normals of each face (as indicated above in that article)

2. Calculate the normals of each vertex

This would be a little tricky. What I did was adding up each face normal to its vertices so that after calculating the face normals any vertex would have a sum of the normals belonging to faces that share this very vertex. And that is the normal of the vertex.

What’s even more tricky is: usually the normals calculated are not normalized and if you don’t want to do the normalization you need to specify:

glEnable(GL_NORMALIZE);

Otherwise it would be like … who knows?

Advertisements

About Xiang 'Anthony' Chen

Making an Impact in Your Life

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Twitter Updates

%d bloggers like this: