6 @maintainer Morgan McGuire, matrix@graphics3d.com
11 Copyright 2000-2006, Morgan McGuire.
18 #include "G3D/platform.h"
19 #include "G3D/Vector3.h"
20 #include "G3D/debug.h"
21 #include "G3D/Array.h"
31 /** Optional argument placeholder */
39 /** Does not initialize the fields */
43 Constructs a zero-area AABox at v.
45 inline AABox(const Vector3
& v
) {
49 /** Assumes that low is less than or equal to high along each dimension.
50 To have this automatically enforced, use
51 <code>AABox(low.min(high), low.max(high));</code>
53 inline AABox(const Vector3
& low
, const Vector3
& high
) {
57 /** Assumes that low is less than or equal to high along each dimension.
59 inline void set(const Vector3
& low
, const Vector3
& high
) {
69 inline const Vector3
& low() const {
73 inline const Vector3
& high() const {
78 The largest possible finite box.
80 static inline const AABox
& maxFinite() {
81 static const AABox b
= AABox(Vector3::minFinite(), Vector3::maxFinite());
85 static inline const AABox
& inf() {
86 static const AABox b
= AABox(-Vector3::inf(), Vector3::inf());
90 static inline const AABox
& zero() {
91 static const AABox b
= AABox(Vector3::zero(), Vector3::zero());
96 Returns the centroid of the box.
98 inline Vector3
center() const {
99 return (lo
+ hi
) * 0.5;
103 Distance from corner(0) to the next corner along axis a.
105 inline double extent(int a
) const {
107 return hi
[a
] - lo
[a
];
110 inline Vector3
extent() const {
115 @deprecated Use culledBy(Array<Plane>&)
118 const class Plane
* plane
,
120 int32
& cullingPlaneIndex
,
121 const uint32 testMask
,
122 uint32
& childMask
) const;
125 @deprecated Use culledBy(Array<Plane>&)
128 const class Plane
* plane
,
130 int32
& cullingPlaneIndex
= dummy
,
131 const uint32 testMask
= 0xFFFFFF) const;
134 Splits the box into two AABoxes along the specified axis. low contains
135 the part that was closer to negative infinity along axis, high contains
136 the other part. Either may have zero volume.
138 void split(const Vector3::Axis
& axis
, float location
, AABox
& low
, AABox
& high
) const;
141 Conservative culling test for up to 32 planes.
142 Returns true if there exists a <CODE>plane[p]</CODE> for
143 which the entire object is in the negative half space
144 (opposite the plane normal).
146 <CODE>testMask</CODE> and <CODE>childMask</CODE>
147 are used for optimizing bounding volume hierarchies.
148 The version of this method that produces childMask
149 is slower than the version without; it should only
150 be used for parent nodes.
152 @param cullingPlaneIndex The index of the first plane for which
153 the entire object is in the negative half-space. The function
154 exits early when one plane is found. -1 when the function
155 returns false (i.e. when no plane culls the whole object).
157 @param testMask If bit <I>p</I> is 0, the
158 bounding volume automatically passes the culling test for
159 <CODE>plane[p]</CODE> (i.e. it is known that the volume
160 is entirely within the positive half space). The function
161 must return false if testMask is 0 and test all planes
162 when testMask is -1 (0xFFFFFFFF).
164 @param childMask Test mask for the children of this volume.
168 const Array
<Plane
>& plane
,
169 int32
& cullingPlaneIndex
,
170 const uint32 testMask
,
171 uint32
& childMask
) const;
174 Conservative culling test that does not produce a mask for children.
177 const Array
<Plane
>& plane
,
178 int32
& cullingPlaneIndex
= dummy
,
179 const uint32 testMask
= -1) const;
181 inline bool contains(
182 const Vector3
& point
) const {
193 inline float surfaceArea() const {
194 Vector3 diag
= hi
- lo
;
195 return 2.0f
* (diag
.x
* diag
.y
+ diag
.y
* diag
.z
+ diag
.x
* diag
.z
);
198 inline float area() const {
199 return surfaceArea();
202 inline float volume() const {
203 Vector3 diag
= hi
- lo
;
204 return diag
.x
* diag
.y
* diag
.z
;
207 Vector3
randomInteriorPoint() const;
209 Vector3
randomSurfacePoint() const;
211 /** @deprecated use Box constructor */
212 class Box
toBox() const;
214 /** Returns true if there is any overlap */
215 bool intersects(const AABox
& other
) const;
217 /** Returns true if there is any overlap.
218 @cite Jim Arvo's algorithm from Graphics Gems II*/
219 bool intersects(const class Sphere
& other
) const;
221 /** Return the intersection of the two boxes */
222 AABox
intersect(const AABox
& other
) const {
223 Vector3 H
= hi
.min(other
.hi
);
224 Vector3 L
= lo
.max(other
.lo
).min(H
);
228 inline unsigned int hashCode() const {
229 return lo
.hashCode() + hi
.hashCode();
232 inline bool operator==(const AABox
& b
) const {
233 return (lo
== b
.lo
) && (hi
== b
.hi
);
236 inline bool operator!=(const AABox
& b
) const {
237 return !((lo
== b
.lo
) && (hi
== b
.hi
));
240 void getBounds(AABox
& out
) const {
248 Hashing function for use with Table.
250 inline unsigned int hashCode(const G3D::AABox
& b
) {