Perspective Projection Far Plane Not Clipping?

I've just discovered that far away objects in my world don't seem to clip like they should with a perspective projection matrix.

When I fly far away from my main landscape, so that I am much more than 10 units (if not hundreds) away, it won't disappear. This is weird, because I thought objects should clip/disappear once they hit the far plane.

Here's a photo that demonstrates the issue:

I have defined the projection with my own custom function. The field of view is 60 degrees and the aspect ratio is 1.3333 (although those shouldn't matter), the near plane is 0.1 and the far plane is 10. I have experimented with adjusting the far plane and even when it is 0.2 nothing is ever clipped. When it is 0.1 or below I get a blank screen. (which makes sense)

The matrix is calculated like so:

    projectionMatrix.setIdentity();

float yScale = MathHelper.coTangent((float) Math.toRadians(fieldOfView / 2f));
float xScale = yScale / aspectRatio;
float frustumLength = farPlane - nearPlane;

projectionMatrix.m00 = xScale;
projectionMatrix.m11 = yScale;
projectionMatrix.m22 = -((farPlane - nearPlane) / frustumLength);
projectionMatrix.m23 = -1;
projectionMatrix.m32 = -((2 * nearPlane * farPlane) / frustumLength);
projectionMatrix.m33 = 0;


This produces a perspective projection like so:

    1.299038 0.0       0.0    0.0
0.0      1.7320508 0.0    0.0
0.0      0.0       -1.0   -0.20202021
0.0      0.0       -1.0   0.0


Thanks very much if you could help with this annoying issue/benefit.

• Is your matrix column or row major ? – concept3d Jan 28 '15 at 9:45
• That's a good question I don't really know :). All I can say is I'm using LWJGL, and when I set uniforms the transpose argument is set to false, so I suppose whatever OpenGL uses? (you can see my strong point is not maths). Edit: I think column major – neon64 Jan 28 '15 at 9:57
• I don't know about OpenGL, but in DirectX, you have to set clipping to enabled in the rasterizer state, maybe something similar is required here, too. – János Turánszki Jan 28 '15 at 10:54
• OpenGL is column major by default, just like your matrix impl., but this didn't seem to be the problem anyway, otherwise you probably would not be seeing much. I think it must have something to do with the way you're computing your perspective projection matrix. I'll check that later (at cellphone now). Atm you could try verifying correctness yourself here: songho.ca/opengl/gl_projectionmatrix.html – Pedro Boechat Jan 28 '15 at 14:12