6 @maintainer Morgan McGuire, matrix@graphics3d.com
8 @cite Portions based on Dave Eberly's Magic Software Library at <A HREF="http://www.magic-software.com">http://www.magic-software.com</A>
12 Copyright 2000-2006, Morgan McGuire.
19 #include "G3D/platform.h"
20 #include "G3D/Vector3.h"
21 #include "G3D/Array.h"
22 #include "G3D/Plane.h"
26 class CoordinateFrame
;
29 An arbitrary 3D box, useful as a bounding box.
32 To construct a box from a coordinate frame, center and extent, use the idiom:
34 <CODE>Box box = cframe.toObjectSpace(Box(center - extent/2, center + extent/2));</CODE>
41 friend class CoordinateFrame
;
49 front back (seen through front)
62 Extent along each axis.
76 Does not initialize the fields.
81 Constructs a box from two opposite corners.
87 Box(const class AABox
& b
);
91 Returns the object to world transformation for
92 this box. localFrame().worldToObject(...) takes
93 objects into the space where the box axes are
94 (1,0,0), (0,1,0), (0,0,1). Note that there
95 is no scaling in this transformation.
97 CoordinateFrame
localFrame() const;
99 void getLocalFrame(CoordinateFrame
& frame
) const;
102 Returns the centroid of the box.
104 inline Vector3
center() const {
108 inline Vector3
getCenter() const {
113 Returns a corner (0 <= i < 8)
116 inline Vector3
getCorner(int i
) const {
121 inline Vector3
corner(int i
) const {
129 inline Vector3
axis(int a
) const {
135 Distance from corner(0) to the next corner
136 along the box's local axis a.
138 inline float extent(int a
) const {
140 return (float)_extent
[a
];
143 inline Vector3
extent() const {
148 Returns the four corners of a face (0 <= f < 6).
149 The corners are returned to form a counter clockwise quad facing outwards.
159 @deprecated Use culledBy(Array<Plane>&)
162 const class Plane
* plane
,
164 int32
& cullingPlaneIndex
,
165 const uint32 testMask
,
166 uint32
& childMask
) const;
169 @deprecated Use culledBy(Array<Plane>&)
172 const class Plane
* plane
,
174 int32
& cullingPlaneIndex
= dummy
,
175 const uint32 testMask
= -1) const;
181 const Array
<Plane
>& plane
,
182 int32
& cullingPlaneIndex
,
183 const uint32 testMask
,
184 uint32
& childMask
) const;
187 Conservative culling test that does not produce a mask for children.
190 const Array
<Plane
>& plane
,
191 int32
& cullingPlaneIndex
= dummy
,
192 const uint32 testMask
= -1) const;
195 const Vector3
& point
) const;
198 float surfaceArea() const;
200 inline float area() const {
201 return surfaceArea();
204 float volume() const;
206 void getRandomSurfacePoint(Vector3
& P
, Vector3
& N
= Vector3::dummy
) const;
210 Uniformly distributed on the surface.
212 inline Vector3
randomSurfacePoint() const {
214 getRandomSurfacePoint(V
);
219 Uniformly distributed on the interior (includes surface)
221 Vector3
randomInteriorPoint() const;
223 void getBounds(class AABox
&) const;