Roating .x file objects

Started by
4 comments, last by smittix 19 years, 7 months ago
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?
Advertisement
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.
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.
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?
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.
Ok, changing the order in which the matrices were multiplied fixed it, thanks for all your help!

This topic is closed to new replies.

Advertisement