繁体   English   中英

OpenGL-ES改变视锥体的视角

[英]OpenGL-ES change angle of vision in frustum

让我们看看我是否可以解释自己。

设置glFrustum视图时,它将提供透视效果。 附近的东西和大...远远的东西。 一切看起来都沿着Z轴收缩以产生这种效果。

有没有办法让它不缩水那么多? 接近透视图到正交视图......但没有那么多完全失去视角?

谢谢

该角度由两个参数确定:最近剪裁平面的高度(由顶部和底部参数确定),以及最近剪切平面的距离(由zNearest确定)。 要制作透视矩阵使其不会过度缩小图像,可以设置较小的高度或更近的最近剪裁平面。

问题是要理解正交视图是FOV为零且摄像机位置在无穷远处的视图。 因此,有一种方法可以通过减少FOV并将相机移动到远处来逼近正交视图。

我可以建议下面的代码来自给定计算近正投影相机theta FOV值。 我在个人项目中使用它,虽然它使用自定义矩阵类而不是glOrthoglFrustum ,所以它可能是不正确的。 我希望它能提供一个很好的总体思路。

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM