# Rotating an object

This topic is 3834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Mabye it's better here... Hy. I've got a object with his matrix. Now i would to rotate it on the X,Y or Z axes, but the object is not on that axes. So, knowing this trasformation:
		D3DXMatrixTranslation(&Alien.MeshData.ColladaBuffer.Objmatr,15.0f,-30.0f,25.0f);
D3DXMatrixScaling(&p,0.6f,0.6f,0.6f);
D3DXMatrixRotationX(&p,-1.3f);


I tried to rotate it in this way
	D3DXMATRIXA16 m,p,q,r;
D3DXMatrixTranslation(&q,15.0f,-30.0f,25.0f);
D3DXMatrixRotationZ(&r,-1.3f);
D3DXMatrixInverse(&m,NULL,&q);
D3DXMatrixRotationY(&p,f);
Alien.MeshData.ColladaBuffer.Objmatr = m * p * r * q;
f+=0.0001f;


But it does not give me the wishered result. If i remove the r multiplication, it rotates correctly, but it's not centred. Here is an image http://img213.imageshack.us/img213/1629/imghu3.jpg I should say that i do not know if the object, in it's starting position, it's in 0,0,0 point. Anyway... Can you give me an help?

##### Share on other sites
If the first code you posted is the transformation for the object, you need to undo that transformation first.

That first code translates the object and then rotates it.

Your second code needs to unrotate it first, unscale it, then untranslate it, in the reverse order that you applied originally.

So: after the first code has been applied and you then want to rotate the object:

D3DXMATRIX rot, unrot, unscale, scale, trans, untrans, newroty, newrotz;D3DXMatrixRotationX(&rot,-1.3f);D3DXMatrixInverse(&unrot,NULL,&rot);D3DXMatrixScaling(&scale,0.6f,0.6f,0.6f);D3DXMatrixInverse(&unscale,NULL,&scale);D3DXMatrixTranslation(&trans,15,-30,25);D3DXMatrixInverse(&untrans,NULL,&trans);.. create your newroty and newrotz ..ObjMatr = unrot * unscale * untrans * newrotz * newroty * trans * scale * rot;

The effect of "unrot * unscale * untrans" is to get the object back to the origin at its original scale and rotation.

Then restore the translation and rotation you had originally.

Is that what you want to do?

##### Share on other sites
Oh man it was so simple...i did not make the right untrasformation...
I can't try now; i will use your code this night, and i will let you know something. Thank you anyway

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633726
• Total Posts
3013572
×