我正在读一本书,上面写着:For perspective projection, avoid setting your near or far plane to zero or a negative number. Mathematically this just doesn’t work out.
它指的是矩阵的near
和far
参数,例如:
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 的 az,显示在屏幕上很好。但是如果近和远的截锥体 z 分别设置为 5 和 10,为什么屏幕上会出现 -7?不应该只出现转换为 5 到 10 之间的 az 的对象吗?