Skip to main content
gamedev.net
🔒 Locked

D3D: Transform problem, please help

Started by Floru 3 replies 450+ views
Original Post
Floru
Floru
Ok... I''m getting quite desperate... I had this question already in another form. But the question was written in very difficult way so I cleaned the function a little bit so it could be readen a little bit more easier... The problem is in rotation with translation. The rotation works independent (rotation doesn''t cause translation) even if you define the starting point for the obejct different than (0,0,0). But if you chance later the position of the object the rotation doesn''t work anymore (rotation causes translation). And I just don''t get it why. Please could someone give me a solution. I''d like to use this function also in my other classes so I''d like this to work perfectly. Info about the function: m_vectPos stores the object''s positio m_vectRot stores the objects rotation What the function should do: pos should change the position. If the vector is(5,0,0) the object moves 5 units to right. rot should rotate the object but should not cause translation of any kind. scale should scale the object in any direction. void Transform(LPDIRECT3DDEVICE7 device, D3DVECTOR pos, D3DVECTOR rot, D3DVECTOR scale) { D3DMATRIX matTrans1, matTrans2, matRotateY, matRotateZ, matRotateX, matScale, view; D3DUtil_SetTranslateMatrix(matTrans1, -1.0f*m_vectPos); // update position info m_vectPos+=pos; D3DUtil_SetTranslateMatrix(matTrans2, m_vectPos); // update rotation info m_vectRot+=rot; D3DUtil_SetRotateYMatrix(matRotateY, m_vectRot.dvY); D3DUtil_SetRotateXMatrix(matRotateX, m_vectRot.dvX); D3DUtil_SetRotateZMatrix(matRotateZ, m_vectRot.dvZ); SetScaleMatrix(matScale, scale); D3DMath_MatrixMultiply(m_matTrans, matTrans1, matRotateX); D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matRotateZ); D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matRotateY); D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matScale); D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matTrans2); device->SetTransform(D3DTRANSFORMSTATE_WORLD, &m_matTrans); } Floru
Friday13
Friday13
>D3DMath_MatrixMultiply(m_matTrans, matTrans1, matRotateX);
>D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matRotateZ);
>D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matRotateY);
>D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matScale);
>D3DMath_MatrixMultiply(m_matTrans, m_matTrans, matTrans2)

Are you sure the above order is exactly what you want?

The order in which you multiply is important. If you multiply something successively by matrices 1,2,3,4,5 one step at a time, the resulting ''one-shot'' matrix looks like 5*4*3*2*1. In your example above you first translate, then scale, then rotate, while you should do right the opposite.

Floru
Floru

Well I thought it''s correct because matTrans1 is the position of object''s origo (pos*-1). So you first translate the object to the center point. And in the end of all multiplications you translate it to the new position which is stored in matTrans2. So in which order should I change these multiplications?

Floru
Friday13
Friday13
>So in which order should I change these multiplications?

Try bottom to top. Feel free to flame if it doesn''t work.

Floru
Floru

Hi!

I tested the different order. And the translation works just fine now! Thanks. But there is now a new problem. Only one of the rotation axes is working. I don''t remember was it the last or the first of the rotation matrices. So what what should be the order of them?

Thanks
Floru

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.