Take the 2-minute tour ×

I'm currently facing some perspective issues when trying to render the axes of a coordinate system into my scene. For these axes I draw three orthogonal lines that go through the center of my 3D cube. It's pretty tough to explain what the problem is, so I guess the most demonstrative way of presenting it is to post some pictures.

1) view on the whole scene: click here

2) zoomed in view on the origin of the coordinate system: click here

3) When I zoom in a tiny little bit further, two of the axes disappear and the other one seems to be displaced for some reason: click here

Why does this happen and how can I prevent it?

My modelview and projection matrices look the following:

 // Set ProjectionMatrix
projectionMatrix = glm::perspective(90.0f, (GLfloat)width / (GLfloat) height, 0.0001f, 1000.f);
glBindBuffer(GL_UNIFORM_BUFFER, globalMatricesUBO);
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(projectionMatrix));
glBindBuffer(GL_UNIFORM_BUFFER, 0);

// Set ModelViewMatrix
glm::mat4 identity        = glm::mat4(1.0); // Start with the identity as the transformation matrix
glm::mat4 pointTranslateZ = glm::translate(identity, glm::vec3(0.0f, 0.0f, -translate_z)); // Zoom in or out by translating in z-direction based on user input 
glm::mat4 viewRotateX     = glm::rotate(pointTranslateZ, rotate_x, glm::vec3(1.0f, 0.0f, 0.0f)); // Rotate the whole szene in x-direction based on user input
glm::mat4 viewRotateY     = glm::rotate(viewRotateX,  rotate_y, glm::vec3(0.0f, 1.0f, 0.0f)); // Rotate the whole szene in y-direction based on user input
glm::mat4 pointRotateX    = glm::rotate(viewRotateY, -90.0f, glm::vec3(1.0f, 0.0f, 0.0f)); // Rotate the camera by 90 degrees in negative x-direction to get a frontal look on the szene
glm::mat4 viewTranslate   = glm::translate(pointRotateX, glm::vec3(-dimensionX/2.0f, -dimensionY/2.0f, -dimensionZ/2.0f)); // Translate the origin to be the center of the cube
share|improve this question
Frustrum culling? –  Alexander Jan 24 '13 at 18:20
That would explain why the 2 axes disappear, right? But why is the other one in the third image displaced completely when I zoom in just a little bit further? –  Schnigges Jan 24 '13 at 18:23
Maybe a part of it is getting rendered and you see the movement as unnatural due to the closeness. –  Alexander Jan 24 '13 at 18:25

1 Answer 1

up vote 2 down vote accepted

That's called "clipping". The axis is hitting the near-clip plane and thus is being clipped. The third axis is not "displaced"; it is simply partially clipped. Take your second image and cover up most of it, so that you only see part of the diagonal axis; that's what you're getting.

There are a few general solutions to this. First, you could just not allow the user to zoom in that far. Or you could adjust the near clip plane inward as the camera is moved closer to the target object. This will also cause precision problems for far away objects, so you'll probably want to adjust your far clip plane inward too.

Alternatively, you can just turn on depth clamping (assuming you have GL 3.x+, or access to ARB_depth_clamp or NV_depth_clamp). This isn't a perfect solution, as things will still be clipped when they get behind the camera. And things that intersect the near clip plane will no longer have proper depth buffering if two such objects overlap. But it's generally good enough.

share|improve this answer

Your Answer


