Normalized Vectors

Member
Posts: 196
Joined: 2002.04
Post: #1
Hi long time no post :ohmy:,

Everyone's been asking about how to make normal vectors. Here's a good web site to check out; I think it has the best explanation: http://www.lighthouse3d.com/opengl/terra...p3?normals

The t1, t2, t3 are the vertices as in t1 = x, y, z or
v1x = xt2 - xt1
v1y = yt2 - yt1
v1z = zt2 - zt1

v1x = xt3 - xt1
v1y = yt3 - yt1
v1z = zt3 - zt1

The next step is the Cross product:
vx = v1y * v2z - v1z * v2y
vy = v1z * v2x - v1x * v2z
vz = v1x * v2y - v1y * v2x

Finally you normalize it:

L = sqrt(vx * vx + vy * vy + vz * vz)

nvx = vx / L
nvy = vy / L
nvz = vz / L

So this is what it looks like in OpenGL:

glNormal3f(nvx, nvy, nvz);

glVertex3f(xt1, yt1, zt1);
glVertex3f(xt2, yt2, zt2);
glVertex3f(xt3, yt3, zt3);

There you go. Hopefully I did it right there are more complex ways to do which are explained at the bottom of the page of link above but this will get you started.

Hope this helps,
Iceman

P.S. Hey Carlos maybe you could post this in the news stuff so more people can see it and before henryj tears his hair out Wow.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Remember to put the normal3f calls before the vertex3f calls they correspond to...
Quote this message in a reply
henryj
Unregistered
 
Post: #3
Quote:henryj tears his hair out


???? Care to explain?
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #4
Thanks OSC I fixed it and henryj I was only jokingWink. I got the impression you were mad from the "3798543 times" the question had been mentioned before.

Thanks,
Iceman
Quote this message in a reply
henryj
Unregistered
 
Post: #5
How about you add it to the faq, then I wont get so Mad
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #6
Quote:Originally posted by henryj
How about you add it to the faq, then I wont get so Mad
It might be relevant to add this along with this discussion, as it's a useful accelerating of the divide by square root part if you're doing this at runtime.

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Member
Posts: 196
Joined: 2002.04
Post: #7
Quote:Originally posted by henryj
How about you add it to the faq, then I wont get so Mad


Because it looks really hard to set up and no one uses it anyway since it's not even close to being user friendly Grin.

Ice

B.T.W. How would I get a normal for each vertex?

Update: Ok I got the normal for each vector working. Maybe some day when I have a lot of time I'll figure out that F.A.Q. page thing.
Quote this message in a reply
Post Reply