2010-06-08 94 views
2

让我们看看我能否解释一下自己。OpenGL-ES改变视锥的视角

当您设置glFrustum视图时,它会给出透视效果。近东西附近的东西&大...远东东西&小。一切都看起来像沿着它的Z轴收缩来产生这种效果。

有没有办法让它缩小那么多? 要接近正视视角的透视图....但没有那么多,完全失去视角?

由于

回答

1

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

1

事情是了解正投影视图是一个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); 
}