2010-06-08 54 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); 
}