Wednesday, February 20, 2013

How to Derive the Near and Far Clip Plane Distances From the Projection Matrix

Here is a method to derive the near and far clip plane distances from the projection matrix. Assuming the the projection matrix is created with two entries that are calculated as:

// n = near clip plane distance
// f  = far clip plane distance

C = matrix[2][2] = (-f - n) / ( f - n);
for a column major matrix
D = matrix[2][3] = (-2 f n ) / ( f - n)

The near and far clip planes are calculated:

float n = D / (C - 1.0);
float f = D / (C + 1.0);