# Matrix rotation and axis change (XNA)

## Recommended Posts

If I rotate a sprite 90 degrees along the Z-axis and then multiply that matrix by a translation matrix, I expect my sprite to move upwards. This is because the x-axis of the sprite is now aligned with the world's z-axis. However, the sprite instead still moves right or left along the world's z-axis. Can anyone explain what's wrong?

[code]

//expect this to change the axis on which the sprite works on

Matrix rr = Matrix.CreateRotationZ(MathHelper.ToRadians(90.0f));

//moves to the right instead of upwards like I expect
Matrix tr = Matrix.CreateTranslation(new Vector3(2, 0, 0));

world = identity * rr * tr;[/code]

##### Share on other sites
[quote name='Sansros' timestamp='1306035786' post='4814099']
[code]world = identity * rr * tr;[/code]
[/quote]

Because the order in which you multiply you FIRST translate and then rotate. Read matrix multiplications from right to left. Also multiplying with identity is pointless by definition and just like multiplying a number with 1.

##### Share on other sites
[quote name='Trienco' timestamp='1306035992' post='4814101']
[quote name='Sansros' timestamp='1306035786' post='4814099']
[code]world = identity * rr * tr;[/code]
[/quote]

Because the order in which you multiply you FIRST translate and then rotate. Read matrix multiplications from right to left. Also multiplying with identity is pointless by definition and just like multiplying a number with 1.
[/quote]

So what I wrote is fine if I read right to left and do:

world = tr * rr;

correct?

##### Share on other sites
The rotation needs to be applied first so the coordinate would be multiplied like so : ObjectPosition = ( tr * (rr * objectPosition) )

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### Forum Statistics

• Total Topics
628345
• Total Posts
2982191

• 9
• 24
• 10
• 9
• 13