]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/cml/mathlib/frustum.h
cml version bump to 1.0.1
[chaz/yoink] / src / Moof / cml / mathlib / frustum.h
index 6a707afb78dc2019ba8fa44b7bccb02c226841b7..43eb41f8aea876df7fb31a8cc52412b73e834d3a 100644 (file)
@@ -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.
This page took 0.021646 seconds and 4 git commands to generate.