Jump to content
  • Advertisement
Sign in to follow this  
TheUmpteenth

Translation THEN rotation

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

can anyone tell me if it's possible to do a Translation THEN a rotation (both at the same time doesnt work for my purposes) here's the code
void cSky::Render(LPDIRECT3DDEVICE9 pDxDevHandle, D3DXVECTOR3 Translation)
{
	D3DXMATRIX m_Translation;
	D3DXMATRIX m_Rotation;
	D3DXMATRIX m_World;
	pDxDevHandle->SetStreamSource(0, p_SkyBox_VB, 0, sizeof(TEXTURED_VERTEX3D));
	pDxDevHandle->SetFVF(CUSTOM_FVF_TEXTURED);
	pDxDevHandle->SetIndices(p_SkyBox_IB);
	pDxDevHandle->SetTexture(0,Tex.Use());
	D3DXMatrixRotationYawPitchRoll(&m_Rotation, 0, D3DX_PI/4, D3DX_PI/4);
	D3DXMatrixTranslation(&m_Translation,Translation.x,Translation.z,Translation.y);
	D3DXMatrixMultiply(&m_World,&m_Rotation,&m_Translation);
	pDxDevHandle->SetTransform(D3DTS_WORLD, &m_World);//this is where I want to separate the transform
	pDxDevHandle->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,36);
}

if I do two sepatate ->SetTransform s, only the last one works

Share this post


Link to post
Share on other sites
Advertisement
I'd read up on a bit of matrix maths before going much further.

To do translation then rotation, you want World = Translation * Rotation, not World = Rotation * Translation.

I.e. you wany your D3DXMatrixMultiply() call to be:
D3DXMatrixMultiply(&m_World,&m_Translation,&m_Rotation,);

Matrix multiplication is not associative, A*B is not nessecarily the same as B*A.

Share this post


Link to post
Share on other sites
So, you appear to be suffering from a few misunderstandings.

Quote:

can anyone tell me if it's possible to do a Translation THEN a rotation (both at the same time doesnt work for my purposes)

It is certainly possible, although it doesn't mean what you seem to think it means. Also, they are both done "at the same time," ultimately.

Quote:

if I do two sepatate ->SetTransform s, only the last one works

SetTransform() simply copies the matrix you specify to the matrix that will ultimately be sent to the card. The actual transformation is not applied to any vertices until the vertices are submitted to the card (and then, the card does all the work). SetTransform() is essentially an assignment; CurrentWorldMatrix = parameterMatrix; or similar.

The order in which you multiply transformation matrices matters (because A * B != B * A for matrices, remember). Thus, when you do matrixTranslation * matrixRotation, you get different results than when you do matrixRotation * matrixTranslation. The actual values of the matrix are different; although you can think of this as "first translating, then rotating," in practice you have only one matrix applied (usually) so both operations are "done at the same time."

Now, when you say you want to do a translation then a rotation, what exactly do you want? You can certainly do that, but you need to be sure you know what the means. If you have a cube, and transform it by M = Rz(45) * Tx(10) -- rotation of 45 degrees around the Z axis followed by translation of 10 units along the X axis, you will have:

Original:
+---+
| * |
+---+

Transformed:
+
/ \
* + +
\ /
+

The * represents the origin (0,0,0). Please excuse the distortion inherit in my ASCII art. On the other hand, if you transform it by M = Tx(10) * Rz(45), you get a different result:

+
/ \
+ +
\ /
+


*


This is because rotations are done about the origin, and once the translation is applied to the vertices they are off-center from the origin, and rotate appropriately.

EDIT: fixed ASCII art.

Share this post


Link to post
Share on other sites
ok, thanks, I get the whole matrix multiplication is not associative bit.

also, I understand the "at the same time" bit, as I'm ultimately multiplying by a single matrix. for the purpose of aiding my understanding, however, I wish to refer to the apparent order of the calculations.

Now, from this

Quote:

Original:

+---+

| * |

+---+



Transformed:

+

/ \

* + +

\ /

+


The * represents the origin (0,0,0). Please excuse the distortion inherit in my ASCII art. On the other hand, if you transform it by M = Tx(10) * Rz(45), you get a different result:


+

/ \

+ +

\ /

+





*



This is because rotations are done about the origin, and once the translation is applied to the vertices they are off-center from the origin, and rotate appropriately.


i draw the conclusion that if I want to move a rotated version of my object, I need to use Rot * Trans.

However, this is what I'm doing, and I still seem to be translating along a rotated axis

Is this correct?

The OpenGL glPushMatrix() would be handy here!

Share this post


Link to post
Share on other sites
I've discovered other problems. gah!

I was passing the EyePos of my camera as a translation, and this isn't translating the box as much as it translates the camera. World matrix & View matrix don't mix.

ok, I'll be doing some maths for a while then...

Thanks for your help guys

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!