Rotating a mesh with normals

Started by
3 comments, last by jollyjeffers 16 years, 11 months ago
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.
There is nothing that can't be solved. Just people that can't solve it. :)
Advertisement
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 ^__^'
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.
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
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement