简体   繁体   English

正交和透视投影OpenGL

[英]Orthogonal & Perspective Projection OpenGL

I am using the code snippet below to switch between orthogonal and perspective projections based on the user's selection. 我正在使用下面的代码片段根据用户的选择在正交投影和透视投影之间切换。 However, irrespective of the user's choice the rendered model is always in orthogonal projection. 但是,无论用户选择如何,渲染的模型始终处于正交投影状态。 Could you please let me know what am I missing here. 您能否让我知道我在这里想念什么。

Orthogonal 正交的

Perspective 透视

As seen above, the perspective projection obtained currently is just a zoomed in version of the orthogonal projection. 如上所述,当前获得的透视投影只是正交投影的放大版本。

Thank you. 谢谢。

float fov = 10.0;
float Oleft = -1.0, Oright = 1.0, Obottom = -1.0, Otop = 1.0;

 glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    if(proj_type==0)
        gluPerspective(fov, 1, 0.1, 200);
    else
        glOrtho(Oleft, Oright, Obottom, Otop,0.1,50);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(10, 7, 10, 0, 0, 0, 0, 1, 0);

Orthogonal projection in fact is perspective with FoV = 0.0f. 正交投影实际上是FoV = 0.0f的透视图。 Lowering FoV in perspective makes it looks similar to orthogonal. 降低FoV的角度使其看起来类似于正交。

Just move camera close and increase FoV to 45-60 degrees. 只需将相机移近,并将FoV增大至45-60度即可。 https://www.packtpub.com/graphics/9781849691727/graphics/1727_04_24.jpg https://drive.google.com/file/d/0B2jjLSK7_nvaVE9WUGZRenJ0bVE/view?usp=sharing https://www.packtpub.com/graphics/9781849691727/graphics/1727_04_24.jpg https://drive.google.com/file/d/0B2jjLSK7_nvaVE9WUGZRenJ0bVE/view?usp=sharing

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

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