为什么当我使用旋转摄像机渲染场景时,您希望出现在其他对象后面的场景却没有这样做? OPENGL Objective-c
我正在渲染一个场景,其中有两个球体。我正在围绕其中一个旋转相机。所发生的事情是违反直觉的。当摄像机绕球体旋转时,另一个摄像机却在它前面,而您预计它在后面。因此,看起来好像这些球体并没有围绕彼此旋转,而应该围绕的球体总是在前面。请帮忙。
以下是渲染场景的代码:
glLoadIdentity();
[self positionCamera];
glutSolidSphere(2, 12,12);
glPushMatrix();
glTranslatef(5, 0, 0);
glutSolidSphere(0.5, 12,12);
glPopMatrix();
glFlush();
该块是使用时调用的类的一部分。
[NSTimer scheduledTimerWithTimeInterval:DEFAULT_ANIMATION_INTERVAL
target:self
selector:@selector(drawRect)
userInfo:nil
repeats:YES];
并
-(void)positionCamera{}
包含相机旋转数学和 gluLookAt()
I am rendering a scene in which I have two spheres. I am revolving a camera around one of them. What happens is counter-intuitive. When the camera goes around the sphere the other gets in front of it when you'd expect it to be behind. So it appears as though the spheres aren't revolving around each other and the one the should go around is always upfront. Please help.
Here is the code that renders the scene:
glLoadIdentity();
[self positionCamera];
glutSolidSphere(2, 12,12);
glPushMatrix();
glTranslatef(5, 0, 0);
glutSolidSphere(0.5, 12,12);
glPopMatrix();
glFlush();
This block is part of a class that gets called on using.
[NSTimer scheduledTimerWithTimeInterval:DEFAULT_ANIMATION_INTERVAL
target:self
selector:@selector(drawRect)
userInfo:nil
repeats:YES];
And
-(void)positionCamera{}
Contains math do camera revolution and gluLookAt()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您现在正在做的是从后到前的渲染,其中最后绘制的图元将始终显示在其他图元之上。
您想要做的是启用深度测试,在屏幕上绘制之前将比较每个片段的深度。
glEnable(DEPTH_TEST)
应该有帮助。Basically what you're doing now is a back-to-front rendering, where the last primitive drawn will always appear be drawn over the others.
What you want to do is enable the depth test, where the depth of each fragment will be compared before being drawn on screen.
glEnable(DEPTH_TEST)
should help.