15 #include "boundingBox.h" 16 #include "boundingSphere.h" 17 #include "boundingHexahedron.h" 18 #include "boundingLine.h" 19 #include "boundingPlane.h" 20 #include "config_mathutil.h" 26 const int BoundingBox::plane_def[6][3] = {
76 PN_stdfloat BoundingBox::
84 return (_max[0] - _min[0]) * (_max[1] - _min[1]) * (_max[2] - _min[2]);
93 get_approx_center()
const {
96 return (_min + _max) * 0.5f;
113 for (
int i = 1; i < 8; ++i) {
115 n.set(min(n[0], p[0]), min(n[1], p[1]), min(n[2], p[2]));
116 x.set(max(x[0], p[0]), max(x[1], p[1]), max(x[2], p[2]));
129 output(ostream &out)
const {
131 out <<
"bbox, empty";
133 out <<
"bbox, infinite";
135 out <<
"bbox, (" << _min <<
") to (" << _max <<
")";
158 return other->extend_by_box(
this);
170 return other->around_boxes(first, last);
180 return other->contains_box(
this);
190 extend_by_point(
const LPoint3 &point) {
191 nassertr(!point.
is_nan(),
false);
199 _min.set(min(_min[0], point[0]), min(_min[1], point[1]), min(_min[2], point[2]));
200 _max.set(max(_max[0], point[0]), max(_max[1], point[1]), max(_max[2], point[2]));
222 _min.set(min(_min[0], box->_min[0]),
223 min(_min[1], box->_min[1]),
224 min(_min[2], box->_min[2]));
225 _max.set(max(_max[0], box->_max[0]),
226 max(_max[1], box->_max[1]),
227 max(_max[2], box->_max[2]));
250 _min.set(min(_min[0], min1[0]),
251 min(_min[1], min1[1]),
252 min(_min[2], min1[2]));
253 _max.set(max(_max[0], max1[0]),
254 max(_max[1], max1[1]),
255 max(_max[2], max1[2]));
268 nassertr(first != last,
false);
276 while (p != last && (*p).
is_nan()) {
281 mathutil_cat.warning()
282 <<
"BoundingBox around NaN\n";
293 while (p != last && (*p).
is_nan()) {
307 _min.set(min(_min[0], (*p)[0]),
308 min(_min[1], (*p)[1]),
309 min(_min[2], (*p)[2]));
310 _max.set(max(_max[0], (*p)[0]),
311 max(_max[1], (*p)[1]),
312 max(_max[2], (*p)[2]));
318 if (skipped_nan != 0) {
319 mathutil_cat.warning()
320 <<
"BoundingBox ignored " << skipped_nan <<
" NaN points of " 321 << (last - first) <<
" total.\n";
338 nassertr(first != last,
false);
347 nassertr(!(*p)->is_empty() && !(*p)->is_infinite(),
false);
349 _min = vol->get_min();
350 _max = vol->get_max();
352 for (++p; p != last; ++p) {
353 nassertr(!(*p)->is_infinite(),
false);
354 if (!(*p)->is_empty()) {
358 _min.set(min(_min[0], min1[0]),
359 min(_min[1], min1[1]),
360 min(_min[2], min1[2]));
361 _max.set(max(_max[0], max1[0]),
362 max(_max[1], max1[1]),
363 max(_max[2], max1[2]));
377 contains_point(
const LPoint3 &point)
const {
378 nassertr(!point.
is_nan(), IF_no_intersection);
381 return IF_no_intersection;
384 return IF_possible | IF_some | IF_all;
387 if (point[0] >= _min[0] && point[0] <= _max[0] &&
388 point[1] >= _min[1] && point[1] <= _max[1] &&
389 point[2] >= _min[2] && point[2] <= _max[2]) {
390 return IF_possible | IF_some | IF_all;
392 return IF_no_intersection;
404 nassertr(!a.
is_nan() && !b.
is_nan(), IF_no_intersection);
407 return contains_point(a);
410 return IF_no_intersection;
413 return IF_possible | IF_some | IF_all;
417 unsigned int a_bits = 0;
419 if (a[0] < _min[0]) {
421 }
else if (a[0] > _max[0]) {
425 if (a[1] < _min[1]) {
427 }
else if (a[1] > _max[1]) {
431 if (a[2] < _min[2]) {
433 }
else if (a[2] > _max[2]) {
437 unsigned int b_bits = 0;
439 if (b[0] < _min[0]) {
441 }
else if (b[0] > _max[0]) {
445 if (b[1] < _min[1]) {
447 }
else if (b[1] > _max[1]) {
451 if (b[2] < _min[2]) {
453 }
else if (b[2] > _max[2]) {
457 if ((a_bits & b_bits) != 0) {
461 return IF_no_intersection;
463 }
else if ((a_bits | b_bits) == 0) {
466 return IF_possible | IF_some | IF_all;
468 }
else if (a_bits == 0 || b_bits == 0) {
471 return IF_possible | IF_some;
474 unsigned int differ = (a_bits ^ b_bits);
475 if (differ == 0x03 || differ == 0x0c || differ == 0x30) {
478 return IF_possible | IF_some;
503 if (min1[0] >= _min[0] && max1[0] <= _max[0] &&
504 min1[1] >= _min[1] && max1[1] <= _max[1] &&
505 min1[2] >= _min[2] && max1[2] <= _max[2]) {
507 return IF_possible | IF_some | IF_all;
509 }
else if (max1[0] >= _min[0] && min1[0] <= _max[0] &&
510 max1[1] >= _min[1] && min1[1] <= _max[1] &&
511 max1[2] >= _min[2] && min1[2] <= _max[2]) {
517 return IF_no_intersection;
532 int result = contains_finite(hexahedron);
533 if (result == IF_no_intersection || ((result & IF_all) != 0)) {
539 return hexahedron->contains_box(
this) & ~IF_all;
551 return line->contains_box(
this) & ~IF_all;
563 return plane->contains_box(
this) & ~IF_all;
576 LPoint3 min1 = volume->get_min();
577 LPoint3 max1 = volume->get_max();
579 if (min1[0] >= _min[0] && max1[0] <= _max[0] &&
580 min1[1] >= _min[1] && max1[1] <= _max[1] &&
581 min1[2] >= _min[2] && max1[2] <= _max[2]) {
583 return IF_possible | IF_some | IF_all;
585 }
else if (max1[0] >= _min[0] && min1[0] <= _max[0] &&
586 max1[1] >= _min[1] && min1[1] <= _max[1] &&
587 max1[2] >= _min[2] && min1[2] <= _max[2]) {
593 return IF_no_intersection;
An axis-aligned bounding box; that is, a minimum and maximum coordinate triple.
bool is_empty() const
Any kind of volume might be empty.
virtual const BoundingBox * as_bounding_box() const
Virtual downcast method.
bool is_infinite() const
The other side of the empty coin is an infinite volume.
static const LPoint3f & zero()
Returns a zero-length point.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
bool is_nan() const
Returns true if any component of the matrix is not-a-number, false otherwise.
This funny bounding volume is an infinite plane that divides space into two regions: the part behind ...
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
This is a 4-by-4 transform matrix.
const LPoint3 & get_maxq() const
An inline accessor for the maximum value.
LPoint3 get_point(int n) const
Returns the nth vertex of the rectangular solid.
A special kind of GeometricBoundingVolume that is known to be finite.
BoundingBox()
Constructs an empty box object.
TypeHandle is the identifier used to differentiate C++ class types.
This defines a bounding convex hexahedron.
This funny bounding volume is an infinite line with no thickness and extending to infinity in both di...
const LPoint3 & get_minq() const
An inline accessor for the minimum value.