# Thread: Problem with the correct sequence of multiplications

1. ## Problem with the correct sequence of multiplications

Hi there,

I think I have a problem with some multiplications in my OpenGL program.
I designed a cube: I can move, spin, increase/decrease the size (it works)
I also designed a coordinatesystem to show the position of the cube in space.
And now my problem:
I start with the cube at the position (3,3,3).
Then I move the cube to the Point (0,0,0), now I spin it 10 degrees in direction of the negative z-axis. After that I want to move my cube again, for example in the positive x-axis. After the multiplication with the matrix:

(x-axis-translation +1)
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1

my cube moves in the x-direction and! in the negative y-direction. The matrix on the stack changes the y-value from -2.34 to -2,55. So my cube is a little bit under the x-z-plane. I think this is because of the rotation i did before.
How can I move the cube only in the x-direction?

2. ## Re: Problem with the correct sequence of multiplications

If you do the translation before the rotation it wont be affected by it. So you can move it along the normal axis.

Is that what you mean?

3. ## Re: Problem with the correct sequence of multiplications

Without the rotation i can move it along the axis. When i rotate the cube it moves too, but when i only want only the x direction it moves also in the y direction.

It doesn't move along the x-axis of the coordinatesystem (which is not affected by the rotation), it moves in the x-direction of the cube (after the rotation) ...

4. ## Re: Problem with the correct sequence of multiplications

First do the two translation, then your rotation. Otherwise, the second translation will be affected by your rotation.

5. ## Re: Problem with the correct sequence of multiplications

many thx, but i know that because this is the Problem

I'm searching for the answer to avoid that the rotation affect my translation.

It must be possible that i can make a translation after a rotation without moving in the x-direction of the cube, mustn't it?
The translation should be along the axis of my coordinatesystem.

6. ## Re: Problem with the correct sequence of multiplications

Ok, there is one thing to know: The order of Matrix multiplications is important! Changing it, you get different results.
E.g. you have an object in the center. First your rotate it 45 degrees around z, then you move it along x an amount of 50. Result is the object on the x-axis with distance 50 rotated.
If you would move it first and then rotate it: Imagine moving the object outwards 50 on the x-axis. Then rotate it around the _CENTER_ at 45 degrees. The object has an other position.

And last but not least: Matrix multiplies are applied from back to forth!

Good luck,

Kilam.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•