소스 검색

move frustum planes calculus to Plane

ncannasse 11 년 전
부모
커밋
32420cd7aa
3개의 변경된 파일36개의 추가작업 그리고 37개의 파일을 삭제
  1. 6 19
      h3d/col/Bounds.hx
  2. 24 0
      h3d/col/Plane.hx
  3. 6 18
      h3d/col/Point.hx

+ 6 - 19
h3d/col/Bounds.hx

@@ -15,31 +15,18 @@ class Bounds {
 	}
 	
 	public function inFrustum( mvp : Matrix ) {
-
-		// left
-		if( testPlane(new Plane(mvp._14 + mvp._11, mvp._24 + mvp._21 , mvp._34 + mvp._31, -(mvp._44 + mvp._41))) < 0 )
+		if( testPlane(Plane.frustumLeft(mvp)) < 0 )
 			return false;
-		
-		// right
-		if( testPlane(new Plane(mvp._14 - mvp._11, mvp._24 - mvp._21 , mvp._34 - mvp._31, mvp._41 - mvp._44)) < 0 )
+		if( testPlane(Plane.frustumRight(mvp)) < 0 )
 			return false;
-
-		// bottom
-		if( testPlane(new Plane(mvp._14 + mvp._12, mvp._24 + mvp._22 , mvp._34 + mvp._32, -(mvp._44 + mvp._42))) < 0 )
+		if( testPlane(Plane.frustumBottom(mvp)) < 0 )
 			return false;
-
-		// top
-		if( testPlane(new Plane(mvp._14 - mvp._12, mvp._24 - mvp._22 , mvp._34 - mvp._32, mvp._42 - mvp._44)) < 0 )
+		if( testPlane(Plane.frustumTop(mvp)) < 0 )
 			return false;
-
-		// near
-		if( testPlane(new Plane(mvp._13, mvp._23, mvp._33, -mvp._43)) < 0 )
+		if( testPlane(Plane.frustumNear(mvp)) < 0 )
 			return false;
-
-		// far
-		if( testPlane(new Plane(mvp._14 - mvp._13, mvp._24 - mvp._23, mvp._34 - mvp._33, mvp._43 - mvp._44)) < 0 )
+		if( testPlane(Plane.frustumFar(mvp)) < 0 )
 			return false;
-			
 		return true;
 	}
 	

+ 24 - 0
h3d/col/Plane.hx

@@ -89,4 +89,28 @@ class Plane {
 		return new Plane( 0, 0, 1, v );
 	}
 	
+	public static inline function frustumLeft( mvp : Matrix ) {
+		return new Plane(mvp._14 + mvp._11, mvp._24 + mvp._21 , mvp._34 + mvp._31, -(mvp._44 + mvp._41));
+	}
+
+	public static inline function frustumRight( mvp : Matrix ) {
+		return new Plane(mvp._14 - mvp._11, mvp._24 - mvp._21 , mvp._34 - mvp._31, mvp._41 - mvp._44);
+	}
+	
+	public static inline function frustumBottom( mvp : Matrix ) {
+		return new Plane(mvp._14 + mvp._12, mvp._24 + mvp._22 , mvp._34 + mvp._32, -(mvp._44 + mvp._42));
+	}
+
+	public static inline function frustumTop( mvp : Matrix ) {
+		return new Plane(mvp._14 - mvp._12, mvp._24 - mvp._22 , mvp._34 - mvp._32, mvp._42 - mvp._44);
+	}
+	
+	public static inline function frustumNear( mvp : Matrix ) {
+		return new Plane(mvp._13, mvp._23, mvp._33, -mvp._43);
+	}
+
+	public static inline function frustumFar( mvp : Matrix ) {
+		return new Plane(mvp._14 - mvp._13, mvp._24 - mvp._23, mvp._34 - mvp._33, mvp._43 - mvp._44);
+	}
+	
 }

+ 6 - 18
h3d/col/Point.hx

@@ -14,30 +14,18 @@ class Point {
 	}
 	
 	public function inFrustum( mvp : Matrix ) {
-		// left
-		if( !new Plane(mvp._14 + mvp._11, mvp._24 + mvp._21 , mvp._34 + mvp._31, -(mvp._44 + mvp._41)).side(this))
+		if( !Plane.frustumLeft(mvp).side(this) )
 			return false;
-		
-		// right
-		if( !new Plane(mvp._14 - mvp._11, mvp._24 - mvp._21 , mvp._34 - mvp._31, mvp._41 - mvp._44).side(this) )
+		if( !Plane.frustumRight(mvp).side(this) )
 			return false;
-
-		// bottom
-		if( !new Plane(mvp._14 + mvp._12, mvp._24 + mvp._22 , mvp._34 + mvp._32, -(mvp._44 + mvp._42)).side(this) )
+		if( !Plane.frustumBottom(mvp).side(this) )
 			return false;
-
-		// top
-		if( !new Plane(mvp._14 - mvp._12, mvp._24 - mvp._22 , mvp._34 - mvp._32, mvp._42 - mvp._44).side(this) )
+		if( !Plane.frustumTop(mvp).side(this) )
 			return false;
-
-		// near
-		if( !new Plane(mvp._13, mvp._23, mvp._33, -mvp._43).side(this) )
+		if( !Plane.frustumNear(mvp).side(this) )
 			return false;
-
-		// far
-		if( !new Plane(mvp._14 - mvp._13, mvp._24 - mvp._23, mvp._34 - mvp._33, mvp._43 - mvp._44).side(this) )
+		if( !Plane.frustumFar(mvp).side(this) )
 			return false;
-			
 		return true;
 	}