Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

More on Rotations

Another thing you may have noticed when playing around with your triangle is that when the application first starts, the triangle appears to be spinning in place. If you move the triangle to the left, it still rotates, but now it appears to be orbiting the origin rather than spinning in place. This is because the order of the translation and the rotation makes a big difference in the resulting effect.

When a rotation is applied, the rotation always rotates the object around the origin. In your code, you are applying the translation first and then the rotation during every frame. So, when the application first loads, the object is drawn at the origin and the rotation causes it to rotate around the origin, which gives the effect of it spinning in place.

However, once you move the object to the left, adding the rotation to the object so that it rotates around the origin (which now is to the right of the object) causes it to have an orbiting effect.

To get your object to spin in place regardless of where it is, you'll need to apply the rotation first, and then the translation. This will cause the rotation to be applied while the object is at the origin (giving it the effect of spinning in place), and the translation will then move the object and its rotation to the specified location.

For this to work, instead of having a single object representing the world for the triangle, you'll need to add two variables to represent the world of the object (you can also remove the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page