Scaling and normals

Started by
5 comments, last by birger 21 years, 5 months ago
When using a transformation matrix to do rotations and scaling, how do you handle transformations of normal vectors? As I understand, normal vectors are transformed differently than tangent vectors when it comes to scaling. Do you keep a double set of transformation matrixes, do you avoid normals altogether, or is there a better way to deal with it? For the moment, whenever I need to transform a normal, I convert it to a pair of tangents, transform the tangents and then convert them back to a normal again. It works, but it sure feels awkward.
Advertisement
You should be able to apply the transformation to your normals as you would your points. When dealing with scales, your normals may become change from the unit length so if you wanted to maintain them at there unit length you could just normalize them when you transform. If your just transform using the graphics card prior to rendering an object and it''s normals (and ur using opengl) u can specify that the normals are all normalized by glEnable(GL_NORMALIZE) or to rescale normals u can use glEnable(GL_RESCALE_NORMALS) (im sure that Direct3D has an equivalent).
The D3D equivalent is

device->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );
John BlackburneProgrammer, The Pitbull Syndicate
Thanks for your answers, but I don''t see how normals could be transformed the same way as points or tangents. For instance, say I have a vector (1,1,0) specifying the direction of a line. A normal vector to that line would be (-1,1,0). Now, if I scale the line by a factor 2 x-wise, the direction vector should change to (2,1,0). Scaling the normal the same way would give (-2,1,0), but that is not normal to (2,1,0). Rather, the normal should be in the direction of (-1,2,0).
quote:Original post by birger
Thanks for your answers, but I don''t see how normals could be transformed the same way as points or tangents. For instance, say I have a vector (1,1,0) specifying the direction of a line. A normal vector to that line would be (-1,1,0). Now, if I scale the line by a factor 2 x-wise, the direction vector should change to (2,1,0). Scaling the normal the same way would give (-2,1,0), but that is not normal to (2,1,0). Rather, the normal should be in the direction of (-1,2,0).


Umm i''m not too sure that you understand the concept of a normal. But following your idea i can offer you this:

--------------------------------------------------------------
The normal you have calculated for your ''line'' should be normalised for a start. So..

V1 = (1,1,0)--------> N1 = iroot2*(-1,1,0)

the iroot2 represents the inverse of the magnitude of the line vector.

Also, if for some reason you want to use normals as you have stated then you must recalculate the normal using the gradient of the line vector (which for simplifying''s sake i will do in 2 dimensions)

Eg

V1 = (1,1)

gradient of V1 = rise/run = dy/dx = (1-0/1-0) = 1.

find the gradient that is perpendicular to this by negating it, then inverting it

gradient of N1 = - run/rise = - 1^-1 = -1.

then create the new normal vector using this gradient. (y=mx)

y = m*x for x=-1, y=1 therefore N1 = (-1,1)
but normalised N1 = (-1,1)/magnitude = (-1,1)/sqrt(1^2+1^2)

using this method on V2 = (2,1) gives N2 = (-0.5, 1)/sqrt(1.25)

but calculating the right direction for the normal is going to require a bit more thinking about the arrangement of your points
---------------------------------------------------------------

I think that you should read up a bit inthe articles in gamedev, or through google, about normals. As in your case i could see no real purpose for calculating the normal of a line.

-Ben
The normal is usually transformed by the transposed of the inverse transformation matrix. However, an additional normalization may be needed.
VolkerG, thank you very much! The transposed inverse does the job perfectly. Just what I was looking for! Thanks again.

This topic is closed to new replies.

Advertisement