TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::AABox Class Reference

#include <AABox.h>

Public Member Functions

 AABox ()
 
 AABox (const Point3 &v)
 
 AABox (const class Any &a)
 
Any toAny () const
 
bool isEmpty () const
 
 AABox (const Point3 &low, const Point3 &high)
 
AABox operator* (float f) const
 
AABox operator/ (float f) const
 
void set (const Point3 &low, const Point3 &high)
 
void merge (const AABox &a)
 
void merge (const Point3 &a)
 
void merge (const class Box &b)
 
void serialize (class BinaryOutput &b) const
 
void deserialize (class BinaryInput &b)
 
bool isFinite () const
 
const Point3low () const
 
const Point3high () const
 
Point3 center () const
 
Point3 corner (int index) const
 
float extent (int a) const
 
Vector3 extent () const
 
void split (const Vector3::Axis &axis, float location, AABox &low, AABox &high) const
 
bool culledBy (const Array< Plane > &plane, int32 &cullingPlaneIndex, const uint32 testMask, uint32 &childMask) const
 
bool culledBy (const Array< Plane > &plane, int32 &cullingPlaneIndex=dummy, const uint32 testMask=0xFFFFFFFF) const
 
bool contains (const AABox &other) const
 
bool contains (const Point3 &point) const
 
float area () const
 
float volume () const
 
Point3 randomInteriorPoint () const
 
Point3 randomSurfacePoint () const
 
bool intersects (const AABox &other) const
 
bool intersects (const Sphere &other) const
 
AABox intersect (const AABox &other) const
 
size_t hashCode () const
 
bool operator== (const AABox &b) const
 
bool operator!= (const AABox &b) const
 
AABox operator+ (const Vector3 &v) const
 
AABox operator- (const Vector3 &v) const
 
void getBounds (AABox &out) const
 
void getBounds (Sphere &out) const
 

Static Public Member Functions

static const AABoxmaxFinite ()
 
static const AABoxlarge ()
 
static const AABoxinf ()
 
static const AABoxzero ()
 
static const AABoxempty ()
 

Private Attributes

Point3 lo
 
Point3 hi
 

Static Private Attributes

static int dummy = 0
 

Friends

class Intersect
 

Detailed Description

An axis-aligned box.

Constructor & Destructor Documentation

G3D::AABox::AABox ( )
inline

Creates the empty bounds, i.e., an empty set of points.

48 : lo(fnan(), fnan(), fnan()), hi(fnan(), fnan(), fnan()) {}
float fnan()
Definition: g3dmath.cpp:82
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

G3D::AABox::AABox ( const Point3 v)
inlineexplicit

Constructs a zero-volume AABox at v.

53  {
54  lo = hi = v;
55  }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40
G3D::AABox::AABox ( const class Any a)
explicit

Format is one of:

G3D::AABox::AABox ( const Point3 low,
const Point3 high 
)
inline

Assumes that low is less than or equal to high along each dimension. To have this automatically enforced, use AABox(low.min(high), low.max(high));

75  {
76  set(low, high);
77  }
const Point3 & low() const
Definition: AABox.h:136
void set(const Point3 &low, const Point3 &high)
Definition: AABox.h:93
const Point3 & high() const
Definition: AABox.h:141

+ Here is the call graph for this function:

Member Function Documentation

float G3D::AABox::area ( ) const
inline
258  {
259  if (isEmpty()) { return 0; }
260  Vector3 diag = hi - lo;
261  return 2.0f * (diag.x * diag.y + diag.y * diag.z + diag.x * diag.z);
262  }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

Point3 G3D::AABox::center ( ) const
inline

Returns the centroid of the box (NaN if empty)

163  {
164  return (lo + hi) * 0.5;
165  }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

bool G3D::AABox::contains ( const AABox other) const
inline

less than or equal to containment

238  {
239  return
240  (other.hi.x <= hi.x) &&
241  (other.hi.y <= hi.y) &&
242  (other.hi.z <= hi.z) &&
243  (other.lo.x >= lo.x) &&
244  (other.lo.y >= lo.y) &&
245  (other.lo.z >= lo.z);
246  }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
float y
Definition: Vector3.h:62
float z
Definition: Vector3.h:62
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

