collision segment that does not extend to an infinite bounding volume

This commit is contained in:
Zachary Pavlov 2010-04-27 22:16:41 +00:00
parent c3eace229e
commit 4930c9a6f2

View File

@ -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())) { LVector3f pdelta = _b - _a;
GeometricBoundingVolume *gbound;
DCAST_INTO_R(gbound, bound, bound);
// This makes the assumption that _a and _b are laid out // If p1 and p2 are sufficiently close, just put a sphere around
// sequentially in memory. It works because that's they way // them.
// they're defined in the class. float d2 = pdelta.length_squared();
nassertr(&_a + 1 == &_b, bound); if (d2 < collision_parabola_bounds_threshold * collision_parabola_bounds_threshold) {
gbound->around(&_a, &_b + 1); LPoint3f pmid = (_a + _b) * 0.5f;
return new BoundingSphere(pmid, csqrt(d2) * 0.5f);
} }
LPoint3f min_p(min(_a[0], _b[0]) - .01, min(_a[1], _b[1]) - .01, min(_a[2],_b[2]) - .01);
return bound; 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);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////