2012-06-15 19 views
0

我试着用不同的旋转方式旋转一些顶点 - GL.Rotate,Matrix4.CreateRotationX和Matrix4.RotateX。令我惊讶的是他们给出了不同的结果 以下是创建三个矩阵并将其输出到控制台的功能。GL.Rotate和Matrix4.CreateRotationX不同的输出

private void for_debug() 
    { 
     Vector3 CubeRotationAnglesInDeg = new Vector3(15, 29, 84); 

     Matrix4 XCubeRotationMatrix1 = Matrix4.CreateRotationX(Helper.ToRadians(CubeRotationAnglesInDeg.X)), 
       YCubeRotationMatrix1 = Matrix4.CreateRotationY(Helper.ToRadians(CubeRotationAnglesInDeg.Y)), 
       ZCubeRotationMatrix1 = Matrix4.CreateRotationZ(Helper.ToRadians(CubeRotationAnglesInDeg.Z)); 
     Matrix4 finalMatrixMine1 = XCubeRotationMatrix1 * YCubeRotationMatrix1 * ZCubeRotationMatrix1; 


     Matrix4 XCubeRotationMatrix2 = Matrix4.RotateX(Helper.ToRadians(CubeRotationAnglesInDeg.X)), 
       YCubeRotationMatrix2 = Matrix4.RotateY(Helper.ToRadians(CubeRotationAnglesInDeg.Y)), 
       ZCubeRotationMatrix2 = Matrix4.RotateZ(Helper.ToRadians(CubeRotationAnglesInDeg.Z)); 
     Matrix4 finalMatrixMine2 = XCubeRotationMatrix2 * YCubeRotationMatrix2 * ZCubeRotationMatrix2; 


     GL.MatrixMode(MatrixMode.Modelview); 
     GL.LoadIdentity(); 
     GL.Rotate(CubeRotationAnglesInDeg.X, Vector3.UnitX); 
     GL.Rotate(CubeRotationAnglesInDeg.Y, Vector3.UnitY); 
     GL.Rotate(CubeRotationAnglesInDeg.Z, Vector3.UnitZ); 
     Matrix4 finalMatrixOpen; 
     GL.GetFloat(GetPName.ModelviewMatrix, out finalMatrixOpen); 

     Console.WriteLine(finalMatrixMine1.Column0); 
     Console.WriteLine(finalMatrixMine1.Column1); 
     Console.WriteLine(finalMatrixMine1.Column2); 
     Console.WriteLine(finalMatrixMine1.Column3); 
     Console.WriteLine(); 

     Console.WriteLine(finalMatrixMine2.Column0); 
     Console.WriteLine(finalMatrixMine2.Column1); 
     Console.WriteLine(finalMatrixMine2.Column2); 
     Console.WriteLine(finalMatrixMine2.Column3); 
     Console.WriteLine(); 

     Console.WriteLine(finalMatrixOpen.Column0); 
     Console.WriteLine(finalMatrixOpen.Column1); 
     Console.WriteLine(finalMatrixOpen.Column2); 
     Console.WriteLine(finalMatrixOpen.Column3); 
     Console.WriteLine(); 

     Console.WriteLine(); 
     Console.WriteLine(); 
     Console.WriteLine(); 
     Console.WriteLine(); 
    } 

而这里的ToRadians功能

public static float ToRadians(float degrees) 
    { 
     return degrees * (float)(Math.PI/180f); 
    } 

这是正常的,我能做些什么来使结果一样吗?

编辑: 这里的输出

(0.09142262, -0.9475183, 0.3063508, 0) 
(0.8698285, 0.2257573, 0.4386708, 0) 
(-0.4848096, 0.2263682, 0.8448178, 0) 
(0, 0, 0, 1) 

(0.09142262, -0.9475183, 0.3063508, 0) 
(0.8698285, 0.2257573, 0.4386708, 0) 
(-0.4848096, 0.2263682, 0.8448178, 0) 
(0, 0, 0, 1) 

(0.09142266, -0.8698285, 0.4848096, 0) 
(0.9737504, -0.02382383, -0.2263682, 0) 
(0.2084515, 0.4927787, 0.8448178, 0) 
(0, 0, 0, 1) 
+0

请发布输出 - 它会帮助那些不能/不想重新创建样本的人。 – Ani

回答

0

我怀疑你应该把你的GL.Rotate()命令以相反的顺序来得到想要的结果。