GL.Rotate和Matrix 4.创建旋转不同的输出

时间:2012-06-15 13:51:03

标签: opengl opentk rotational-matrices glrotate

我尝试使用不同的旋转方式旋转一些顶点 - GL.Rotate,Matrix4.CreateRotationX和Matrix4.RotateX。令我惊讶的是,他们给出了不同的输 这是创建三个矩阵并将它们输出到控制台的函数。

    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)

2 个答案:

答案 0 :(得分:0)

它们应该相同,至少是Matrix4.CreateRotationX和Matrix4.RotateX。功能的定义是相同的。 在这里:http://www.opentk.com/files/doc/struct_open_t_k_1_1_matrix4.html#ae9868e1bd3b8aa411abd848e107a55af

答案 1 :(得分:0)

我怀疑你应该以相反的顺序放置你的GL.Rotate()命令以获得所需的结果。