Sign in to follow this  

Roating .x file objects

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

This topic is 4835 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this