Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 26 Jul 2006
Offline Last Active Apr 03 2013 03:03 PM

Posts I've Made

In Topic: Projection matrix from 6 arbitrary frustum planes?

04 November 2008 - 04:17 PM

Eric Lengyel's article might be helpful:


Also see his powerpoint on "projection matrix tricks:"


In Topic: Projection matrix from 6 arbitrary frustum planes?

25 October 2008 - 06:41 AM

Even if you have skew, shear, off center, whatever you want to call it, it turns out to be pretty easy.

What you want is to get the left, right, top, bottom, near, and far values (let's call them l, r, t, b, zn, zf) to pass into something like glFrustum or D3DXMatrixPerspectiveOffCenterLH or the like - see the documentation for either of those functions to see how to derive the actual projection matrix from those values if you need it.

l, r, t, and b represent the extents of the rectangle formed by the intersection of the near clipping plane on the view frustum.

The equation for each of your frustum planes are:

Ax + By + Cz + D = 0

Where (A,B,C) is your plane's normal, and D is the distance.

When computing l and r, you know that z is the near clip plane's distance, and y can be set to zero. For top and bottom, z is still the near clip plane's distance, and x can be set to zero. Conveniently, D is zero for the left, right, top, and bottom planes of the projection, and zn and zf are simply the distances for the near and far clip planes (take care with the signs, the far clip plane's distance is negative since the plane points inward, so you'll need to negate it to get zf.)

The resulting algebra is trivial, but the bottom line is this:

To compute l and r, use x = (C * zn) / A (where A and C are from the plane equations for the left and right clipping planes respectively)

To compute t and b, use y = (C * zn) / B

If you're in a left handed coordinate system, negate all of these results.

Pass them into glFrustum or its equivalent, and you're done.