我想为现有的四元数添加欧拉角。这是我得到的:
Quaternion oldTransform = transform.Rotation;
float YawRotation = mouseDiff.x * RotationSpeed;
Quaternion YawRotationQuaternion = new Quaternion();
YawRotationQuaternion.CreateFromAxisAngle (0, 1, 0, YawRotation);
float PitchRotation = mouseDiff.y * RotationSpeed;
Quaternion PitchRotationQuaternion = new Quaternion();
PitchRotationQuaternion.CreateFromAxisAngle ( 1, 0, 0, PitchRotation);
Quaternion result = oldTransform * YawRotationQuaternion * PitchRotationQuaternion;
transform.Rotation = result;
我只想有偏航和俯仰旋转。旧变换具有此属性。我添加的欧拉角也只是俯仰和偏航旋转。当我乘以它时会发生什么,oldTransform 描述的旋转引入了滚动旋转。
然后我尝试了:
Quaternion result = YawRotationQuaternion * oldTransform * PitchRotationQuaternion;
这不会引入滚动旋转。此选项更糟糕,因为当 oldTransform 将偏航轴旋转到俯仰轴上时,它具有万向节锁定。
现在我可以想象的是,人们从 oldTransform 获取旧的偏航和俯仰旋转并修改偏航和俯仰轴,使它们不再是 (0,1,0) 和 (1,0,0)。这里的问题是,当我从四元数中提取欧拉角时,我也会得到万向节锁。
那么如何将特定轴的欧拉角添加到四元数?