[4054] added: Line of sight (vmaps) [part 1]
[mangos-git.git] / dep / include / g3dlite / G3D / Box.h
blobf097c10e18ef768dba65f50d077c008b8ba55739
1 /**
2 @file Box.h
4 Box class
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>
9 @created 2001-06-02
10 @edited 2006-01-05
12 Copyright 2000-2006, Morgan McGuire.
13 All rights reserved.
16 #ifndef G3D_BOX_H
17 #define G3D_BOX_H
19 #include "G3D/platform.h"
20 #include "G3D/Vector3.h"
21 #include "G3D/Array.h"
22 #include "G3D/Plane.h"
24 namespace G3D {
26 class CoordinateFrame;
28 /**
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>
36 class Box {
37 private:
39 static int32 dummy;
41 friend class CoordinateFrame;
43 /**
44 <PRE>
45 3 2 7 6
47 0 1 4 5
49 front back (seen through front)
50 </PRE>
52 Vector3 _corner[8];
54 /**
55 Unit axes.
57 Vector3 _axis[3];
59 Vector3 _center;
61 /**
62 Extent along each axis.
64 Vector3 _extent;
66 float _area;
67 float _volume;
69 void init(
70 const Vector3& min,
71 const Vector3& max);
73 public:
75 /**
76 Does not initialize the fields.
78 Box();
80 /**
81 Constructs a box from two opposite corners.
83 Box(
84 const Vector3& min,
85 const Vector3& max);
87 Box(const class AABox& b);
90 /**
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 {
105 return _center;
108 inline Vector3 getCenter() const {
109 return center();
113 Returns a corner (0 <= i < 8)
114 @deprecated
116 inline Vector3 getCorner(int i) const {
117 debugAssert(i < 8);
118 return _corner[i];
121 inline Vector3 corner(int i) const {
122 debugAssert(i < 8);
123 return _corner[i];
127 Unit length.
129 inline Vector3 axis(int a) const {
130 debugAssert(a < 3);
131 return _axis[a];
135 Distance from corner(0) to the next corner
136 along the box's local axis a.
138 inline float extent(int a) const {
139 debugAssert(a < 3);
140 return (float)_extent[a];
143 inline Vector3 extent() const {
144 return _extent;
148 Returns the four corners of a face (0 <= f < 6).
149 The corners are returned to form a counter clockwise quad facing outwards.
151 void getFaceCorners(
152 int f,
153 Vector3& v0,
154 Vector3& v1,
155 Vector3& v2,
156 Vector3& v3) const;
159 @deprecated Use culledBy(Array<Plane>&)
161 bool culledBy(
162 const class Plane* plane,
163 int numPlanes,
164 int32& cullingPlaneIndex,
165 const uint32 testMask,
166 uint32& childMask) const;
169 @deprecated Use culledBy(Array<Plane>&)
171 bool culledBy(
172 const class Plane* plane,
173 int numPlanes,
174 int32& cullingPlaneIndex = dummy,
175 const uint32 testMask = -1) const;
178 See AABox::culledBy
180 bool culledBy(
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.
189 bool culledBy(
190 const Array<Plane>& plane,
191 int32& cullingPlaneIndex = dummy,
192 const uint32 testMask = -1) const;
194 bool contains(
195 const Vector3& point) const;
197 /** @deprecated */
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;
209 @deprecated
210 Uniformly distributed on the surface.
212 inline Vector3 randomSurfacePoint() const {
213 Vector3 V;
214 getRandomSurfacePoint(V);
215 return V;
219 Uniformly distributed on the interior (includes surface)
221 Vector3 randomInteriorPoint() const;
223 void getBounds(class AABox&) const;
228 #endif