Problem rotating an object

Started by
4 comments, last by Fallen_Angel 19 years, 4 months ago
I'm currently having trouble rotating an object around its own axis. Whenever I try to rotate it, it seems to still rotate around the world axis. See here for what I'm talking about but please excuse my crappy attempt at drawing arrows. Basically the object moves in a circular motion around the world rather than spinning around in the same position. I have posted a similar problem before with relation to push/pop of matrices and have been told that things are done a little differently in DirectX than in OpenGL and I still haven't adjusted yet. The code that I am using is as follows:

MatrixStack ms = new MatrixStack();
ms.Push();
ms.RotateAxis(new Vector3(1,0,0), Geometry.DegreeToRadian(80.0f));
ms.RotateAxis(new Vector3(0,0,1), Geometry.DegreeToRadian(o.Direction));
ms.Scale((0.5f * clsGlobal.ScreenRatio), (0.5f * clsGlobal.ScreenRatio), (0.5f * clsGlobal.ScreenRatio));
ms.Translate((o.PosX * clsGlobal.ScreenRatio), (o.PosY * clsGlobal.ScreenRatio), 0.0f);				
deviceGraphics.SetTransform(TransformType.World, ms.Top);
ms.Pop();
for (int i = 0; i < meshMaterialTank1.Length; i++)
{
	deviceGraphics.Material = meshMaterialTank1;
	deviceGraphics.SetTexture(0, meshTextureTank1);
	meshTank1.DrawSubset(i);
}

Thanks
Advertisement
Store a matrix for each of your objects and call SetTransform(D3DTS_WORLD, &objMatrix) for all of them

regards
Sorry but isn't that what I'm doing with the MatrixStack or am I doing something wrong? I'va also had an idea that I'm going to try when I get home tonight. I'm thinking that the order that I am transforming the object is wrong in that I am rotating the object and then moving it which is being effected by the rotation. I'm thinking that if I perform the translation first and then rotate that my problem might go away? Not too sure though until I get home from work.
Ok my latest theory didn't exactly work as I had expected. Has anyone got any other possible solutions that might fix my problem?

Thanks
Rotation is always done around the world 0,0
To rotate the object around it's own 0,0 you must translate it to 0,0 in worldspace do the rotation and then translate it to what ever position it should have.
Ok found the problem thanks to some google work. This was happening because my model was not created directly on (0,0,0) therefore any transforms that I was performing was also being effected by the transform in the model. And here I was staring at my code for days trying to figure out what was wrong with it. Thanks for the help as it did get me to look deeper into the issue to resolve it.

This topic is closed to new replies.

Advertisement