PDA

View Full Version : Normals

03-27-2003, 05:51 AM
Hello all!

Im calculating normals for every vertex, but in the end, it looks almost as if I was using GL_FLAT instead of GL_SMOOTH, anyway
the way I calculate them is:
C
|\
| \
|__\B
A

A normal:

v1=B-A
v2=C-A
nv=cross(v1,v2)
d=sqrt((vn.x * vn.x) + (vn.y * vn.y) + (vn.z * vn.z))
vn.x/=d
vn.y/=d
vn.z/=d

B Normal:

v1=C-B
v2=A-B
nv=cross(v1,v2)
d=sqrt((vn.x * vn.x) + (vn.y * vn.y) + (vn.z * vn.z))
vn.x/=d
vn.y/=d
vn.z/=d

C Normal:

v1=A-C
v2=B-C
nv=cross(v1,v2)
d=sqrt((vn.x * vn.x) + (vn.y * vn.y) + (vn.z * vn.z))
vn.x/=d
vn.y/=d
vn.z/=d

I think this is the right way to do it, isnt it?

Thx http://www.opengl.org/discussion_boards/ubb/smile.gif

T
03-27-2003, 06:21 AM
All of the above calculate the same normal, the normal of the face. If you want smoothed normals: calculate all face normals, then for each vertex average the face normals of the faces that use that vertex.

03-28-2003, 02:30 AM
Dam, i feel dumb :|
Thx, ur very right http://www.opengl.org/discussion_boards/ubb/wink.gif