PDA

View Full Version : depth problem caused by changing gluperspective



brennt
08-22-2009, 01:59 PM
in some project we tried to do something like this:




glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.33, 1.0, 120000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(500, 200+playerTeam->teamAvatar->pos.y*0.1, 500, 0, 0+playerTeam->teamAvatar->pos.y*0.1, 0, 1.0, 1.0, 1.0);
glRotatef(this->angle, 0.0f, 1.0f, 0.0f);
glTranslatef(-pos2[0],-pos2[1],-pos2[2]);

// Draw some objects

glEnable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.33, 500.0, 120000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(500, 200+playerTeam->teamAvatar->pos.y*0.1, 500, 0, 0+playerTeam->teamAvatar->pos.y*0.1, 0, 1.0, 1.0, 1.0);
glRotatef(this->angle, 0.0f, 1.0f, 0.0f);
glTranslatef(-pos2[0],-pos2[1],-pos2[2]);



// draw some other objects

glDisable(GL_LIGHTING);

to get the effect of trimming objects between viewer and main character (its a third-person-view game). Of course it works fine, until we realise that there are problems with z-buffer testing (caused by changing zNear value) sothat trees on other side of hill are visible instead of the hill itself.

Is there a possibility to block affecting z-buffer values while re-setting gluPerspective's zNear value?

earthquad
08-23-2009, 07:08 AM
not sure but i think the preferred way to do this in a game is to trace a ray from the player to the desired camera location, say within a bounding sphere radius of intersection with the world. then you're home free, without any modification to any matrices.

depth range hacks can be used to prevent first person weapons etc. from disappearing into walls, but that doesn't sound like what you are going for.

ZbuffeR
08-23-2009, 11:21 AM
Either follow earthquad advice, or to stay within image-space algorithm you may want to try something even simpler like

draw 1.0-120000.0 range without player
clear zbuffer (and not color)
draw player