소스 검색

proper bounds

Zachary Pavlov 18 년 전
부모
커밋
2c0ceb6731
1개의 변경된 파일23개의 추가작업 그리고 1개의 파일을 삭제
  1. 23 1
      panda/src/collide/collisionFloorMesh.cxx

+ 23 - 1
panda/src/collide/collisionFloorMesh.cxx

@@ -102,7 +102,29 @@ output(ostream &out) const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PT(BoundingVolume) CollisionFloorMesh::
 PT(BoundingVolume) CollisionFloorMesh::
 compute_internal_bounds() const {
 compute_internal_bounds() const {
-  return new BoundingBox(LPoint3f(0,0,0), LPoint3f(1,1,1));
+  if (_vertices.empty()) {
+    return new BoundingBox;
+  }
+
+
+  pvector<LPoint3f>::const_iterator pi = _vertices.begin();
+  LPoint3f p = (*pi);
+
+  LPoint3f x = p;
+  LPoint3f n = p;
+
+  for (++pi; pi != _vertices.end(); ++pi) {
+    p = *pi;
+
+    n.set(min(n[0], p[0]),
+          min(n[1], p[1]),
+          min(n[2], p[2]));
+    x.set(max(x[0], p[0]),
+          max(x[1], p[1]),
+          max(x[2], p[2]));
+  }
+
+  return new BoundingBox(n, x);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////