Advertisement

Normals

Started by September 01, 1999 04:00 AM
8 comments, last by GameDev.net 25 years, 4 months ago
Normals are computed as the cross product between two vectors. So...

given two vectors u = (u_x, u_y, u_z)
and v = (v_x, v_y, v_z)

u x v = n <-- the normal vector

n_x = (u_y * v_z) - (u_z * v_y)
n_y = (u_x * v_z) - (u_z * v_x)
n_z = (u_x * v_y) - (u_y * v_x)

where n = (n_x, n_y, n_z)

There's the equation. Hopefully I got that right.

Khawk


-----
I edited the post since some of it was missing because the board thought I was doing html.

[This message has been edited by Khawk (edited August 10, 1999).]

Admin for GameDev.net.

The cross product equation posted is incorrect. It should read:

N.x = (U.y * V.z) - (U.z * V.y)
N.y = (U.z * V.x) - (U.x * V.z)
N.z = (U.x * V.y) - (U.y * V.x)

Advertisement
Thank you for the correction.

Khawk

Admin for GameDev.net.

The bloke above was not wrong, both equations are correct depending upon the orientation of your world.

The second answer given is the "proper maths" way to do it, but the first answer given is actually the most widely used in graphics programming.

Fool.

That's easy for finding face normals, but what about vertex normals? I guess you could do like a weighted average of the face normals for all faces that connect to that normal, but damn that would be a p.i.t.a. Is there an easy way?
Oops I meant "all faces that connect to that vertex".
Advertisement
Unfortunately, that is the only way. However, if you precompute these at startup or whatever, and then translate them using the inverse matrix method - it shouldn't be a problem.
If you're doing face normals for polygons, does it matter wether they are clockwise or CCW?
Write more poetry.http://www.Me-Zine.org
Does anybody have any good algorithms or formulas or anything for calculating normals?

I was using the Microsoft writtine function CalculateNormals() which comes with the XFile example on the SDK CD. It's good, but not good enough.

Anyone else have any better ideas?

Thanks.

-Snowman

if you change the direction of vertex definition the direction of the normal is changed, too.

Sengir


--
Sengir

This topic is closed to new replies.

Advertisement