Jump to content
  • Advertisement
Sign in to follow this  
Sansros

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!