forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboundingBox.I
More file actions
108 lines (98 loc) · 2.51 KB
/
boundingBox.I
File metadata and controls
108 lines (98 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file boundingBox.I
* @author drose
* @date 2007-05-31
*/
/**
* Constructs an empty box object.
*/
INLINE_MATHUTIL BoundingBox::
BoundingBox() {
}
/**
* Constructs a specific box object.
*/
INLINE_MATHUTIL BoundingBox::
BoundingBox(const LPoint3 &min, const LPoint3 &max) :
_min(min), _max(max)
{
#ifdef NDEBUG
_flags = F_empty;
nassertv(!_min.is_nan() && !_max.is_nan());
nassertv(_min[0] <= _max[0] && _min[1] <= _max[1] && _min[2] <= _max[2]);
#endif // NDEBUG
_flags = 0;
}
/**
* An inline accessor for the minimum value. get_min() would also work, but
* it is a virtual non-inline method.
*/
INLINE_MATHUTIL const LPoint3 &BoundingBox::
get_minq() const {
nassertr(!is_empty(), _min);
nassertr(!is_infinite(), _min);
return _min;
}
/**
* An inline accessor for the maximum value. get_max() would also work, but
* it is a virtual non-inline method.
*/
INLINE_MATHUTIL const LPoint3 &BoundingBox::
get_maxq() const {
nassertr(!is_empty(), _max);
nassertr(!is_infinite(), _max);
return _max;
}
/**
* Returns 8: the number of vertices of a rectangular solid.
*/
INLINE_MATHUTIL int BoundingBox::
get_num_points() const {
return 8;
}
/**
* Returns the nth vertex of the rectangular solid.
*/
INLINE_MATHUTIL LPoint3 BoundingBox::
get_point(int n) const {
nassertr(n >= 0 && n < 8, LPoint3::zero());
// We do some trickery assuming that _min and _max are consecutive in
// memory.
const LPoint3 *a = &_min;
return LPoint3(a[(n>>2)&1][0], a[(n>>1)&1][1], a[(n)&1][2]);
}
/**
* Returns 6: the number of faces of a rectangular solid.
*/
INLINE_MATHUTIL int BoundingBox::
get_num_planes() const {
return 6;
}
/**
* Returns the nth face of the rectangular solid.
*/
INLINE_MATHUTIL LPlane BoundingBox::
get_plane(int n) const {
nassertr(n >= 0 && n < 6, LPlane());
return LPlane(get_point(plane_def[n][0]),
get_point(plane_def[n][1]),
get_point(plane_def[n][2]));
}
/**
* Sets the min and max point of the rectangular solid.
*/
INLINE_MATHUTIL void BoundingBox::
set_min_max(const LPoint3 &min, const LPoint3 &max) {
nassertv(!min.is_nan() && !max.is_nan());
nassertv(min[0] <= max[0] && min[1] <= max[1] && min[2] <= max[2]);
_min = min;
_max = max;
_flags = 0;
}