简体   繁体   English

如果我使用 glFrustum,为什么绘制的这个对象会有所不同?

[英]Why is this object drawn different if I use glFrustum?

I'm doing this OpenGL project for my Computer Graphics class, where I display an object and I rotate it and stuff, the thing is that at the beginning of the project we used glOrtho() and it looked really great.我正在为我的计算机图形类做这个 OpenGL 项目,在那里我显示一个对象并旋转它等等,问题是在项目开始时我们使用了glOrtho() ,它看起来非常棒。

glOrthoOBJ

But now the teacher said that we have to use glFrustum() for perspective and if I use that function, the object is drawn like this and I really don't know why does this happens:但是现在老师说透视必须用glFrustum() ,如果我用那个函数,对象是这样画的,我真的不知道为什么会这样:

视锥体对象

This is my code from the init() function where everything changes:这是我的init()函数中的代码,其中一切都发生了变化:

void init (void)
{
    /*  select clearing (background) color       */
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-100.0, 100.0, -60.0, 160.0, -100.0, 100.0);
    //glFrustum(-100, 100 ,-100 ,100 ,1 , 40);


    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(90,0,1,0);
}

I'd appreciate your help.我很感激你的帮助。

EDIT: If I use glFrustum(-100, 100, -100, 100, 20, 200) it looks like this, like I'm getting closer but what about the left, right, top and bottom parameters?编辑:如果我使用 glFrustum(-100, 100, -100, 100, 20, 200) 它看起来像这样,就像我越来越接近但是左边,右边,顶部和底部参数呢? Are they okay with that values?他们对这个价值观没意见吗?

在此处输入图片说明

It's hard to be certain without more information.没有更多信息就很难确定。 Perhaps the model could give some insight.也许该模型可以提供一些见解。 But I suspect it may have to do with your clipping planes ( nearVal and farVal as described here ) arguments passed to glFrustum ( 1, 40 ).但我怀疑它可能与你的裁剪平面(做nearValfarVal描述这里)传递给参数glFrustum1, 40 )。 Perhaps try setting them to a broader range like your glOrtho call: 1, 150 (Note: neither nearVal or farVal can be negative when passed to glFrustum ).也许尝试将它们设置为更广泛的范围,例如您的glOrtho调用: 1, 150 (注意:传递给glFrustum时, nearValfarVal都不能为负)。

This all depends on the scale of the model and how it is positioned relative to the camera.这一切都取决于模型的比例以及它相对于相机的定位方式。 If part of the model falls outside of the clipping planes, then it will be, well... clipped.如果模型的一部分落在剪裁平面之外,那么它将被剪裁。

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

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