Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

VB: Matrices: Object manipulation

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,
Knossos.
0
Knossos
Asked:
Knossos
1 Solution
 
davebytesCommented:
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.

-d
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now