Sign in to follow this  
raydey

Rotating a group of meshes in DirectX

Recommended Posts

raydey    159
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[i].getCenter().x,
	game.getMaze().walls[i].getCenter().y, 
	game.getMaze().walls[i].getCenter().z);
	d3ddev->SetTransform(D3DTS_WORLD, &matWorld);
		
	D3DXMatrixRotationZ(&matRotation, game.getOrientation());
	d3ddev->SetTransform(D3DTS_WORLD, &matRotation);
		
	meshBox[i]->DrawSubset(0);
}

But it doesn't work and I'm fresh out of ideas. Any help would really be appreciated. Cheers

Share this post


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

Share this post


Link to post
Share on other sites
raydey    159
*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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this