O'Reilly logo

Learning XNA 3.0 by Aaron Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required