X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2Fcml%2Fmathlib%2Ffrustum.h;h=43eb41f8aea876df7fb31a8cc52412b73e834d3a;hp=6a707afb78dc2019ba8fa44b7bccb02c226841b7;hb=50c1239917f5e443b8ec91773c85ceb3db7da67b;hpb=c2321281bf12a7efaedde930422c7ddbc92080d4 diff --git a/src/Moof/cml/mathlib/frustum.h b/src/Moof/cml/mathlib/frustum.h index 6a707af..43eb41f 100644 --- a/src/Moof/cml/mathlib/frustum.h +++ b/src/Moof/cml/mathlib/frustum.h @@ -108,18 +108,7 @@ extract_frustum_planes( planes[5][3] = m.basis_element(3,3) - m.basis_element(3,2); /* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */ - - if (z_clip == z_clip_neg_one) { - planes[4][0] = m.basis_element(0,3) + m.basis_element(0,2); - planes[4][1] = m.basis_element(1,3) + m.basis_element(1,2); - planes[4][2] = m.basis_element(2,3) + m.basis_element(2,2); - planes[4][3] = m.basis_element(3,3) + m.basis_element(3,2); - } else { // z_clip == z_clip_zero - planes[4][0] = m.basis_element(0,2); - planes[4][1] = m.basis_element(1,2); - planes[4][2] = m.basis_element(2,2); - planes[4][3] = m.basis_element(3,2); - } + extract_near_frustum_plane(m, planes[4], z_clip); /* @todo: This will be handled by the plane class */ if (normalize) { @@ -136,6 +125,36 @@ extract_frustum_planes( } } +/** Extract the near plane of a frustum given a concatenated modelview and + * projection matrix with the given near z-clipping range. The plane is + * not normalized. + * + * @note The plane is in ax+by+cz+d = 0 form. + * + * @warning The matrix is assumed to be a homogeneous transformation + * matrix. + */ +template < class MatT, class PlaneT > void +extract_near_frustum_plane( + const MatT& m, + PlaneT& plane, + ZClip z_clip + ) +{ + /* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */ + if (z_clip == z_clip_neg_one) { + plane[0] = m.basis_element(0,3) + m.basis_element(0,2); + plane[1] = m.basis_element(1,3) + m.basis_element(1,2); + plane[2] = m.basis_element(2,3) + m.basis_element(2,2); + plane[3] = m.basis_element(3,3) + m.basis_element(3,2); + } else { // z_clip == z_clip_zero + plane[0] = m.basis_element(0,2); + plane[1] = m.basis_element(1,2); + plane[2] = m.basis_element(2,2); + plane[3] = m.basis_element(3,2); + } +} + namespace detail { /* This is currently only in support of finding the corners of a frustum.