Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.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# OpenGL中的旋转问题_C#_Opengl_Rotation_Quaternions_Opentk - Fatal编程技术网

C# OpenGL中的旋转问题

C# OpenGL中的旋转问题,c#,opengl,rotation,quaternions,opentk,C#,Opengl,Rotation,Quaternions,Opentk,我正在OpenGL中开发一个3D应用程序,我想像在AutoCad、SolidEdge或其他CAD程序中一样用鼠标旋转对象。顺便说一句,我对3D编程和OpenGl一无所知。 我试过使用GL.Rotate,但据我所知,它很复杂,对用户来说也不是很吸引人,因为围绕一个轴的旋转会影响其他轴。所以我一直在寻找,我找到了四元数。我以为我了解它们是如何工作的,但当我运行应用程序时,我使用的GLControl是完全白色的。同样在调试模式下,我看到矩阵“Mat”中充满了NaN,我认为这就是问题所在。AngX和An

我正在OpenGL中开发一个3D应用程序,我想像在AutoCad、SolidEdge或其他CAD程序中一样用鼠标旋转对象。顺便说一句,我对3D编程和OpenGl一无所知。 我试过使用GL.Rotate,但据我所知,它很复杂,对用户来说也不是很吸引人,因为围绕一个轴的旋转会影响其他轴。所以我一直在寻找,我找到了四元数。我以为我了解它们是如何工作的,但当我运行应用程序时,我使用的GLControl是完全白色的。同样在调试模式下,我看到矩阵“Mat”中充满了NaN,我认为这就是问题所在。AngX和AngY是我在鼠标移动中改变的旋转角度 这就是我所做的:

主回路:

Mat = Matrix4d.Identity; //Global
Vector3d vect1 = new Vector3d(0, -1, 0);
Vector3d vect2 = new Vector3d(-1, 0, 0);
QuatRot1 = new Quaterniond(vect1, AngX);//Global
QuatRot2 = new Quaterniond(vect2, AngY);//Global
QuatRot1.Normalize();
QuatRot2.Normalize();
Quaterniond.Multiply(QuatAcc, QuatRot1);
Quaterniond.Multiply(QuatAcc, QuatRot2);
Matrix4d.CreateFromQuaternion(ref QuatAcc, out Mat);// I think the problem is here
AngX = 0;
AngY = 0;
GL.MultMatrix(ref Mat);
鼠标移动:

if (WheelPress)
{   //mouse1 previous mouse position
    //mouse0 current mouse position 
    AngY = 0.1f * (mouse1.X - mouse0.X);
    AngX = 0.1f * (mouse1.Y - mouse0.Y);
    Cursor.Current = Cursors.Hand;
    glControl1.Refresh();
}
另外,我不知道这是否重要,但我与OpenTK合作