Panda3D
boundingBox.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 boundingBox.I
10  * @author drose
11  * @date 2007-05-31
12  */
13 
14 /**
15  * Constructs an empty box object.
16  */
17 INLINE_MATHUTIL BoundingBox::
19 }
20 
21 /**
22  * Constructs a specific box object.
23  */
24 INLINE_MATHUTIL BoundingBox::
25 BoundingBox(const LPoint3 &min, const LPoint3 &max) :
26  _min(min), _max(max)
27 {
28 #ifdef NDEBUG
29  _flags = F_empty;
30  nassertv(!_min.is_nan() && !_max.is_nan());
31  nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
32 #endif // NDEBUG
33  _flags = 0;
34 }
35 
36 /**
37  * An inline accessor for the minimum value. get_min() would also work, but
38  * it is a virtual non-inline method.
39  */
40 INLINE_MATHUTIL const LPoint3 &BoundingBox::
41 get_minq() const {
42  nassertr(!is_empty(), _min);
43  nassertr(!is_infinite(), _min);
44  return _min;
45 }
46 
47 /**
48  * An inline accessor for the maximum value. get_max() would also work, but
49  * it is a virtual non-inline method.
50  */
51 INLINE_MATHUTIL const LPoint3 &BoundingBox::
52 get_maxq() const {
53  nassertr(!is_empty(), _max);
54  nassertr(!is_infinite(), _max);
55  return _max;
56 }
57 
58 /**
59  * Returns 8: the number of vertices of a rectangular solid.
60  */
61 INLINE_MATHUTIL int BoundingBox::
62 get_num_points() const {
63  return 8;
64 }
65 
66 /**
67  * Returns the nth vertex of the rectangular solid.
68  */
69 INLINE_MATHUTIL LPoint3 BoundingBox::
70 get_point(int n) const {
71  nassertr(n >= 0 && n < 8, LPoint3::zero());
72 
73  // We do some trickery assuming that _min and _max are consecutive in
74  // memory.
75  const LPoint3 *a = &_min;
76  return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
77 }
78 
79 /**
80  * Returns 6: the number of faces of a rectangular solid.
81  */
82 INLINE_MATHUTIL int BoundingBox::
83 get_num_planes() const {
84  return 6;
85 }
86 
87 /**
88  * Returns the nth face of the rectangular solid.
89  */
90 INLINE_MATHUTIL LPlane BoundingBox::
91 get_plane(int n) const {
92  nassertr(n >= 0 && n < 6, LPlane());
93  return LPlane(get_point(plane_def[n][0]),
94  get_point(plane_def[n][1]),
95  get_point(plane_def[n][2]));
96 }
97 
98 /**
99  * Sets the min and max point of the rectangular solid.
100  */
101 INLINE_MATHUTIL void BoundingBox::
102 set_min_max(const LPoint3 &min, const LPoint3 &max) {
103  nassertv(!min.is_nan() && !max.is_nan());
104  nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
105  _min = min;
106  _max = max;
107  _flags = 0;
108 }
get_point
Returns the nth vertex of the rectangular solid.
Definition: boundingBox.h:51
bool is_empty() const
Any kind of volume might be empty.
void set_min_max(const LPoint3 &min, const LPoint3 &max)
Sets the min and max point of the rectangular solid.
Definition: boundingBox.I:102
bool is_infinite() const
The other side of the empty coin is an infinite volume.
const LPoint3 & get_maxq() const
An inline accessor for the maximum value.
Definition: boundingBox.I:52
get_plane
Returns the nth face of the rectangular solid.
Definition: boundingBox.h:54
BoundingBox()
Constructs an empty box object.
Definition: boundingBox.I:18
const LPoint3 & get_minq() const
An inline accessor for the minimum value.
Definition: boundingBox.I:41