0

我尝试使用不同的旋转方式来旋转一些顶点——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)
4

2 回答 2

0

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

于 2015-04-04T13:56:36.700 回答
0

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

于 2012-07-10T14:12:00.657 回答