瀏覽代碼

add h3d.col.Polygon.getBounds()

trethaller 6 年之前
父節點
當前提交
008d620eb7
共有 1 個文件被更改,包括 14 次插入0 次删除
  1. 14 0
      h3d/col/Polygon.hx

+ 14 - 0
h3d/col/Polygon.hx

@@ -1,5 +1,6 @@
 package h3d.col;
 
+@:allow(h3d.col.Polygon)
 class TriPlane implements Collider {
 
 	public var next : TriPlane = null;
@@ -212,6 +213,19 @@ class Polygon implements Collider {
 		return ret;
 	}
 
+	public function getBounds(?bnds: h3d.col.Bounds) : h3d.col.Bounds {
+		if(bnds == null) bnds = new h3d.col.Bounds();
+		bnds.empty();
+		var t = triPlanes;
+		while( t != null ) {
+			bnds.addPos(t.p0x, t.p0y, t.p0z);
+			bnds.addPos(t.d1x + t.p0x, t.d1y + t.p0y, t.d1z + t.p0z);
+			bnds.addPos(t.d2x + t.p0x, t.d2y + t.p0y, t.d2z + t.p0z);
+			t = t.next;
+		}
+		return bnds;
+	}
+
 	public function contains( p : Point ) {
 		if( !isConvex() )
 			throw "Not implemented for concave polygon";