Browse Source

collision segment that does not extend to an infinite bounding volume

Zachary Pavlov 15 years ago
parent
commit
4930c9a6f2
1 changed files with 11 additions and 11 deletions
  1. 11 11
      panda/src/collide/collisionSegment.cxx

+ 11 - 11
panda/src/collide/collisionSegment.cxx

@@ -125,20 +125,20 @@ set_from_lens(LensNode *camera, const LPoint2f &point) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 PT(BoundingVolume) CollisionSegment::
 PT(BoundingVolume) CollisionSegment::
 compute_internal_bounds() const {
 compute_internal_bounds() const {
-  PT(BoundingVolume) bound = CollisionSolid::compute_internal_bounds();
 
 
-  if (bound->is_of_type(GeometricBoundingVolume::get_class_type())) {
-    GeometricBoundingVolume *gbound;
-    DCAST_INTO_R(gbound, bound, bound);
+  LVector3f pdelta = _b - _a;
 
 
-    // This makes the assumption that _a and _b are laid out
-    // sequentially in memory.  It works because that's they way
-    // they're defined in the class.
-    nassertr(&_a + 1 == &_b, bound);
-    gbound->around(&_a, &_b + 1);
+  // If p1 and p2 are sufficiently close, just put a sphere around
+  // them.
+  float d2 = pdelta.length_squared();
+  if (d2 < collision_parabola_bounds_threshold * collision_parabola_bounds_threshold) {
+    LPoint3f pmid = (_a + _b) * 0.5f;
+    return new BoundingSphere(pmid, csqrt(d2) * 0.5f);
   }
   }
-
-  return bound;
+  LPoint3f min_p(min(_a[0], _b[0]) - .01, min(_a[1], _b[1]) - .01, min(_a[2],_b[2]) - .01);
+  LPoint3f max_p(max(_a[0], _b[0]) + .01, max(_a[1], _b[1]) + .01, max(_a[2],_b[2]) + .01);
+  
+  return new BoundingBox(min_p, max_p);  
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////