VB: Matrices: Object manipulation

Posted on 2005-04-18
Last Modified: 2013-12-08
Hi, I'm having some trouble working out how to manipulate a single mesh when I have multiple meshes in my world.

At the moment, my mesh creation code is:
        Set objMesh(Index).Mesh = myDX.D3DX.LoadMeshFromX(App.Path & "\resources\models\" & strModel & ".x", D3DXMESH_MANAGED, myDX.D3DDevice, Nothing, mtrlBuffer, objMesh(Index).nMaterials)

My matrix manipulation code is:
        D3DXMatrixTranslation matTranslation, 0, 0, 0
        D3DXMatrixRotationYawPitchRoll matRotation, RotX / 5000, RotY / 5000, RotZ / 5000
        D3DXMatrixScaling matScaling, 1, 1, 1
        D3DXMatrixMultiply matTransform, matRotation, matTranslation
        D3DXMatrixMultiply matTransform, matTransform, matScaling
        D3DDevice.MultiplyTransform D3DTS_WORLD, matTransform

I understand the general theory behind it, however I have no idea how to rotate a single object. Whenever I use code like this it just rotates everything.

Thanks for any assistance,
Question by:Knossos
    1 Comment
    LVL 17

    Accepted Solution

    Your matTransform should effectively start out as the identity matrix before rendering each object.  If there are master 'view' changes that you want done to the CAMERA, do them to D3DTS_PROJECTION and D3DTS_VIEW matrices, not to the WORLD matrix.  For instance, to make everything bigger in the view, scale the view, not the world... ;)

    Now, assuming all objects are independent (no hierarchies yet!), you start before each object by clearing matTransform, then set up any object-specific translation (position it in the world-space, where it was loaded in object-space coords assumedly...) to move the object around, then set up the rotations if you want the given object rotated at all, multiply up the matTransform like you've been doing, and then commit matTransform as the new world matrix.  So, before each object, you do something like:

            D3DXMatrixIdentity matTransform
            D3DXMatrixTranslation matTranslation, objectOffX, objectOffY, objectOffZ
            D3DXMatrixRotationYawPitchRoll matRotation, objectRotX, objectRotY, objectRotZ
            D3DXMatrixScaling matScaling, objectScaleX, objectScaleY, objectScaleZ
            D3DXMatrixMultiply matTransform, matRotation, matTranslation
            D3DXMatrixMultiply matTransform, matTransform, matScaling
            D3DDevice.SetTransform D3DTS_WORLD, matTransform

    Note that I used fake variables for offset/translation, rotation, and scaling, on a per-object basis.  If this stuff doesn't change at all, there's no need to multiply them in.  For instance, if translation is 0,0,0, it has no effect on the result -- same for rotation, and same for scaling = 1,1,1.  In those cases, you can optimize by not calculating and multiplying those pieces -- but do that once the framework is all together. ;)

    That make sense?  Set up your perspective matrix, set up your view matrix, then before each object start with a clean model/world/transform matrix as the identity, and add to it whatever the given object wants for manipulations, set the world matrix to that, then render that object.  Rinse and repeat.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
    As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now