Hey there !

This sounds like you keep just a single matrix for each of your objects.

Using your approach, you would want to change the place where you add your matrix multiplication.

I.e. usually, you have this:

```
worldposition = Matrix * objectposition;
```

or, in detail:

```
worldposition = Translation * Rotation * objectposition
```

with: objectposition being a point local to the reference frame of your object, and worldposition being the coordinates of same point in the global coordinate system. (Sorry, I’m not one of the DX users, so this has been created based on your textual description.)

Matrix multiplication is associative, but not commutative, which means you may put in arbitrary brackets, but may not change the order of operations.

Let’s now rewrite the equation above with a few brackets:

```
worldposition = (Translation * (Rotation * objectposition))
```

As you can see, the point first is sent through the rotation matrix you created, it then is in global space, and translated to the place where it should be.

So, if you want to add another translation local to the object’s coordinates, where would you place it ? :)

Indeed, right in front of the existing translation (which is in global space). Thus, in the above case, you’d need to multiply in your translation from the left.

Thus:

```
worldposition = (new_translation * Matrix) * objectposition;
```

Another approach would be to transform the global axes with the inverse of your existing matrix, and add appropriate translation matrices for the transformed global axes to the right of your matrix stack.

Finally, note that in most cases it is better to seperate between object position and object rotation (possibly use a quaternion here instead of 3 euler angles or matrices, because both of these have severe stability issues), and rebuild an appropriate matrix when required.

Btw: If your DX matrix multiplication calls for C = A * B are matrixmult(C, A, B), which I think were the logical order, then there is something fishy in your code (since you’d have the rotation last in queue then, it would be around the objects local axes, and not around the global one as you wrote)…. just guessing here though…

Hope this helps,

Cheers,

- Wernaeh

Hi,

I want to translate the object along X and Y direction.

For that I construct a translation matrix and Multiply It to World Matrix.

D3DXMatrixTranslation(&matTrans, xDist, yDist, 0);

D3DXMatrixMultiply (&matWorld, &matWorld, &matTrans);

This works fine.

Next,I want to rotate by object around world origin along Z direction.

For that I construct a Rotation matrix and Multiply It to World Matrix.

D3DXMatrixRotationZ(&matRotZ, zAngle*0.0174);

D3DXMatrixMultiply (&matWorld, &matWorld, &matRotZ);

This rotates the object and its axes also.

Next I want to translate again.

This causes the translation to happen along the direction of rotated X,Y axes caused due to the previous rotation.

But I want the object to always translate along the World’s X and Y direction not to translate along the object’s axes.

What should I do for this?

Can Any one help?

Expecting help.