且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

XNA 中的这种旋转行为是什么?

更新时间:2023-11-20 19:49:22

XNA SpriteBatch 在 Client Space 中工作.其中向上"是 Y-,而不是 Y+(如笛卡尔空间、投影空间以及大多数人通常为他们的世界空间选择的空间).这使得旋转显示为顺时针(不像在笛卡尔空间中那样逆时针).旋转产生的实际坐标是相同的.

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.

如果您正在使用诸如 sincosatan2 之类的数学函数,那么绝对角度总是从X+轴为零弧度,正旋转方向向Y+旋转.

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

SpriteBatch 的操作顺序如下所示:

The order of operations of SpriteBatch looks something like this:

  1. Sprite 从左上角为 (0,0) 的四边形开始,其大小与其纹理大小(或 SourceRectangle)相同.
  2. 将精灵按原点平移回原点(因此将其原点置于 (0,0)).
  3. 缩放精灵
  4. 旋转精灵
  5. 根据精灵的位置翻译精灵
  6. 应用 SpriteBatch.Begin 中的矩阵
  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.

最后,将矩阵应用于每个批次,以将该客户空间转换为 GPU 使用的投影空间.(投影空间从视口左下角的 (-1,-1) 到右上角的 (1,1).)

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