让我们看看我是否可以解释自己。
当您设置 glFrustum 视图时,它将给出透视效果。近事近大...远事远小。一切看起来都沿着 Z 轴收缩以产生这种效果。
有没有办法让它不缩小那么多?将透视图接近正交视图....但完全失去透视图并没有那么多?
谢谢
角度由两个参数决定:最近的剪裁平面的高度(由 top 和 bottom 参数确定)和最近的剪裁平面的距离(由 zNearest 确定)。要制作透视矩阵以使其不会过度缩小图像,您可以设置较小的高度或更接近的剪切平面。
问题是要了解正交视图是 FOV 为零且相机位置无限远的视图。因此,有一种方法可以通过减少 FOV 并将相机移远来接近正交视图。
我可以建议使用以下代码从给定的theta
FOV 值计算近正交投影相机。我在个人项目中使用它,虽然它使用自定义矩阵类而不是glOrtho
and glFrustum
,所以它可能不正确。我希望它可以提供一个好的总体思路。
void SetFov(int width, int height, float theta)
{
float near = -(width + height);
float far = width + height;
/* Set the projection matrix */
if (theta < 1e-4f)
{
/* The easy way: purely orthogonal projection. */
glOrtho(0, width, 0, height, near, far);
return;
}
/* Compute a view that approximates the glOrtho view when theta
* approaches zero. This view ensures that the z=0 plane fills
* the screen. */
float t1 = tanf(theta / 2);
float t2 = t1 * width / height;
float dist = width / (2.0f * t1);
near += dist;
far += dist;
if (near <= 0.0f)
{
far -= (near - 1.0f);
near = 1.0f;
}
glTranslate3f(-0.5f * width, -0.5f * height, -dist);
glFrustum(-near * t1, near * t1, -near * t2, near * t2, near, far);
}