Rotating multiple .x file objects

Started by
1 comment, last by smittix 19 years, 7 months ago
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?
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
Works perfect, thanks a lot.

This topic is closed to new replies.

Advertisement