What is this rotation behavior in XNA?

前端 未结 2 545
无人及你
无人及你 2021-01-02 22:17

I am just starting out in XNA and have a question about rotation. When you multiply a vector by a rotation matrix in XNA, it goes counter-clockwise. This I understand.

2条回答
  •  执念已碎
    2021-01-02 22:46

    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). The actual coordinates the rotation is producing are the same.

    Rotations are relative, so they don't really "start" from any specified position.

    If you are using maths functions like sin or cos or atan2, then absolute angles always start from the X+ axis as zero radians, and the positive rotation direction rotates towards Y+.


    The order of operations of SpriteBatch looks something like this:

    1. Sprite starts as a quad with the top-left corner at (0,0), its size being the same as its texture size (or SourceRectangle).
    2. Translate the sprite back by its origin (thus placing its origin at (0,0)).
    3. Scale the sprite
    4. Rotate the sprite
    5. Translate the sprite by its position
    6. Apply the matrix from SpriteBatch.Begin

    This places the sprite in Client Space.

    Finally a matrix is applied to each batch to transform that Client Space into the Projection Space used by the GPU. (Projection space is from (-1,-1) at the bottom left of the viewport, to (1,1) in the top right.)

提交回复
热议问题