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