bool G3D::AABox::contains ( const Point3 point) const
inline
248  {
249  return
250  (point.x >= lo.x) &&
251  (point.y >= lo.y) &&
252  (point.z >= lo.z) &&
253  (point.x <= hi.x) &&
254  (point.y <= hi.y) &&
255  (point.z <= hi.z);
256  }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
float y
Definition: Vector3.h:62
float z
Definition: Vector3.h:62
Point3 lo
Definition: AABox.h:40
Vector3 G3D::AABox::corner ( int  index) const
361  {
362 
363  // default constructor inits all components to 0
364  Vector3 v;
365 
366  switch (index)
367  {
368  case 0:
369  v.x = lo.x;
370  v.y = lo.y;
371  v.z = hi.z;
372  break;
373 
374  case 1:
375  v.x = hi.x;
376  v.y = lo.y;
377  v.z = hi.z;
378  break;
379 
380  case 2:
381  v.x = hi.x;
382  v.y = hi.y;
383  v.z = hi.z;
384  break;
385 
386  case 3:
387  v.x = lo.x;
388  v.y = hi.y;
389  v.z = hi.z;
390  break;
391 
392  case 4:
393  v.x = lo.x;
394  v.y = lo.y;
395  v.z = lo.z;
396  break;
397 
398  case 5:
399  v.x = hi.x;
400  v.y = lo.y;
401  v.z = lo.z;
402  break;
403 
404  case 6:
405  v.x = hi.x;
406  v.y = hi.y;
407  v.z = lo.z;
408  break;
409 
410  case 7:
411  v.x = lo.x;
412  v.y = hi.y;
413  v.z = lo.z;
414  break;
415 
416  default:
417  debugAssertM(false, "Invalid corner index");
418  break;
419  }
420 
421  return v;
422 }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
float y
Definition: Vector3.h:62
float z
Definition: Vector3.h:62
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

bool G3D::AABox::culledBy ( const Array< Plane > &  plane,
int32 cullingPlaneIndex,
const uint32  testMask,
uint32 childMask 
) const

Conservative culling test for up to 32 planes. Returns true if there exists a plane[p] for which the entire object is in the negative half space (opposite the plane normal).

testMask and childMask are used for optimizing bounding volume hierarchies. The version of this method that produces childMask is slower than the version without; it should only be used for parent nodes.

Parameters
cullingPlaneIndexThe index of the first plane for which the entire object is in the negative half-space. The function exits early when one plane is found. -1 when the function returns false (i.e. when no plane culls the whole object).
testMaskIf bit p is 0, the bounding volume automatically passes the culling test for plane[p] (i.e. it is known that the volume is entirely within the positive half space). The function must return false if testMask is 0 and test all planes when testMask is -1 (0xFFFFFFFF).
childMaskTest mask for the children of this volume.

+ Here is the caller graph for this function:

bool G3D::AABox::culledBy ( const Array< Plane > &  plane,
int32 cullingPlaneIndex = dummy,
const uint32  testMask = 0xFFFFFFFF 
) const

Conservative culling test that does not produce a mask for children.

void G3D::AABox::deserialize ( class BinaryInput b)
99  {
100  lo = b.readVector3();
101  hi = b.readVector3();
102 }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const AABox & G3D::AABox::empty ( )
static
61  {
62  static const AABox b;
63  return b;
64 }
AABox()
Definition: AABox.h:48

+ Here is the caller graph for this function:

float G3D::AABox::extent ( int  a) const
inline

Distance from corner(0) to the next corner along axis a.

172  {
173  if (isEmpty()) {
174  return 0.0f;
175  }
176  debugAssert(a < 3);
177  return hi[a] - lo[a];
178  }
Point3 hi
Definition: AABox.h:43
#define debugAssert(exp)
Definition: debugAssert.h:160
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Vector3 G3D::AABox::extent ( ) const
inline
181  {
182  if (isEmpty()) {
183  return Vector3::zero();
184  }
185  return hi - lo;
186  }
Point3 hi
Definition: AABox.h:43
static const Vector3 & zero()
Definition: Vector3.cpp:119
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AABox::getBounds ( AABox out) const
inline
331  {
332  out = *this;
333  }

