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

Get Learning XNA 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.