Panda3D
 All Classes Functions Variables Enumerations
boundingBox.I
1 // Filename: boundingBox.I
2 // Created by: drose (31May07)
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 ////////////////////////////////////////////////////////////////////
17 // Function: BoundingBox::Constructor
18 // Access: Published
19 // Description: Constructs an empty box object.
20 ////////////////////////////////////////////////////////////////////
21 INLINE_MATHUTIL BoundingBox::
23 }
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: BoundingBox::Constructor
27 // Access: Published
28 // Description: Constructs a specific box object.
29 ////////////////////////////////////////////////////////////////////
30 INLINE_MATHUTIL BoundingBox::
31 BoundingBox(const LPoint3 &min, const LPoint3 &max) :
32  _min(min), _max(max)
33 {
34 #ifdef NDEBUG
35  _flags = F_empty;
36  nassertv(!_min.is_nan() && !_max.is_nan());
37  nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
38 #endif // NDEBUG
39  _flags = 0;
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: BoundingBox::get_minq
44 // Access: Public
45 // Description: An inline accessor for the minimum value. get_min()
46 // would also work, but it is a virtual non-inline
47 // method.
48 ////////////////////////////////////////////////////////////////////
49 INLINE_MATHUTIL const LPoint3 &BoundingBox::
50 get_minq() const {
51  nassertr(!is_empty(), _min);
52  nassertr(!is_infinite(), _min);
53  return _min;
54 }
55 
56 ////////////////////////////////////////////////////////////////////
57 // Function: BoundingBox::get_maxq
58 // Access: Public
59 // Description: An inline accessor for the maximum value. get_max()
60 // would also work, but it is a virtual non-inline
61 // method.
62 ////////////////////////////////////////////////////////////////////
63 INLINE_MATHUTIL const LPoint3 &BoundingBox::
64 get_maxq() const {
65  nassertr(!is_empty(), _max);
66  nassertr(!is_infinite(), _max);
67  return _max;
68 }
69 
70 ////////////////////////////////////////////////////////////////////
71 // Function: BoundingBox::get_num_points
72 // Access: Published
73 // Description: Returns 8: the number of vertices of a rectangular solid.
74 ////////////////////////////////////////////////////////////////////
75 INLINE_MATHUTIL int BoundingBox::
76 get_num_points() const {
77  return 8;
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: BoundingBox::get_point
82 // Access: Published
83 // Description: Returns the nth vertex of the rectangular solid.
84 ////////////////////////////////////////////////////////////////////
85 INLINE_MATHUTIL LPoint3 BoundingBox::
86 get_point(int n) const {
87  nassertr(n >= 0 && n < 8, LPoint3::zero());
88 
89  // We do some trickery assuming that _min and _max are consecutive
90  // in memory.
91  const LPoint3 *a = &_min;
92  return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: BoundingBox::get_num_planes
97 // Access: Published
98 // Description: Returns 6: the number of faces of a rectangular solid.
99 ////////////////////////////////////////////////////////////////////
100 INLINE_MATHUTIL int BoundingBox::
101 get_num_planes() const {
102  return 6;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: BoundingBox::get_plane
107 // Access: Published
108 // Description: Returns the nth face of the rectangular solid.
109 ////////////////////////////////////////////////////////////////////
110 INLINE_MATHUTIL LPlane BoundingBox::
111 get_plane(int n) const {
112  nassertr(n >= 0 && n < 6, LPlane());
113  return LPlane(get_point(plane_def[n][0]),
114  get_point(plane_def[n][1]),
115  get_point(plane_def[n][2]));
116 }
int get_num_points() const
Returns 8: the number of vertices of a rectangular solid.
Definition: boundingBox.I:76
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:258
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:463
const LPoint3 & get_maxq() const
An inline accessor for the maximum value.
Definition: boundingBox.I:64
bool is_infinite() const
The other side of the empty coin is an infinite volume.
LPoint3 get_point(int n) const
Returns the nth vertex of the rectangular solid.
Definition: boundingBox.I:86
BoundingBox()
Constructs an empty box object.
Definition: boundingBox.I:22
bool is_empty() const
Any kind of volume might be empty.
LPlane get_plane(int n) const
Returns the nth face of the rectangular solid.
Definition: boundingBox.I:111
const LPoint3 & get_minq() const
An inline accessor for the minimum value.
Definition: boundingBox.I:50
int get_num_planes() const
Returns 6: the number of faces of a rectangular solid.
Definition: boundingBox.I:101