Jump to content
  • Advertisement
Sign in to follow this  

DirectX Matrix Transformations

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

If you intended to correct an error in the post then please contact us.

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 );
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 this post

Link to post
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 this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!