Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Normals

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

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).]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites