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::
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);
}
////////////////////////////////////////////////////////////////////