Public Group

# DirectX Matrix Transformations

This topic is 3173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I would like to rotate a cube primitive around a single axis. To be more specific, I would like to rotate the vertex points (8) of the cube, which uses an index buffer to create the triangles. In GDI and other projects, I have written my own functions to handle matrix transformations. However, I would like to use methods provided by dx if possible (since I am trying to learn it). I have done some searching and found this:
    D3DXMATRIX mSunScale;
D3DXMATRIX mSunSpinRotation;
D3DXMATRIX mSunMatrix;

D3DXMatrixRotationY( &mSunSpinRotation, D3DXToRadian( fSunSpin ) );
D3DXMatrixScaling( &mSunScale, 5.0f, 5.0f, 5.0f );

// Now, concatenate them together...

mSunMatrix = mSunScale *       // 1. Uniformly scale the Sun up in size
mSunSpinRotation; // 2. and then spin it on its axis.

g_pd3dDevice->SetTransform( D3DTS_WORLD, &mSunMatrix );
g_pSunMesh->DrawSubset(0);

This example applies to a mesh, not a primitive. I also do not see where the matrix transformation is actually applied to the mesh?? Is that in the DrawSubset(0) call? Further down the rendering process, a similar approach is repeated mutliple times for different meshes, and DrawSubset(0) is called each time. So I am guessing that this is part of applying the transformation to the mesh, but my searches on the DrawSubset() function didn't turn up much info. Can anyone point me in the right direction for example(s) of transformations on primitives? Or provide a sample here? Thanks for any help, Brad

##### Share on other sites
I would begin with the DirectX SDK tutorials, specifically Tutorial 3: Using matrices.
Once you use SetTransform, the provided matrix is used to transform any primitives or meshes drawn after that point. The next call to SetTransform for the same matrix type (D3DTS_WORLD for example), will replace that matrix so that the new one is used instead in following draw calls. (This works for DrawPrimitive, as well as the other draw functions).

##### Share on other sites
Ok, thanks for the info Erik. That cleared it up for me.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631424
• Total Posts
3000009
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!