Hi, i have implemented first person camera in OpenGL, but when i get closer to an object it starts to disappear, so i want to set near plane close to zero so i could get closer to the objects. So if anybody can tell me what is the best way to do that. Thank you.
+1
A:
The near plane is set when you set the projection matrix, either with glFrustum or glOrtho. One of the parameters is the near plane. Notice that the distance to the near plane must be > 0.
Matias Valdenegro
2010-08-04 21:48:28
The question was, how to give a good first parameter to gluPerspective
Calvin1602
2010-08-05 07:28:02
@Calvin1602: Negative. First parameter of gluPerspective is FOV. Which has nothing to do with znear and disappearing objects.
SigTerm
2010-08-05 13:29:51
Who knows what 'zNear' parameter means?
Luca
2010-08-05 19:03:12
@Luca: "Who knows" Almost every single person that ever at least tried to use OpenGL/DirectX and made it past first few tutorials. Read the documentation. znear==near clipping plane.
SigTerm
2010-08-05 19:20:43
@SigTerm My mistake : I didn't mean the 1srt parameter (obviously the FoV won't help), and according to the upvotes it was really gluPerspective that he wanted.
Calvin1602
2010-08-06 06:16:42
Obviously I was ironic!
Luca
2010-08-06 06:17:34
Hi guys, sorry i didn't replay. So. i tried gluPerspective and i can get closer to the objects, but the camera moving is all messed up, and at some point the hole object disappears. This is how i set it: gluPerspective(90,1,0.1,100). Does anybody have any idea why the moving of the camera is messed up. Thanks again.
2010-08-06 11:13:13
@skippycap: "camera moving is all messed up" doesn't describe your problem. You need to post code and screenshots (if applicable)...
SigTerm
2010-08-06 12:09:57
@skippycap : In what extent does my answer below does and does not matches what you're asking ? Basically you can't set zNear to 0, so either move your camera backwards or set zNear to a tiny value and prepare for z-fighting
Calvin1602
2010-08-08 08:41:36
A:
You don't have many options.
- Cast some rays from the camera (for instance in the 4 corners and in the center), take the shortest minus epsilon, clamped to a decent value > 0. 0.1f will do.
- Simply forbid the camera to be here in the first place ! For this you can link it to a sphere in your physics engine, check whether it intersects something, and it it does, move it (how and where to move it is your problem since it's for a large part gameplay. Think of Super Mario Galaxy)
Never set a too little nearPlane. You will run in precision issues with your z-buffer. The farPlane can be quite large though. Values like (0.1, 1000) can be all right depending on your application
Calvin1602
2010-08-05 07:27:23
actually, the thing that matters is the ratio between near and far. It directly relates to the precision of the Z-buffer.
Bahbar
2010-08-05 07:36:39
Yes, but this means that a slight change in zNear will bring you a lot more precision than the same change in zFar. So as a rule of thumb, you generaly want to increase zNear. ( 0.2/1000 much better than 0.1/999.9 )
Calvin1602
2010-08-05 08:30:30