Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在OpenTK C中获取对象的方向#_C#_Winforms_Opengl_Opentk_Opengl Compat - Fatal编程技术网

C# 在OpenTK C中获取对象的方向#

C# 在OpenTK C中获取对象的方向#,c#,winforms,opengl,opentk,opengl-compat,C#,Winforms,Opengl,Opentk,Opengl Compat,我曾经在多个阶段旋转一个对象,但我不知道如何获得对象的实际方向(欧拉角度) 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(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));

现在对象的方向是什么

当您将角度应用于当前矩阵时,我建议更改角度的顺序:

GL.Rotate(rotateCAz, new Vector3d(1, 0, 0));
GL.Rotate(rotateCAy, new Vector3d(0, 1, 0));
GL.Rotate(rotateCAx, new Vector3d(0, 0, 1));
GL.Rotate(zRot, new Vector3d(1, 0, 0));
GL.Rotate(yRot, new Vector3d(0, 1, 0));
GL.Rotate(xRot, new Vector3d(0, 0, 1));
从GPU读回当前矩阵:

Matrix4 currentModelView;
GL.GetFloat(GetPName.ModelviewMatrix, out currentModelView);
或计算具有相同旋转的变换矩阵:

Matrix4 currentModelView=
Matrix4.CreateRotationX(xRot*(float)Math.PI/180.0f)*
Matrix4.CreateRotationY(yRot*(float)Math.PI/180.0f)*
Matrix4.CreateRotationZ(zRot*(float)Math.PI/180.0f)*
Matrix4.CreateRotationX(rotateCAx*(float)Math.PI/180.0f)*
Matrix4.CreateRotationY(rotateCAy*(float)Math.PI/180.0f)*
Matrix4.CreateRotationZ(rotateCAz*(float)Math.PI/180.0f);
将的旋转组件转换为:

从四元数计算角度。可在中找到的算法。我已将实施用于,并且:

const double epsi=0.0001;
双y=2.0*(q.y*q.Z+q.W*q.X);
双x=q.W*q.W-q.x*q.x-q.Y*q.Y+q.Z*q.Z;
双节距=(数学Abs(q.X)
角度
俯仰
偏航
滚动
对应于当前围绕x、y和z轴的旋转(在视图空间中)


偏航、俯仰和横摇值突然变化,并在-3和+3之间继续循环。即使角度变化一个角度,也会将其从-1变为2.5
Quaternion q = currentModelView.ExtractRotation();
float rot_x = pitch * 180.0f / (float)Math.PI; 
float rot_y = yaw   * 180.0f / (float)Math.PI; 
float rot_z = roll  * 180.0f / (float)Math.PI;