+ Here is the caller graph for this function:

void G3D::AABox::getBounds ( Sphere out) const
339  {
340  s.center = center();
341  s.radius = extent().length() / 2;
342 }
float length() const
Definition: Vector3.h:751
Vector3 extent() const
Definition: AABox.h:181
Point3 center() const
Definition: AABox.h:163

+ Here is the call graph for this function:

size_t G3D::AABox::hashCode ( ) const
inline
297  {
298  return lo.hashCode() + hi.hashCode();
299  }
Point3 hi
Definition: AABox.h:43
size_t hashCode() const
Definition: Vector3.cpp:155
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Point3& G3D::AABox::high ( ) const
inline

Returns not-a-number if empty

141  {
142  return hi;
143  }
Point3 hi
Definition: AABox.h:43

+ Here is the caller graph for this function:

const AABox & G3D::AABox::inf ( )
static
81  {
82  static const AABox b = AABox(-Vector3::inf(), Vector3::inf());
83  return b;
84 }
AABox()
Definition: AABox.h:48
static const Vector3 & inf()
Definition: Vector3.cpp:124

+ Here is the call graph for this function:

AABox G3D::AABox::intersect ( const AABox other) const
inline

Return the intersection of the two boxes

282  {
283  if (isEmpty() || other.isEmpty()) {
284  return empty();
285  }
286 
287  const Point3& H = hi.min(other.hi);
288  const Point3& L = lo.max(other.lo).min(H);
289 
290  if (H.x < L.x && H.y < L.y && H.z < L.z) {
291  return empty();
292  } else {
293  return AABox(L, H);
294  }
295  }
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
Point3 hi
Definition: AABox.h:43
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
#define H(x, y, z)
static const AABox & empty()
Definition: AABox.cpp:61
AABox()
Definition: AABox.h:48
Vector3 Point3
Definition: Vector3.h:820
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::AABox::intersects ( const AABox other) const

Returns true if there is any overlap

175  {
176  // Must be overlap along all three axes.
177  // Try to find a separating axis.
178 
179  for (int a = 0; a < 3; ++a) {
180 
181  // |--------|
182  // |------|
183 
184  if ((lo[a] > other.hi[a]) ||
185  (hi[a] < other.lo[a])) {
186  return false;
187  }
188  }
189 
190  return true;
191 }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

bool G3D::AABox::intersects ( const Sphere other) const

Returns true if there is any overlap. [Jim] Arvo's algorithm from Graphics Gems II

345  {
346  double d = 0;
347 
348  //find the square of the distance
349  //from the sphere to the box
350  for (int i = 0; i < 3; ++i) {
351  if (sphere.center[i] < lo[i]) {
352  d += square(sphere.center[i] - lo[i]);
353  } else if (sphere.center[i] > hi[i]) {
354  d += square(sphere.center[i] - hi[i]);
355  }
356  }
357 
358  return d <= square(sphere.radius);
359 }
Point3 hi
Definition: AABox.h:43
double square(double fValue)
Definition: g3dmath.h:698
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

bool G3D::AABox::isEmpty ( ) const
inline
67  {
68  return lo.isNaN();
69  }
bool isNaN() const
Definition: Vector3.cpp:83
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::AABox::isFinite ( ) const
inline
131  {
132  return isEmpty() || (lo.isFinite() && hi.isFinite());
133  }
Point3 hi
Definition: AABox.h:43
bool isFinite() const
Definition: Vector3.h:652
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const AABox & G3D::AABox::large ( )
static

A large finite box. This is smaller than FLT_MAX because it leaves room to add boxes together.

74  {
75  static const AABox b = AABox(Vector3::minFinite() * 0.5f,
76  Vector3::maxFinite() * 0.5f);
77  return b;
78 }
static const Vector3 & minFinite()
Definition: Vector3.cpp:126
static const Vector3 & maxFinite()
Definition: Vector3.cpp:127
AABox()
Definition: AABox.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Point3& G3D::AABox::low ( ) const
inline

