Jump to content
  • Advertisement
Sign in to follow this  
bengaltgrs

Rotating multiple .x file objects

This topic is 5486 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 trying to place and rotate multiple .x file objects into a scene. I am able to place the objects where they need to go using: D3DXMATRIX Position; D3DXMatrixTranslation(&Position, 0, 0, 0); Device->SetTransform(D3DTS_WORLD, &Position); If I place this code before displaying each object it works fine, but when I try to rotate each object by placing this code before displaying each object: static float y = 0.0f; D3DXMATRIX yRot; D3DXMatrixRotationY(&yRot, y); y += timeDelta; D3DXMATRIX World = yRot; Device->SetTransform(D3DTS_WORLD, &World); It will rotate the whole scene, no matter how I place them. How can I rotate each object individually?

Share this post


Link to post
Share on other sites
Advertisement
Try this before each object:

//Put your position into a matrix (change your position for each object)
D3DXMATRIX Position;
D3DXMatrixTranslation(&Position, 0, 0, 0);

//Put your rotation into a matrix
static float y = 0.0f;
D3DXMATRIX yRot;
D3DXMatrixRotationY(&yRot, y);
y += timeDelta;

//now compile your matrix so you have your rotation and position in one
D3DXMATRIX compMat;
compMat=Position*yRot;

//now render with your compiled matrix
Device->SetTransform(D3DTS_WORLD, &compMat);


See how that works for you. As a note, see how I said to change the position of the matrix for each object? If all the objects are rotating at the same speed and are on the same spot as each other it will seem as though the entire world is rotating rather then the objects individually, but really what is happening is that those individual objects are rotating syncronized giving that effect. So if you move them to diffrent locations you'll see that they are rotating independently and the world isn't rotating.
~Wave

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!