Panda3D
boundingVolume.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file boundingVolume.I
10  * @author drose
11  * @date 1999-10-01
12  */
13 
14 /**
15  *
16  */
17 INLINE_MATHUTIL BoundingVolume::
18 BoundingVolume() {
19  _flags = F_empty;
20 }
21 
22 /**
23  * Any kind of volume might be empty. This is a degenerate volume that
24  * contains no points; it's not the same as, for instance, a sphere with
25  * radius zero, since that contains one point (the center). It intersects
26  * with no other volumes.
27  */
28 INLINE_MATHUTIL bool BoundingVolume::
29 is_empty() const {
30  return (_flags & F_empty) != 0;
31 }
32 
33 /**
34  * The other side of the empty coin is an infinite volume. This is a
35  * degenerate state of a normally finite volume that contains all points.
36  * (Note that some kinds of infinite bounding volumes, like binary separating
37  * planes, do not contain all points and thus correctly return is_infinite()
38  * == false, even though they are technically infinite. This is a special
39  * case of the word 'infinite' meaning the volume covers all points in space.)
40  *
41  * It completely intersects with all other volumes except empty volumes.
42  */
43 INLINE_MATHUTIL bool BoundingVolume::
44 is_infinite() const {
45  return (_flags & F_infinite) != 0;
46 }
47 
48 /**
49  * Marks the volume as infinite, even if it is normally finite. You can think
50  * of this as an infinite extend_by() operation.
51  */
52 INLINE_MATHUTIL void BoundingVolume::
54  _flags = F_infinite;
55 }
56 
57 /**
58  * Increases the size of the volume to include the given volume.
59  */
60 INLINE_MATHUTIL bool BoundingVolume::
62  if (vol->is_infinite()) {
63  set_infinite();
64 
65  } else if (!vol->is_empty()) {
66  // This is a double-dispatch. We call this virtual function on the volume
67  // we were given, which will in turn call the appropriate virtual function
68  // in our own class to perform the operation.
69  return vol->extend_other(this);
70  }
71  return true;
72 }
73 
74 
75 /**
76  * Returns the appropriate set of IntersectionFlags to indicate the amount of
77  * intersection with the indicated volume.
78  */
79 INLINE_MATHUTIL int BoundingVolume::
80 contains(const BoundingVolume *vol) const {
81  if (is_empty() || vol->is_empty()) {
82  return IF_no_intersection;
83 
84  } else if (is_infinite()) {
85  return IF_possible | IF_some | IF_all;
86 
87  } else if (vol->is_infinite()) {
88  return IF_possible | IF_some;
89  }
90 
91  // This is a double-dispatch. We call this virtual function on the volume
92  // we were given, which will in turn call the appropriate virtual function
93  // in our own class to perform the operation.
94  return vol->contains_other(this);
95 }
96 
97 INLINE_MATHUTIL std::ostream &operator << (std::ostream &out, const BoundingVolume &bound) {
98  bound.output(out);
99  return out;
100 }
int contains(const BoundingVolume *vol) const
Returns the appropriate set of IntersectionFlags to indicate the amount of intersection with the indi...
bool is_empty() const
Any kind of volume might be empty.
bool is_infinite() const
The other side of the empty coin is an infinite volume.
This is an abstract class for any volume in any sense which can be said to define the locality of ref...
void set_infinite()
Marks the volume as infinite, even if it is normally finite.
bool extend_by(const BoundingVolume *vol)
Increases the size of the volume to include the given volume.