正确使用截头锥体

时间:2013-03-11 04:49:28

标签: opengl opengl-es

我正在读一本书:For perspective projection, avoid setting your near or far plane to zero or a negative number. Mathematically this just doesn’t work out.

指的是矩阵的nearfar参数,例如:

static Matrix4<T> Frustum(T left, T right, T bottom, T top, T near, T far)
{
    T a = 2 * near / (right - left);
    T b = 2 * near / (top - bottom);
    T c = (right + left) / (right - left);
    T d = (top + bottom) / (top - bottom);
    T e = - (far + near) / (far - near);
    T f = -2 * far * near / (far - near);
    Matrix4 m;
    m.x.x = a; m.x.y = 0; m.x.z = 0; m.x.w = 0;
    m.y.x = 0; m.y.y = b; m.y.z = 0; m.y.w = 0;
    m.z.x = c; m.z.y = d; m.z.z = e; m.z.w = -1;
    m.w.x = 0; m.w.y = 0; m.w.z = f; m.w.w = 1;
    return m;
}

好的,我明白了。但是我不能得到的是,作者然后将所有演示模型翻译为-7的z,这在屏幕上显示得很好。但如果将视锥体z近和远分别设置为5和10,为什么屏幕上的-7为什么?不应该只出现翻译为5到10之间的z的对象吗?

1 个答案:

答案 0 :(得分:0)

因为相机的znear和zfar值是距离来自相机,而不是绝对数字。他们总是积极的。这就是数学运作的方式。

相关问题