Returns not-a-number if empty

136  {
137  return lo;
138  }
Point3 lo
Definition: AABox.h:40

+ Here is the caller graph for this function:

const AABox & G3D::AABox::maxFinite ( )
static

The largest possible finite box.

67  {
68  static const AABox b = AABox(Vector3::minFinite(),
70  return b;
71 }
static const Vector3 & minFinite()
Definition: Vector3.cpp:126
static const Vector3 & maxFinite()
Definition: Vector3.cpp:127
AABox()
Definition: AABox.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AABox::merge ( const AABox a)
inline

Grows to include the bounds of a

106  {
107  if (isEmpty()) {
108  lo = a.lo;
109  hi = a.hi;
110  } else if (! a.isEmpty()) {
111  lo = lo.min(a.lo);
112  hi = hi.max(a.hi);
113  }
114  }
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
Point3 hi
Definition: AABox.h:43
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AABox::merge ( const Point3 a)
inline
116  {
117  if (isEmpty()) {
118  lo = hi = a;
119  } else {
120  lo = lo.min(a);
121  hi = hi.max(a);
122  }
123  }
Vector3 __fastcall max(const Vector3 &v) const
Definition: Vector3.h:794
Point3 hi
Definition: AABox.h:43
Vector3 __fastcall min(const Vector3 &v) const
Definition: Vector3.h:789
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

void G3D::AABox::merge ( const class Box b)
bool G3D::AABox::operator!= ( const AABox b) const
inline
309  {
310  if (isEmpty()) {
311  return b.isEmpty();
312  } else {
313  return !((lo == b.lo) && (hi == b.hi));
314  }
315  }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

AABox G3D::AABox::operator* ( float  f) const
inline
79  {
80  if (f < 0) {
81  return AABox(hi * f, lo * f);
82  } else {
83  return AABox(lo * f, hi * f);
84  }
85  }
Point3 hi
Definition: AABox.h:43
AABox()
Definition: AABox.h:48
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

AABox G3D::AABox::operator+ ( const Vector3 v) const
inline
317  {
318  AABox out;
319  out.lo = lo + v;
320  out.hi = hi + v;
321  return out;
322  }
Point3 hi
Definition: AABox.h:43
AABox()
Definition: AABox.h:48
Point3 lo
Definition: AABox.h:40
AABox G3D::AABox::operator- ( const Vector3 v) const
inline
324  {
325  AABox out;
326  out.lo = lo - v;
327  out.hi = hi - v;
328  return out;
329  }
Point3 hi
Definition: AABox.h:43
AABox()
Definition: AABox.h:48
Point3 lo
Definition: AABox.h:40
AABox G3D::AABox::operator/ ( float  f) const
inline
87  {
88  return *this * (1.0f / f);
89  }
bool G3D::AABox::operator== ( const AABox b) const
inline
301  {
302  if (isEmpty() && b.isEmpty()) {
303  return true;
304  } else {
305  return (lo == b.lo) && (hi == b.hi);
306  }
307  }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

Vector3 G3D::AABox::randomInteriorPoint ( ) const
167  {
168  return Vector3(
169  (float)uniformRandom(lo.x, hi.x),
170  (float)uniformRandom(lo.y, hi.y),
171  (float)uniformRandom(lo.z, hi.z));
172 }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
float y
Definition: Vector3.h:62
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
float z
Definition: Vector3.h:62
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

Vector3 G3D::AABox::randomSurfacePoint ( ) const
129  {
130  Vector3 extent = hi - lo;
131  float aXY = extent.x * extent.y;
132  float aYZ = extent.y * extent.z;
133  float aZX = extent.z * extent.x;
134 
135  float r = (float)uniformRandom(0.0f, aXY + aYZ + aZX);
136 
137  // Choose evenly between positive and negative face planes
138  float d = ((float)uniformRandom(0, 1) < 0.5f) ? 0.0f : 1.0f;
139 
140  // The probability of choosing a given face is proportional to
141  // its area.
142  if (r < aXY) {
143  return
144  lo +
145  Vector3(
146  (float)uniformRandom(0.0f, extent.x),
147  (float)uniformRandom(0.0f, extent.y),
148  d * extent.z);
149  } else if (r < aYZ) {
150  return
151  lo +
152  Vector3(
153  d * extent.x,
154  (float)uniformRandom(0, extent.y),
155  (float)uniformRandom(0, extent.z));
156  } else {
157  return
158  lo +
159  Vector3(
160  (float)uniformRandom(0, extent.x),
161  d * extent.y,
162  (float)uniformRandom(0, extent.z));
163  }
164 }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
Vector3 extent() const
Definition: AABox.h:181
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

void G3D::AABox::serialize ( class BinaryOutput b) const
93  {
94  b.writeVector3(lo);
95  b.writeVector3(hi);
96 }
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AABox::set ( const Point3 low,
const Point3 high 
)
inline

Assumes that low is less than or equal to high along each dimension.

93  {
95  (low.x <= high.x) &&
96  (low.y <= high.y) &&
97  (low.z <= high.z));
98  debugAssert(! low.isNaN() && ! high.isNaN());
99  lo = low;
100  hi = high;
101  }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
const Point3 & low() const
Definition: AABox.h:136
float y
Definition: Vector3.h:62
#define debugAssert(exp)
Definition: debugAssert.h:160
float z
Definition: Vector3.h:62
const Point3 & high() const
Definition: AABox.h:141
bool isNaN() const
Definition: Vector3.cpp:83
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::AABox::split ( const Vector3::Axis axis,
float  location,
AABox low,
AABox high 
) const

