Daniele Bartolini 9 年之前
父節點
當前提交
37b05829b2
共有 1 個文件被更改,包括 43 次插入75 次删除
  1. 43 75
      src/core/math/frustum.h

+ 43 - 75
src/core/math/frustum.h

@@ -8,7 +8,7 @@
 #include "aabb.h"
 #include "intersection.h"
 #include "math_types.h"
-#include "plane.h"
+#include "plane3.h"
 
 namespace crown
 {
@@ -44,87 +44,55 @@ namespace frustum
 {
 	inline void from_matrix(Frustum& f, const Matrix4x4& m)
 	{
-		f.left.n.x   = m.x.w + m.x.x;
-		f.left.n.y   = m.y.w + m.y.x;
-		f.left.n.z   = m.z.w + m.z.x;
-		f.left.d     = m.t.w + m.t.x;
-
-		f.right.n.x  = m.x.w - m.x.x;
-		f.right.n.y  = m.y.w - m.y.x;
-		f.right.n.z  = m.z.w - m.z.x;
-		f.right.d    = m.t.w - m.t.x;
-
-		f.bottom.n.x = m.x.w + m.x.y;
-		f.bottom.n.y = m.y.w + m.y.y;
-		f.bottom.n.z = m.z.w + m.z.y;
-		f.bottom.d   = m.t.w + m.t.y;
-
-		f.top.n.x    = m.x.w - m.x.y;
-		f.top.n.y    = m.y.w - m.y.y;
-		f.top.n.z    = m.z.w - m.z.y;
-		f.top.d      = m.t.w - m.t.y;
-
-		f.near.n.x   = m.x.w + m.x.z;
-		f.near.n.y   = m.y.w + m.y.z;
-		f.near.n.z   = m.z.w + m.z.z;
-		f.near.d     = m.t.w + m.t.z;
-
-		f.far.n.x    = m.x.w - m.x.z;
-		f.far.n.y    = m.y.w - m.y.z;
-		f.far.n.z    = m.z.w - m.z.z;
-		f.far.d      = m.t.w - m.t.z;
-
-		plane::normalize(f.left);
-		plane::normalize(f.right);
-		plane::normalize(f.bottom);
-		plane::normalize(f.top);
-		plane::normalize(f.near);
-		plane::normalize(f.far);
+		f.plane_left.n.x   = m.x.w + m.x.x;
+		f.plane_left.n.y   = m.y.w + m.y.x;
+		f.plane_left.n.z   = m.z.w + m.z.x;
+		f.plane_left.d     = m.t.w + m.t.x;
+
+		f.plane_right.n.x  = m.x.w - m.x.x;
+		f.plane_right.n.y  = m.y.w - m.y.x;
+		f.plane_right.n.z  = m.z.w - m.z.x;
+		f.plane_right.d    = m.t.w - m.t.x;
+
+		f.plane_bottom.n.x = m.x.w + m.x.y;
+		f.plane_bottom.n.y = m.y.w + m.y.y;
+		f.plane_bottom.n.z = m.z.w + m.z.y;
+		f.plane_bottom.d   = m.t.w + m.t.y;
+
+		f.plane_top.n.x    = m.x.w - m.x.y;
+		f.plane_top.n.y    = m.y.w - m.y.y;
+		f.plane_top.n.z    = m.z.w - m.z.y;
+		f.plane_top.d      = m.t.w - m.t.y;
+
+		f.plane_near.n.x   = m.x.w + m.x.z;
+		f.plane_near.n.y   = m.y.w + m.y.z;
+		f.plane_near.n.z   = m.z.w + m.z.z;
+		f.plane_near.d     = m.t.w + m.t.z;
+
+		f.plane_far.n.x    = m.x.w - m.x.z;
+		f.plane_far.n.y    = m.y.w - m.y.z;
+		f.plane_far.n.z    = m.z.w - m.z.z;
+		f.plane_far.d      = m.t.w - m.t.z;
+
+		plane3::normalize(f.plane_left);
+		plane3::normalize(f.plane_right);
+		plane3::normalize(f.plane_bottom);
+		plane3::normalize(f.plane_top);
+		plane3::normalize(f.plane_near);
+		plane3::normalize(f.plane_far);
 	}
 
 	inline bool contains_point(const Frustum& f, const Vector3& p)
 	{
-		return !(plane::distance_to_point(f.left, p) < 0.0f
-			|| plane::distance_to_point(f.right, p) < 0.0f
-			|| plane::distance_to_point(f.bottom, p) < 0.0f
-			|| plane::distance_to_point(f.top, p) < 0.0f
-			|| plane::distance_to_point(f.near, p) < 0.0f
-			|| plane::distance_to_point(f.far, p) < 0.0f
+		return !(plane3::distance_to_point(f.plane_left, p) < 0.0f
+			|| plane3::distance_to_point(f.plane_right, p) < 0.0f
+			|| plane3::distance_to_point(f.plane_bottom, p) < 0.0f
+			|| plane3::distance_to_point(f.plane_top, p) < 0.0f
+			|| plane3::distance_to_point(f.plane_near, p) < 0.0f
+			|| plane3::distance_to_point(f.plane_far, p) < 0.0f
 			);
 	}
 
-	inline Vector3 vertex(const Frustum& f, u32 index)
-	{
-		CE_ASSERT(index < 8, "Index out of bounds");
-
-		// 0 = Near bottom left
-		// 1 = Near bottom right
-		// 2 = Near top right
-		// 3 = Near top left
-		// 4 = Far bottom left
-		// 5 = Far bottom right
-		// 6 = Far top right
-		// 7 = Far top left
-
-		const Plane* side = &f.left;
-		Vector3 ip;
-
-		switch (index)
-		{
-		case 0: plane_3_intersection(side[4], side[0], side[2], ip); break;
-		case 1: plane_3_intersection(side[4], side[1], side[2], ip); break;
-		case 2: plane_3_intersection(side[4], side[1], side[3], ip); break;
-		case 3: plane_3_intersection(side[4], side[0], side[3], ip); break;
-		case 4: plane_3_intersection(side[5], side[0], side[2], ip); break;
-		case 5: plane_3_intersection(side[5], side[1], side[2], ip); break;
-		case 6: plane_3_intersection(side[5], side[1], side[3], ip); break;
-		case 7: plane_3_intersection(side[5], side[0], side[3], ip); break;
-		default: break;
-		}
-
-		return ip;
-	}
-
 	inline AABB to_aabb(const Frustum& f)
 	{
 		Vector3 vertices[8];