'rotating' a normal?

Started by
15 comments, last by mickey 21 years, 2 months ago
hi, it''s a plane, constructed from a model''s min/max bounding box, the plane''s fine if i translate the model''s local coords to world coords, but whenever i started rotating the model.., my plane is not correct anymore, how do i solve this? i''m not really sure if i have to ''rotate'' the normal but if i do, how? thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Advertisement
A normal is basically a vector from the origin. So if you know the amount of rotation, you can simply rotate the normal (using a matrix) and still end up with a unit vector for the rotated normal.
If you''re using 4d homogeneous vectors with 4d matrices, just rotate the normal with the same matrix used for the model rotation. However, you don''t want the translation part of the matrix to be included. This means that you rotate the vertices with 4d vectors of form (x, y, z, 1) and the normals with 4d vectors of the form (x, y, z, 0). The 0 as the 4th component of the normal vectors means that the translation isn''t applied to normal vectors.

If you are using 3d vectors and matrices, apply the rotation but skip the translation for normals.

If you scale the model using the matrix, remember to re-normalise the normals (openGL and DX have an option to do this automatically).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
hey guys,

i kinda get your point, anyway, i don''t store the matrix that i used for rotation, i just store a world matrix that combines all the transformation so is there a way i can get it from there?

i''m using dx''s d3dx functions, i hope you could provide a code,

>>If you''re using 4d homogeneous vectors with 4d matrices
can you explain a bit more?

thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
hi anyone?

i was thinking of using the D3DXVec3Transform(...) and D3DXVec3TransformNormal thinking this might be the functino to do the job,

the description for D3DXVec3Transfrom says: Transforms vector (x, y, z, 1) by a given matrix

so i thought of using that, i don't really understand this, i guess it transforms the vector to the matrix specfied something like that,

thanks!

edit:
i've posted some screenshots here,
not yet rotated
rotated

i've constructed the quad to show you what the plane would look like and here's how i construct the quad,

GetBoundingBoxOfObjects(VectorMinBox, VectorMaxBox);
VectorMinBox += ObjectPosition;
VectorMaxBox += ObjectPosition;

and from the min/max i constructed the quad,

[edited by - mickey on January 29, 2003 5:26:19 AM]

[edited by - mickey on January 29, 2003 5:26:55 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Sorry about the delay.

Those functions look just the ticket. They both take just a 3d vector, but the point one returns a 4d vector, just ignore the last coordinate. They do exactly what is required, the point one takes the vector (x,y,z), constructs a 4d vector (x,y,z,1) and then applies the matrix, returning the 4d result. The normal one transforms (x,y,z,0). The last coefficient tells you how many of the translations to apply to the vector.

You are using homogeneous 4d coordinates by the way if you use direct x or openGL, that''s why you have 4x4 matrices. The other alternative is to use a 3x3 matrix for the scale/rotation and a 3x1 vector for the translation.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
hey there Paradigm Shifter! sorry for the delay? oh no, it's okay, i just bumped it up wondering other people might be able to help me too,

oh wait, sorry, i post the wrong function, i wasn't using D3DXVec3Transform at all, it was D3DXVec3TransformCoord! i don't know how to use D3DXVec3Transform because it wants a 4d vector so i didn't use it,

can you tell me what's the differnce between D3DXVec3Transform and D3DXVec3TransformCoord? it seems D3DXVec3TransformCoord just transforms the vector into the position of the matrix, but it doesn't apply any orientation? while the other one(D3DXVec3Transform)applies a position and the orientation?

and if i have a normal vector generated from a triangle, and if i rotate this triangle using a 4x4 matrix, i should use the D3DXVecTransformNormal on my generated normal?

thanks a lot for your time and pls, feel free to answer me, anytime,

[edited by - mickey on January 29, 2003 11:24:11 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Looks like they are doing similar things but one returns (through the first pointer argument) a 4d vector and the other one returns a 3d vector. Why don''t you write a test function that does both and look at the results using the debugger (put a breakpoint at the first call and step through inspecting variables as they change).

To check the 4d one, just declare a variable of type D3DXVECTOR4 (you don''t need to initialise it) and pass the address of the variable as the first parameter. The structure will be filled in after the funtion returns. It should be the same vector produced by the 3d version but with a 1.0 as it''s w field.

Always translate normals with the D3DXVec3TransformNormal function, you don''t want them to be translated at all.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
that was fast,

i forgot to ask you this from your last reply, pls be patient i think i might get it soon,

>>the point one takes the vector
what do you mean by 'the point'? and i think this is my problem, what kind of vector exatly do i pass in the function? is it the rotation vector i used to rotate the model? position? scaling? and which model?

>> The last coefficient tells you how many of the translations to apply to the vector.
is this the 'w'? and what is this many translations are you saying?

yep, i'm not just stepping thru the debugger, i am rendering the values in my game and i don't see any difference from D3DXVec3Transform and D3DXVec3TransformCoord.., but again i don't really know what kind of vector i should pass in..,

edit:
this is some of the ways i use the function
// to get a position vector from the object
D3DXVec3TransformCoord(&vOutPos, &Getobjectposvector_ToApplyPosVector, &otherobjectsworldmatrix);

// to get the rotataion/orientation
D3DXVec3Transform(&vOutRot, &GetobjectsrotVector_ToApplyRotVector, &otherobjectsworldmatrix);

// works, i think
objects_to_apply_vector.setPos(vOutPos);
// not
objects_to_apply_vector.setRot(vOutRot);

and they have same vOut***..,

[edited by - mickey on January 29, 2003 11:36:05 AM]
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
The point is the model-relative position of the vertex. Use the model transform matrix as the matrix input (not the camera projection matrix), it takes care of the translation, rotation and scaling into world space. I assume the rot vector is the x,y,z angles you used to construct the transformation matrix, you don''t need to use that once you have the matrix. If you transform normals using a transform which has a scale, you may need to re-normalise them afterwards (make them length 1.0). I think there''s a way to get DX to do that automatically though.

And learn to use the debugger. It is your friend!

The w-component is a bit complicated to explain. Try looking at some of the articles here on GameDev, or the DirectX docs on the MSDN. Or do a google search for "homogeneous coordinates".

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley
"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

This topic is closed to new replies.

Advertisement