What is this rotation behavior in XNA?

前端 未结 2 527
无人及你
无人及你 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.)

    0 讨论(0)
  • 2021-01-02 22:48

    Since you are new to XNA, allow me to introduce a library that will greatly help you out while you learn. It is called XNA Debug Terminal and is an open source project that allows you to run arbitrary code during runtime. So you can see if your variables have the value you expect. All this happens in a terminal display on top of your game and without pausing your game. It can be downloaded at http://www.protohacks.net/xna_debug_terminal It is free and very easy to setup so you really have nothing to lose.

    0 讨论(0)
提交回复
热议问题