Open GL _ z Value

Hi Everybody !

I’m quite new to c++ and OF.

I have a doubt about the z value in OpenGL.

When I’m translating an element like :

  
  
z -= 1;  
glTranslate(0,0,z);  
glutSolidCube(10);  
  

The cube is disapearing when the z value is going too far…

I’m looking forward to catch or configure this value to replace the cube back when It’s invisible.

like

  
if ( z < value ) {  
  
z = 500;  
  
}  

Anyone knows if there is a way to fix that ?

It would be so nice

Thanks !

Hey -

What you are seeing is the effect of the openGL clip planes.

You can make them closer or further by changing this code in ofGraphics.cpp:

  
//----------------------------------------------------------  
void ofSetupScreen(){  
  
	int w, h;  
  
	w = glutGet(GLUT_WINDOW_WIDTH);  
	h = glutGet(GLUT_WINDOW_HEIGHT);  
  
	float halfFov, theTan, screenFov, aspect;  
	screenFov 		= 60.0f;  
  
	float eyeX 		= (float)w / 2.0;  
	float eyeY 		= (float)h / 2.0;  
	halfFov 		= PI * screenFov / 360.0;  
	theTan 			= tanf(halfFov);  
	float dist 		= eyeY / theTan;  
  
  

change clip plane distance here:
to make the distance further do something like: dist * 1000.0;

  
  
  
        float nearDist 	= dist / 10.0;	// near / far clip plane  
        float farDist 	= dist * 10.0;  
  
  

  
  
  
  
	aspect 		= (float)w/(float)h;  
  
	glMatrixMode(GL_PROJECTION);  
	glLoadIdentity();  
	gluPerspective(screenFov, aspect, nearDist, farDist);  
	gluLookAt(eyeX, eyeY, dist,  
	eyeX, eyeY, 0.0, 0.0, 1.0, 0.0);  
	glMatrixMode(GL_MODELVIEW);  
	glLoadIdentity();  
  
  
	glScalef(1, -1, 1);           // invert Y axis so increasing Y goes down.  
  	glTranslatef(0, -h, 0);       // shift origin up to upper-left corner.  
}  

It works perfectly :wink:

Thanks a lot !

Greetings from barcelona