Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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:

I tried to rotate it in this way
	D3DXMATRIXA16 m,p,q,r;
	Alien.MeshData.ColladaBuffer.Objmatr = m * p * r * q;

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 this post

Link to post
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;
.. 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 apply your new rotations.

Then restore the translation and rotation you had originally.

Is that what you want to do?

Share this post

Link to post
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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!