我曾经分多个阶段旋转对象,但无法弄清楚如何获得对象的实际方向(欧拉角)。
GL.Rotate(rotateCAx, new Vector3d(1, 0, 0));
GL.Rotate(rotateCAy, new Vector3d(0, 1, 0));
GL.Rotate(rotateCAz, new Vector3d(0, 0, 1));
GL.Rotate(xRot, new Vector3d(1, 0, 0));
GL.Rotate(yRot, new Vector3d(0, 1, 0));
GL.Rotate(zRot, new Vector3d(0, 0, 1));
现在对象的方向是什么
要么从GPU读取当前矩阵:
Matrix4 currentModelView;
GL.GetFloat(GetPName.ModelviewMatrix, out currentModelView);
或计算具有相同旋转度的变换矩阵:
Matrix4 currentModelView =
Matrix4.CreateRotationX(zRot) *
Matrix4.CreateRotationY(yRot) *
Matrix4.CreateRotationZ(xRot) *
Matrix4.CreateRotationX(rotateCAz) *
Matrix4.CreateRotationY(rotateCAy) *
Matrix4.CreateRotationZ(rotateCAx);
将Matrix4
的旋转分量转换为Matrix4
:
Quaternion
从Quaternion
计算Quaternion q = currentModelView.ExtractRotation();
角度。可以在Pitch, yaw, and roll处找到的算法。我已经将Quaternion
实现用于Maths - Conversion Quaternion to Euler,OpenGL Mathematics和glm::pitch
:
glm::pitch