# XNA and Draw rotation

From Wikipedia the (image) conversion degrees / radians shows the quadrants so that the increase of radians causes a counter-clockwise rotation but when using the following code the sprite is rotated clockwise:

rotation = (rotation + 0.5f) % MathHelper.ToRadians(360);
...
spriteBatch.Draw(sprite, sprite_center_other_sprite, new Rectangle(0, 0, 50, 50), Color.White, rotation, new Vector2(width/2, height/2),1.0f, SpriteEffects.None, 0.0f);


Why? The direction is a convention or XNA is different?

• Are you sure about the first line? MathHelper.ToRadians(360) is exactl 2Pi, which is available as a constant from MathHelper. Also, why do you add 0.5 radians to the rotation? Did you mean half Pi? Jul 17 '12 at 11:37
• @Marton, Yes I'm sure that line does a rotation between 0 and 6,14 radians at 0.5 step. Jul 17 '12 at 11:51

As posted in this question on SO:

The XNA SpriteBatch works in Client Space. Where "up" is Y-, not Y+ (as in Cartesian space, projection space, and what most people usually select for their world space). This makes the rotation appear as clockwise (not counter-clockwise as it would in Cartesian space).

So, that said, if this code is intended to prevent the angle from getting too large, consider using the MathHelper.WrapAngle() method. This method wraps the angle you give it (in radians) to between π (180°) and -π(-180°).

rotation = MathHelper.WrapAngle(rotation + 0.5f);


Note: If it is in your Update statement, you may also want to multiply the 0.5f against the elapsed game time so that your rotation speed is per second and not per Update. The final line would be:

rotation = MathHelper.WrapAngle(rotation + 0.5f * (float)gameTime.ElapsedGameTime.TotalSeconds);