Rotating a group of meshes in DirectX

Started by
3 comments, last by dave 15 years, 4 months ago
Hey guys, I'm back again. So I've been playing around with DirectX and am trying to build a simple little physics based game. It's basically a maze where you guide a ball around by tilting the maze. The first thing I tried was rotate the camera itself, but it didn't work since EVERYTHING rotated, including the ball. Ok, so my maze uses 3D meshes (D3DXCreateBox) and is made up of a collection of these meshes (let's call them walls). I'd like to know how to rotate the entire maze. I've tried using D3DXMatrixRotationZ like so:

for(int i = 0; i < game.getMaze().numWalls; i++)
{
	D3DXMatrixTranslation(&matWorld, 
        game.getMaze().walls.getCenter().x,
	game.getMaze().walls.getCenter().y, 
	game.getMaze().walls.getCenter().z);
	d3ddev->SetTransform(D3DTS_WORLD, &matWorld);
		
	D3DXMatrixRotationZ(&matRotation, game.getOrientation());
	d3ddev->SetTransform(D3DTS_WORLD, &matRotation);
		
	meshBox->DrawSubset(0);
}

But it doesn't work and I'm fresh out of ideas. Any help would really be appreciated. Cheers
Advertisement
No help at all? I'm still stuck on this problem and I've googled for ages and have come up with nothing.
Sounds like you need a basic lesson on 3D transformations, maybe this will help.

In your code sample there, the rotation matrix is overwriting the translation. D3DTS_WORLD is a single matrix that you set. You need to multiply the two together, set it to the D3DTS_WORLD and then draw the model.

The order of the multiplications is important. In this case do:

ResultantMatrix = IdentityMatrix * Translation;
ResultantMatrix *= Rotation;

Once you have transformations sussed, i suggest you read up on some basic Scenegraph theory, you'll see the benefits as soon as you do so. It's basically to do with storing a scene in a tree, propogating transformations downwards.
*slaps forehead* I feel like a right idiot now. Yeah it works perfectly lol. I will be reading up on trees as well soon, just wanted to get it somewhat functional. Cheers mate :)
No problem. :)

This topic is closed to new replies.

Advertisement