Archived

This topic is now archived and is closed to further replies.

I can't use matrix!

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

hi! im getting crazy with this, please, i beg someone to help me, im desesperate! i have two vectors in a 3d space representing a line, one will be the "center point" (don''t move) and another one that rotates around it. first i just needed to rotate two vectors making it circle, simple task, i just use cos and sin, but now, i want the third dimension to be rotated, too, and i (think i) need to use a matrix to achieve that 3dimensional rotation! but i cant even rotate 2 dimensions! what do i do is, D3DXMatrixIdentity for a D3DXMatrix mrot and mtemp, then i translate mtemp to the center point (multiply it with mrot), finally i rotate it (multiply it with mrot). then I use D3DXVec3TransformCoord with mrot to get the coordinates. i know im doing something wrong, please help me!!!!!

Share this post


Link to post
Share on other sites
Try doing all your rotations before translating. If you translate before rotating, your rotation will no longer pivot around the object''s center point.

Also, there''s no need to initialize mrot to an identity matrix. Just do this:


  
// float yawVal, pitchVal, rollVal;

// D3DXVECTOR3 transVec;

D3DXMATRIX mrot, mtrans, mfinal;

// Rotation

D3DXMatrixRotationYawPitchRoll(&mrot, yawVal, pitchVal, rollVal);

// Translation

D3DXMatrixTranslation(&mtrans, transVec.x, transVec.y, transVec.z);

// Multiply them, rotation FIRST, translation LAST

D3DXMatrixMultiply(&mfinal, &mrot, &mtrans);


Note that in the above code you can skip the D3DXMatrixTranslation() and D3DXMatrixMultiply() calls by setting the translation values in the mrot matrix manually:


  
// float yawVal, pitchVal, rollVal;

// D3DXVECTOR3 transVec;

D3DXMATRIX mrot;

// Rotation

D3DXMatrixRotationYawPitchRoll(&mrot, yawVal, pitchVal, rollVal);

// Translation

mrot._41 = transVec.x;
mrot._42 = transVec.y;
mrot._43 = transVec.z;


Hope that helps.
--Hoozit.

Share this post


Link to post
Share on other sites
thanks for your help but it won''t do what i want... i mean, i need to get a vector out of the matrix!

so, i have my vector and after i do all the matrix math i do:
D3DXVec3TransformCoord(outvec, yawvec, matrix);
only the translation matrix will take effect, the vector isn''t rotated in any way!

or should i use another function? or i should just get the vector out of the matrix manually? i''ve read that you can get the exact vector position of the matrix by suming all the first 3 rows like this:
x = m._11 + m._12 + m._13 + m_14;
y = m._21 + m._22 + m._23 + m_24;
z = m._31 + m._32 + m._33 + m_34;

but im not sure, in fact, im going to try that now

again, thanks for your help!

Share this post


Link to post
Share on other sites
I''m not sure why you would want to get a vector from a matrix. Chances are you''re making something more difficult than it needs to be.

Let me see if I understand what you''re doing: you have two vectors, each representing endpoints on a line. One of these endpoints should remain stationary, and the other should orbit around the first point. Right?

OK, first things first. If you want point #1 to remain stationary, you should put it at the origin (D3DXVECTOR(0,0,0)). Otherwise, the rotation will cause this point to move from its past location (more specifically, it will orbit around (0,0,0)).

It sounds like you may not even need point #1--just use point #2 since it''s the only one that is supposed to move. Also, you may not need to use cosine/sine functions either. If you just want to rotate point #2, just transform the vector through the rotation matrix I showed you how to create, using some arbitrary pitch/roll/yaw values like 0.001f.

Without knowing more about what you''re trying to do, I''m afraid I can''t offer much more...Please elaborate a bit.

--Hoozit.

Share this post


Link to post
Share on other sites