Matrix 我需要一个右手正交和透视投影矩阵的公式

Matrix 我需要一个右手正交和透视投影矩阵的公式,matrix,3d,Matrix,3d,我正在用右手坐标做一个3D图形“蓝色屏幕上的无结构立方体”测试。然而,它们被奇怪地剪裁或扭曲(在正交法中,显示的左侧在窗口结束之前结束;在透视图中,看起来显示从左后到右前延伸) 不确定问题到底是什么,但投影矩阵似乎是一个很好的起点 我现在使用的是: // Went back to where I found it and found out this is a // left-handed projection. Oops! public static Matrix4x

我正在用右手坐标做一个3D图形“蓝色屏幕上的无结构立方体”测试。然而,它们被奇怪地剪裁或扭曲(在正交法中,显示的左侧在窗口结束之前结束;在透视图中,看起来显示从左后到右前延伸)

不确定问题到底是什么,但投影矩阵似乎是一个很好的起点

我现在使用的是:

    // Went back to where I found it and found out this is a 
    // left-handed projection. Oops!
    public static Matrix4x4 Orthographic(float width, float height,
        float near, float far)
    {
        float farmnear = far - near;
        return new Matrix4x4(
            2 / width, 0, 0, 0,
            0, 2 / height, 0, 0,
            0, 0, 1 / farmnear, -near / farmnear,
            0, 0, 0, 1
            );
    }


    // Copied from a previous project.
    public static Matrix4x4 PerspectiveFov(float fov, float aspect, 
        float near, float far)
    {
        float yScale = 1.0F / (float)Math.Tan(fov / 2);
        float xScale = yScale / aspect;
        float farmnear = far - near;
        return new Matrix4x4(
            xScale, 0, 0, 0,
            0, yScale, 0, 0,
            0, 0, far / (farmnear), 1,
            0, 0, -near * far / (farmnear), 1
            );
    }

谢谢

解决了-谢谢你的帮助。这不是投影矩阵;这是LookAt/View矩阵中的一个错误变量。一切都显示正确,现在它是固定的

    public static Matrix4x4 LookAt(Vector3 eye, Vector3 target, Vector3 up)
    {
        Vector3 zAxis = target; zAxis.Subtract(ref eye); zAxis.Normalize();
        Vector3 xAxis = up; xAxis.Cross(zAxis); xAxis.Normalize();
        Vector3 yAxis = zAxis; yAxis.Cross(xAxis);
        return new Matrix4x4(
            xAxis.X, yAxis.X, zAxis.Z, 0, // There.
            xAxis.Y, yAxis.Y, zAxis.Y, 0,
            xAxis.Z, yAxis.Z, zAxis.Z, 0,
            -xAxis.Dot(eye), -yAxis.Dot(eye), -zAxis.Dot(eye), 1
            );
    }

哎呀。:)

您的转换管道是什么样的?或者你正在使用一些3D图形API,比如OpenGL或Direct3D?我正在使用SlimDX(基本上是针对.Net的DirectX包装器)作为后端,顶部是我自己的库。而且…我不确定“转换管道”是什么,但这里有一些相关代码的粘贴库:-我知道这是一个黑客;这是对基本功能的早期测试。使用“转换管道”,我指的是将顶点的3d坐标转换为屏幕坐标的方式。但是,既然你说你使用的是Direct3D,这是很明显的。但是请记住,如果你使用的是顶点着色器,这取决于着色器如何变换顶点。我目前没有使用的着色器。你能看到我的投影代码有什么明显的错误吗?努力提高我的数学水平,但这不是一个立竿见影的过程。