Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Roating .x file objects

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

I am able to rotate an object using the method: D3DXMATRIX Position; D3DXMatrixTranslation(&Position, 0, 0, 0); static float z = 0.0f; D3DXMATRIX zRot; D3DXMatrixRotationZ(&zRot, z); D3DXMATRIX compMat; compMat=Position*zRot; Device->SetTransform(D3DTS_WORLD, &compMat); The problem is that it rotates about the Worlds Z axis, instead of its own. Is there a method to rotate it about its own Z axis? And if not, could someone lead me somewhere where I could learn to make a standard third person camera?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
compMat=Position*zRot;

should be compMat=zRot*Position IIRC.

Also, since your translation is 0,0,0 the object will spin at the origin which is what your are describing. Try moving it out to 10,0,0 or something and see if it is rotating about itself.

Share this post


Link to post
Share on other sites
The way it's actually set up is:

compMat=xRot*yRot*zRot*Position;

I first setup the Y axis rotation, which worked fine. When I added the Z axis rotation is when I realized that the model is actually rotating about the Worlds axis, not the models. For example, at first the model is facing forward and rotating head over heels, but if I rotate the model 90 degrees to the right (Y axis), the model is now rotating side over side. So the way to solve it would be to get it to rotate it about its own axis, I just don't know how to go about doing that.

Share this post


Link to post
Share on other sites
Translate your object to identity (0,0,0), then do the rotations, then translate the object back to it's original location.

D3DXMATRIX trans, rot;
D3DXVECTOR3 pos=(D3DXVECTOR3)object.m[3];

//subtracts location from object matrix, placing it at 0,0,0
D3DXMatrixTranslation(&trans, -pos.x, -pos.y, -pos.z);
object*=trans;

//do the rotation at 0,0,0
D3DXMatrixRotation(&rot, value);
object*=rot;

//place the rotated object back to it's original position
D3DXMatrixTranlsation(&trans, pos.x, pos.y, pos.z);
object*=trans;


questions?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So you want it to flip the same way even after a yrotation?

If so you want to rotate Z first then Y...

compMat=xRot*zRot*yRot*Position

And all rotations are around the world axis. The order of rotation is important.

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!