# 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.

## 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 on other sites
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 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 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 on other sites
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 on other sites
Ok, changing the order in which the matrices were multiplied fixed it, thanks for all your help!

1. 1
2. 2
3. 3
4. 4
Rutin
11
5. 5

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632666
• Total Posts
3007722
• ### Who's Online (See full list)

There are no registered users currently online

×