iPhone中的物体离得很远时,表面破裂 [英] surfaces got broken when object is far away in iphone

查看:63
本文介绍了iPhone中的物体离得很远时,表面破裂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opengl es显示对象.

I am using the opengl es to display objects.

当物体靠近相机时,一切就完美了. 但是如果将物体移离相机较远,则物体的表面会破裂.

when the object is near to the camera, everything is perfect. but if the objects are moved faraway from the camera, the surface of objects would break.

破碎的物体将像:

绘制对象的代码段为:

glVertexPointer(3, GL_FLOAT, 32, self.vertices);
glNormalPointer(GL_FLOAT, 32, &(self.vertices[3]));
glTexCoordPointer(2, GL_FLOAT, 32, &(self.vertices[6]));    

glDrawElements(GL_TRIANGLES, self.indexNumber, GL_UNSIGNED_SHORT, &(self.faces[0]));

我想原因可能是浮点数的精度.

I guess the reason could be the precision of float number.

有人对此有解决方案吗?谢谢

Anyone have a solution for this? thanks

推荐答案

问题是深度缓冲区的精度.

The problem is depth-buffer precision.

深度值按比例缩放,以使较近的对象比较远的对象具有更大的可能深度值范围.因此,远处的物体更有可能表现出Z角争斗和其他此类问题.请参见此常见问题解答中的问题12.070.

Depth values are scaled such that closer objects have a greater range of possible depth values than those further away. Distant objects are therefore more likely to exhibit z-fighting and other such problems. See question 12.070 in this FAQ.

应始终将近视锥台和远视锥台平面设置为尽可能靠近:即:近视台平面应尽可能远离摄像头,同时仍比渲染对象更近,并且远视平面应为尽可能靠近,但仍比渲染的对象更远.

The near and far frustum planes should always be set to be as close together as possible: i.e.: the near plane should be as far from the camera as possible while still being closer than the rendered object, and the far plane should be as close as possible while still being further away than the rendered object.

看起来您只是在渲染一个对象-找到该对象上最近的点和最近的点,为安全起见添加一点填充,然后将这些值用于近平面和远平面.

It looks like you're just rendering the one object - find the nearest and closest points on that object, add a bit of padding for safety, and use those values for the near and far planes.

如果必须使用远处和前景中的对象来渲染场景,并且遇到类似的问题,则可以将渲染分为两个阶段.首先使用适当的近和远值渲染远处的对象,然后清除深度缓冲区,并使用各自的适当的近和远值渲染前景对象.

If you have to render a scene with objects both in the distance and the foreground and you run into similar problems you can split the rendering into two phases. First render the distant objects with appropriate near and far values, then clear the depth buffer and render the foreground objects with their own appropriate near and far values.

这篇关于iPhone中的物体离得很远时,表面破裂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