Public Group

# Matrix rotation and axis change (XNA)

This topic is 2586 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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?

 //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;

##### Share on other sites

world = identity * rr * tr;

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='Sansros' timestamp='1306035786' post='4814099']
world = identity * rr * tr;

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) )

• 10
• 48
• 12
• 10
• 10
• ### Forum Statistics

• Total Topics
631381
• Total Posts
2999677
×