简体   繁体   English

Directx11围绕世界中心旋转?

[英]Directx11 rotation around center of world?

I've been playing around for awhile now with directx and can't figure out how to rotate something without rotating it all the way around (0,0,0). 我已经使用DirectX玩了一段时间了,无法弄清楚如何旋转某些内容而不将其一直旋转(0,0,0)。 The farther I get away from the center of my world the bigger circles in makes during its rotation. 我离世界中心越远,旋转过程中产生的圆圈越大。

If you need a rotation α, around a point p located at (x₀,y₀,z₀), you create the matrix : 如果需要旋转α,围绕(x₀,y₀,z a)处的点p,则创建矩阵:

T(-x₀,-y₀,-z₀) * R(α) * T(x₀,y₀,z₀)

T means Translation and R means rotation. T表示平移,R表示旋转。 Also, depending on your convention such as row or column matrix, you may have to revert the order of operation. 另外,根据行或列矩阵等惯例,您可能必须还原操作顺序。

Don't forget the matrix transformations apply to the coordinate system. 不要忘记将矩阵变换应用于坐标系。 Let's say you want to move your object upwards on an xy plane by 20 units, and rotate it by 90 degrees. 假设您要在xy平面上将对象向上移动20个单位,然后将其旋转90度。 If you rotate by 90 degrees first, you'll be rotating the entire plane by 90 degrees. 如果先旋转90度,则将整个平面旋转90度。 This means 90 degrees is the new "upwards" when you translate up the y axis. 这意味着90度是向上y轴平移的新“向上”。

So, we translate first, so that our object's center is 0,0. 因此,我们首先进行平移,以使对象的中心为0,0。 Now when we rotate, we should be rotating around the center of the object. 现在,当我们旋转时,我们应该围绕对象的中心旋转。 Of course, don't forgot to translate back, or clear the matrix somehow. 当然,不要忘记翻译回来或以某种方式清除矩阵。

The order does matter when doing matrix transformations, as I'm sure you know. 如您所知,顺序在进行矩阵转换时很重要。 Usually, you should translate, scale, then rotate. 通常,您应该平移,缩放然后旋转。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM