From 4930c9a6f21153ebd7bc1e61945f910209eba982 Mon Sep 17 00:00:00 2001 From: Zachary Pavlov Date: Tue, 27 Apr 2010 22:16:41 +0000 Subject: [PATCH] collision segment that does not extend to an infinite bounding volume --- panda/src/collide/collisionSegment.cxx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/panda/src/collide/collisionSegment.cxx b/panda/src/collide/collisionSegment.cxx index dd20a27dc9..f4e9dc517e 100644 --- a/panda/src/collide/collisionSegment.cxx +++ b/panda/src/collide/collisionSegment.cxx @@ -125,20 +125,20 @@ set_from_lens(LensNode *camera, const LPoint2f &point) { //////////////////////////////////////////////////////////////////// PT(BoundingVolume) CollisionSegment:: 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); } ////////////////////////////////////////////////////////////////////