XNA 中的这种旋转行为是什么? [英] What is this rotation behavior in XNA?

查看:23
本文介绍了XNA 中的这种旋转行为是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用 XNA,有一个关于轮换的问题.当您在 XNA 中将向量乘以旋转矩阵时,它会逆时针旋转.这个我明白了.

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 弧度(testRot += 0.034906585f).我的主要困惑是,资产在此屏幕空间中顺时针旋转.这让我感到困惑,因为旋转矩阵会逆时针旋转向量.

However, let me give you an example of what I don't get. Let's say I load a random art asset into the pipeline. I then create some variable to increment every frame by 2 radians when the update method runs(testRot += 0.034906585f). The main thing of my confusion is, the asset rotates clockwise in this screen space. This confuses me as a rotation matrix will rotate a vector counter-clockwise.

另一件事,当我指定位置向量的位置以及原点时,我知道我正在绕原点旋转.我是否假设也有垂直轴穿过该资产的原点?如果是这样,轮换从哪里开始?换句话说,我是从 Y 轴的顶部开始旋转还是从 X 轴的顶部开始旋转?

One other thing, when I specify where my position vector is, as well as my origin, I understand that I am rotating about the origin. Am I to assume that there are perpendicular axis passing through this asset's origin as well? If so, where does rotation start from? In other words, am I starting rotation from the top of the Y-axis or the x-axis?

推荐答案

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

这篇关于XNA 中的这种旋转行为是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