1
votes

I am building a scale model of buildings and landscape. I'm using openGL and GLUT and the function gluperspective. I know that the last two parameters of the function define the z-clipping path and can only be positive. Well I have stuff getting rendered with a negative z value. Well it is getting clipped which makes sense. Does anyone have a suggestion on how to stop this from clipping my things with a negative z value? My call to the gluperspective is below.

gluPerspective(50.0, (double)w / (double)h, 1.0, 300.0);
1
Just shift the coordinates of the vertices to make sure they are in the right range. - stardt
@stardt I thought about doing that but when I rotate it wouldn't is still rotate into the negative range since I'm rotating around the y-axis? This is my call to the rotate function. glRotatef(_angle, 0.0f, 1.0f, 0.0f); - jcmitch
You could rotate either by transforming the points or by moving the camera. The docs for glMatrixMode() at opengl.org/sdk/docs/man/xhtml/glMatrixMode.xml may help. - stardt
The link is not working - Rahat Zaman

1 Answers

2
votes

There is a difference between the zbuffer and the z value in 3d space. Imagine that you have a camera and are holding it up to your eye. The 1.0 is the camera's screen (i.e. the closest an object can get to you), and the 300.0 is the furthest the camera can see. These define the zbuffer's "range" (which sets up clipping).

Now what if you have an object behind you? Well then the z-VALUE (not z-buffer) is negative. How do you see it? Just turn around (effectively pointing the camera in a new direction. The z-buffer stays the same (i.e. objects closer than 1.0 or further than 300.0 are not visible), but the object that has the negative z-VALUE is not visible.

So with gluPerspective, you set up your perspective matrix (i.e. the camera's field ov view and range). Then to see objects behind you, you need to set up your view matrix (i.e. the camera's orientation).

Edit: So to see stuff that has a negative z-VALUE (without turning around), move your camera backwards (i.e. change your view matrix, so that it is positioned further back).