Jump to content
  • Advertisement
Sign in to follow this  
Fallen_Angel

OpenGL Problem rotating an object

This topic is 4953 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'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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Store a matrix for each of your objects and call SetTransform(D3DTS_WORLD, &objMatrix) for all of them

regards

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!