开发者

My 3D object (opengl es) is disappearing behind the iPhone camera view

I have an augmented reality iPhone app that I am converting from Core Animation to OpenGL ES 1.1. I have added code that has been modified from the Apple OpenGL template.

My problem is that my 3D object , when translating along the negative Z-axis (away from the user), appears to disappear into the camera view, until its completely gone. I have experimented with several solutions, but to no avail.

What I have determined:

Using the 3D icosahedron from Jeff Lamarche's blog here, the object starts it at 0,0,0 and then translates with decreasing z coordinates. By the time the z value reaches -2.0f, the object is gone. It appears as if it is disappearing behind the camera view. This is how I set my frustrum & viewport (unchanged from Apple's code)

glMatrixMode(GL_PROJECTION); size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);

//Grab the size of the screen
CGRect rect = self.bounds;
glFrustumf(-size, size,
           -size / (rect.size.width / rect.size.height),
           size / (rect.size.width / rect.size.height),
           zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

What I have tried: The camera view is the main view and several other views are added t开发者_Go百科o it as subviews, including the openGLView. I have commented those views out for test purposes. I have applied CATransforms to move the openGLView in the z direction -500 and +500, and done the same to the camera view. I have also changed the zFar in the above code to 1.0f, and it still disappears at z position of -2.0, which doesn't make sense (shouldn't it disappear at z=1.0?)

My experimentation has got me more confused than when I started ( which usually means I am missing a key piece, but I can't figure out what). Thanks for your help.


Give the zFar value a quite a big value, like 1000.

By the way remember the z values of the frustum should be given as -zNear and -zFar. So if you need your object to be translated away from you the z value should be negatively large enough to support the scene. Hence -(-zFar) becomes larger positive value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