Splits the box into two AABoxes along the specified axis. low contains the part that was closer to negative infinity along axis, high contains the other part. Either may have zero volume.

112  {
113  // Low, medium, and high along the chosen axis
114  float L = G3D::min(location, lo[axis]);
115  float M = G3D::min(G3D::max(location, lo[axis]), hi[axis]);
116  float H = G3D::max(location, hi[axis]);
117 
118  // Copy over this box.
119  high = low = *this;
120 
121  // Now move the split points along the special axis
122  low.lo[axis] = L;
123  low.hi[axis] = M;
124  high.lo[axis] = M;
125  high.hi[axis] = H;
126 }
Point3 hi
Definition: AABox.h:43
const Point3 & low() const
Definition: AABox.h:136
T max(const T &x, const T &y)
Definition: g3dmath.h:320
#define H(x, y, z)
T min(const T &x, const T &y)
Definition: g3dmath.h:305
const Point3 & high() const
Definition: AABox.h:141
Point3 lo
Definition: AABox.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Any G3D::AABox::toAny ( ) const
44  {
45  if (isEmpty()) {
46  return Any(Any::ARRAY, "AABox::empty");
47  } else if (! isFinite()) {
48  return Any(Any::ARRAY, "AABox::inf");
49  } else {
50  Any a(Any::ARRAY, "AABox");
51  if (lo == hi) {
52  a.append(lo);
53  } else {
54  a.append(lo, hi);
55  }
56  return a;
57  }
58 }
bool isFinite() const
Definition: AABox.h:131
Point3 hi
Definition: AABox.h:43
Definition: Any.h:187
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

float G3D::AABox::volume ( ) const
inline
264  {
265  if (isEmpty()) { return 0; }
266  Vector3 diag = hi - lo;
267  return diag.x * diag.y * diag.z;
268  }
float x
Definition: Vector3.h:62
Point3 hi
Definition: AABox.h:43
Point3 lo
Definition: AABox.h:40
bool isEmpty() const
Definition: AABox.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const AABox & G3D::AABox::zero ( )
static
87  {
88  static const AABox b = AABox(Vector3::zero(), Vector3::zero());
89  return b;
90 }
static const Vector3 & zero()
Definition: Vector3.cpp:119
AABox()
Definition: AABox.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class Intersect
friend

Member Data Documentation

int G3D::AABox::dummy = 0
staticprivate

Optional argument placeholder

Point3 G3D::AABox::hi
private

NaN if empty

Point3 G3D::AABox::lo
private

NaN if empty


The documentation for this class was generated from the following files: