D3D Question

dallasstar

New member
I've been learning D3D for a day or two now, but I can't figure out how to apply a transformation to JUST ONE OBJECT rather than the entire world (i've been applying the transformation to the world matrix).

could somebody help me out?

here's my case:

I have 3 cubes that are all generated at the origin. I want one of them to be at the top left, another at the bottom left, and one at the middle left. However, if I apply a transformation to the world matrix, it translates all 3 cubes at once, so there's no way i can get them to their proper locations. I know that I could just make the original locations of the cubes where I want them to be, but if I did that, then I would not be able to rotate them properly because all rotations are done with respect to the origin :(.

Any help?
 
A possible method:

D3DXMATRIX matWorld, matRotX, matTranslate;

//draw 1st cube
D3DXMatrixTranslation(&matTranslate, cube1.x, cube1.y, cube1.z)
D3DXMatrixRotationX(&matRotX, cube1.thetaX)
D3DXMatrixMultiply(&matWorld, &matRotX, &matTranslate)
SetTransformation(&matWorld)
Draw the 1st cube

//draw 2nd cube
D3DXMatrixTranslation(&matTranslate, cube2.x, cube2.y, cube2.z)
D3DXMatrixRotationX(&matRotX, cube2.thetaX)
D3DXMatrixMultiply(&matWorld, &matRotX, &matTranslate)SetTransformation(&matWorld)
Draw the 2nd cube

The third is done in the same. Just remember to build the transformation matrices for each object and apply it to each object seperately - by that, prior to building the matrices for the next object.
Quite succintly put by Humus' pseudo code.
 
Back
Top