透视矩阵-无深度

时间:2019-03-13 18:30:08

标签: java matrix perspective

我正在使用Java开发3D引擎,但是没有深度。

我使用的透视图矩阵来自:https://solarianprogrammer.com/2013/05/22/opengl-101-matrices-projection-view-model/

public static void initPerspectiveMatrix(double FOV, double near, double far) {
    double top = near * Math.tan(Math.toRadians(FOV / 2.0));
    double bottom = -top;
    double right = top * (Main.WIDTH / Main.HEIGHT);
    double left = -right;

    PROJECTION_MATRIX.set(new double[]{
            (2 * near) / (right - left), 0, (right + left) / (right - left), 0,
            0, (2 * near) / (top - bottom), (top + bottom) / (top - bottom), 0,
            0, 0, -((far + near) / (far - near)), -((2 * far * near) / far - near),
            0, 0, -1, 0
    });
}

这是乘法方法:

public Vec3D multiply(Vec3D input) {
    Vec3D output = new Vec3D(0, 0, 0);

    output.x = input.x * matrix[0][0] + input.y * matrix[0][1] + input.z * matrix[0][2] + matrix[0][3];
    output.y = input.x * matrix[1][0] + input.y * matrix[1][1] + input.z * matrix[1][2] + matrix[1][3];
    output.z = input.x * matrix[2][0] + input.y * matrix[2][1] + input.z * matrix[2][2] + matrix[2][3];
    double w = input.x * matrix[3][0] + input.y * matrix[3][1] + input.z * matrix[3][2] + matrix[3][3];

    if(w != 1.0) {
        output.x /= output.w;
        output.y /= output.w;
        output.z /= output.w;
    }

    return output;
}

为什么没有深度?

0 个答案:

没有答案