【问题标题】:Rotate quaternion in Libgdx在 Libgdx 中旋转四元数
【发布时间】:2023-04-03 00:03:01
【问题描述】:

我们如何在 libgdx 中围绕某个轴旋转四元数?


var rotation = new Quaternion().setEulerAngles(0.0f, 0.0f, 90.0f);
// How do we rotate that quaternion around X axis 90 degrees ?

【问题讨论】:

    标签: java libgdx quaternions


    【解决方案1】:

    旋转四元数意味着:将另一个四元数乘以原始四元数的右侧或左侧(取决于您要旋转的空间)。 例如,如果您希望向量先绕 X 轴旋转 90 度,然后绕 Z 轴旋转 90 度,则可以使用以下代码实现:

    // your quaternion (rotation of 90 degrees around Z axis)
    Quaternion rotation = new Quaternion().setEulerAngles(0, 0, 90);
    // quaternion expressing rotation of 90 degrees around X axis
    Quaternion x90deg = new Quaternion().setEulerAngles(0, 90, 0);
    // concatenation (right-multiply) of the X rotation with the Z rotation
    Quaternion result = new Quaternion(rotation).mul(x90deg);
    // test: rotate (0, 0, 1) around X axis 90 deg, followed by Z axis 90 deg
    // the first rotation will yield (0, -1, 0), and the second rotation (1, 0, 0) as a result
    Vector3 v = new Vector3(0, 0, 1);
    result.transform(v);
    // v = (1, 0, 0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-14
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多