Projection Transform

You can think of the projection transform as controlling the camera's internals. The following ProjectionMatrix sample function takes three input parameters that set the near and far clipping planes and the field of view angle. The field of view should be less than pi.

D3DMATRIX 
ProjectionMatrix(const float near_plane,     // distance to near clipping plane
                 const float far_plane,      // distance to far clipping plane
                 const float fov)            // field of view angle, in radians
{
    float    c, s, Q;
 
    c = (float)cos(fov*0.5);
    s = (float)sin(fov*0.5);
    Q = s/(1.0f - near_plane/far_plane);
 
    D3DMATRIX ret = ZeroMatrix();
    ret(0, 0) = c;
    ret(1, 1) = c;
    ret(2, 2) = Q;
    ret(3, 2) = -Q*near_plane;
    ret(2, 3) = s;
    return ret;
}   // end of ProjectionMatrix()
 

The following matrix is the projection matrix used by Direct3D. In this formula, h is the half-height of the viewing frustum, F is the position in z-coordinates of the back clipping plane, and D is the position in z-coordinates of the front clipping plane:

In Direct3D, the 3,4 element of the projection matrix (the numeral 1 here) cannot be a negative number.