Jump to content
  • Advertisement
Sign in to follow this  

Vertex Normals

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

Could you please give me the detailed calculations of the normal of a surface formed by vertices below? I calculated them myself but when I use them in my OpenGL program they give me wrong results. I just want to compare my calculations and make sure that I’m doing them right. P0 = (-1.0, 0.0, 1.0) P1 = ( 0.0, 1.0, 0.0) P2 = (-1.0, 0.0, -1.0)

Share this post


Link to post
Share on other sites
Advertisement
N = (P2 - P0 ) X ( P1 - P0 )
N = [ 2, -2, 0 ], and normalized: N = [ sqrt(2)/2, -sqrt(2)/2, 0 ]

You may have to adjust depending on which side is the front (as determined by the order of the vertexes).

Share this post


Link to post
Share on other sites
Quote:
Original post by hungryhippo5000
That’s the result I got but according to a sample app the normal is:

N = [-2, 2, 0], normalized N = [-0.707, 0.707, 0.0]

Which doesn't make sense and it’s driving me insane!

Remember that AxB = -(BxA). The difference is probably due to the order in which the vertexes are specified -- clockwise vs. counter-clockwise. That is how front and back are usually determined.

Share this post


Link to post
Share on other sites
This is a typical conflict of 3d coordinates' system handedness. Imagine aligning your right thumb with the direction from P0 to P1, and your right index finger with the direction from P0 to P2. A right handed system would interpret their cross product, as pointing to the direction of your right middle finger (when you stretch it out perpendicular to your palm). A left handed system would yield the exact opposite direction.

As JohnBolton said, this has immediate impact on the 3d api's ability to determine the visible side of a triangle. If you port geometry created in a left-handed system, into a right-handed one, (or vice-versa) you'll have to switch the declaration of vertices in all faces, as such:
1. change vertex order from {v0,v1,v2} into {v0,v2,v1}
2. Multiply your view matrix with the reflection matrix

[ 1 0 0 0 ]
R = [ 0 1 0 0 ]
[ 0 0 -1 0 ]
[ 0 0 0 1 ]


Let V be the view matrix. If you use column-major format use as a view matrix the product V*R, else R*V.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!