在libgdx中,如何绕特定轴旋转四元数?
var rotation = new Quaternion().setEulerAngles(0.0f, 0.0f, 90.0f);
// How do we rotate that quaternion around X axis 90 degrees ?
在libgdx中,如何绕特定轴旋转四元数?
var rotation = new Quaternion().setEulerAngles(0.0f, 0.0f, 90.0f);
// How do we rotate that quaternion around X axis 90 degrees ?
旋转四元数的意思是:将另一个四元数乘以你原始四元数的右边或左边(取决于你想要旋转的空间)。 例如,如果你想让一个向量先绕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)