Sign in to follow this  
DesignerX

Rotating a mesh with normals

Recommended Posts

Suppose I have created a mesh with normals. When I rotate the mesh using the world transformation : rotationMatrix = rotate 5deg around y axis . SetTransform(WORLD, rotationMatrix); Are the normals are rotated as well ? if not how can I update the normals as well ? thx.

Share this post


Link to post
Share on other sites
mesh normals are inside the vertex declaration, so (almost) every operation performed on a vertex, modifies also the relative normal.

Of course this is not true if you're using a shader, but in your case, using the SetTransform function will rotate normals as well.

Anyway you can always try placing a light somewhere over your mesh and start rotating the mesh... if the illumination is correct, you've done it ^__^'

Share this post


Link to post
Share on other sites
just be careful when scaling the mesh though, as the normals will shrink along with it, and the mesh will appear to be lit brighter. There is some line of code (cant remember what exactly) that will prevent your normals from scaling.

Share this post


Link to post
Share on other sites
If your mesh is transformed by a matrix M, then your normals need to be transformed by the inverse transpose matrix of M. Otherwise, for instance when M contains scaling along one direction, your normals will not be perpendicular to the surface anymore.

See at the images here:
http://www.gignews.com/realtime020100.htm

Share this post


Link to post
Share on other sites
If you're using the fixed-function SetTransform() method then it'll handle it for you. The only gotcha is if your world transform has a scaling component - in which case D3DRS_NORMALIZENORMALS = TRUE should sort you out.

If you're using a vertex shader then follow nmi's advice.

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this