Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AABB Class Reference

#include <IceAABB.h>

Public Member Functions

inline_ AABB ()
 Constructor. More...
 
inline_ ~AABB ()
 Destructor. More...
 
void SetMinMax (const Point &min, const Point &max)
 
void SetCenterExtents (const Point &c, const Point &e)
 
void SetEmpty ()
 
void SetPoint (const Point &pt)
 
float GetSize () const
 
void Extend (const Point &p)
 
inline_ void GetMin (Point &min) const
 Get min point of the box. More...
 
inline_ void GetMax (Point &max) const
 Get max point of the box. More...
 
inline_ float GetMin (udword axis) const
 Get component of the box's min point along a given axis. More...
 
inline_ float GetMax (udword axis) const
 Get component of the box's max point along a given axis. More...
 
inline_ void GetCenter (Point &center) const
 Get box center. More...
 
inline_ void GetExtents (Point &extents) const
 Get box extents. More...
 
inline_ float GetCenter (udword axis) const
 Get component of the box's center along a given axis. More...
 
inline_ float GetExtents (udword axis) const
 Get component of the box's extents along a given axis. More...
 
inline_ void GetDiagonal (Point &diagonal) const
 Get box diagonal. More...
 
inline_ float GetWidth () const
 
inline_ float GetHeight () const
 
inline_ float GetDepth () const
 
inline_ float GetVolume () const
 Volume. More...
 
inline_ BOOL Intersect (const AABB &a) const
 
inline_ bool GomezIntersect (const AABB &a)
 
inline_ BOOL Intersect (const AABB &a, udword axis) const
 
inline_ void Rotate (const Matrix4x4 &mtx, AABB &aabb) const
 
inline_ BOOL IsValid () const
 
inline_ AABBoperator*= (float s)
 Operator for AABB *= float. Scales the extents, keeps same center. More...
 
inline_ AABBoperator/= (float s)
 Operator for AABB /= float. Scales the extents, keeps same center. More...
 
inline_ AABBoperator+= (const Point &trans)
 Operator for AABB += Point. Translates the box. More...
 

Public Attributes

 AABB_COMMON_METHODS
 Type-independent methods. More...
 

Detailed Description

AABB class.

Author
Pierre Terdiman
Version
1.0

Definition at line 267 of file IceAABB.h.

Constructor & Destructor Documentation

inline_ AABB::AABB ( )
inline

Constructor.

Definition at line 271 of file IceAABB.h.

271 {}
inline_ AABB::~AABB ( )
inline

Destructor.

Definition at line 273 of file IceAABB.h.

273 {}

Member Function Documentation

void AABB::Extend ( const Point p)
inline

Extends the AABB.

Parameters
p[in] the next point

Definition at line 324 of file IceAABB.h.

325  {
326  Point Max = mCenter + mExtents;
327  Point Min = mCenter - mExtents;
328 
329  if(p.x > Max.x) Max.x = p.x;
330  if(p.x < Min.x) Min.x = p.x;
331 
332  if(p.y > Max.y) Max.y = p.y;
333  if(p.y < Min.y) Min.y = p.y;
334 
335  if(p.z > Max.z) Max.z = p.z;
336  if(p.z < Min.z) Min.z = p.z;
337 
338  SetMinMax(Min, Max);
339  }
inline_ void AABB::GetCenter ( Point center) const
inline

Get box center.

Definition at line 353 of file IceAABB.h.

Referenced by CollisionAABB::CollisionAABB().

353 { center = mCenter; }
inline_ float AABB::GetCenter ( udword  axis) const
inline

Get component of the box's center along a given axis.

Definition at line 358 of file IceAABB.h.

358 { return mCenter[axis]; }
inline_ float AABB::GetDepth ( ) const
inline

Definition at line 366 of file IceAABB.h.

366 { return mExtents.z * 2.0f; }
inline_ void AABB::GetDiagonal ( Point diagonal) const
inline

Get box diagonal.

Definition at line 363 of file IceAABB.h.

363 { diagonal = mExtents * 2.0f; }
inline_ void AABB::GetExtents ( Point extents) const
inline

Get box extents.

Definition at line 355 of file IceAABB.h.

Referenced by CollisionAABB::CollisionAABB().

355 { extents = mExtents; }
inline_ float AABB::GetExtents ( udword  axis) const
inline

Get component of the box's extents along a given axis.

Definition at line 360 of file IceAABB.h.

360 { return mExtents[axis]; }
inline_ float AABB::GetHeight ( ) const
inline

Definition at line 365 of file IceAABB.h.

365 { return mExtents.y * 2.0f; }
inline_ void AABB::GetMax ( Point max) const
inline

Get max point of the box.

Definition at line 345 of file IceAABB.h.

345 { max = mCenter + mExtents; }
inline_ float AABB::GetMax ( udword  axis) const
inline

Get component of the box's max point along a given axis.

Definition at line 350 of file IceAABB.h.

350 { return mCenter[axis] + mExtents[axis]; }
inline_ void AABB::GetMin ( Point min) const
inline

Get min point of the box.

Definition at line 343 of file IceAABB.h.

343 { min = mCenter - mExtents; }
inline_ float AABB::GetMin ( udword  axis) const
inline

Get component of the box's min point along a given axis.

Definition at line 348 of file IceAABB.h.

348 { return mCenter[axis] - mExtents[axis]; }
float AABB::GetSize ( ) const
inline

Gets the size of the AABB. The size is defined as the longest extent.

Returns
the size of the AABB

Definition at line 316 of file IceAABB.h.

316 { return mExtents.Max(); }
inline_ float AABB::GetVolume ( ) const
inline

Volume.

Definition at line 369 of file IceAABB.h.

369 { return mExtents.x * mExtents.y * mExtents.z * 8.0f; }
inline_ float AABB::GetWidth ( ) const
inline

Definition at line 364 of file IceAABB.h.

364 { return mExtents.x * 2.0f; }
inline_ bool AABB::GomezIntersect ( const AABB a)
inline

The standard intersection method from Gamasutra. Just here to check its speed against the one above.

Parameters
a[in] the other AABB
Returns
true on intersection

Definition at line 393 of file IceAABB.h.

394  {
395  Point T = mCenter - a.mCenter; // Vector from A to B
396  return ((fabsf(T.x) <= (a.mExtents.x + mExtents.x))
397  && (fabsf(T.y) <= (a.mExtents.y + mExtents.y))
398  && (fabsf(T.z) <= (a.mExtents.z + mExtents.z)));
399  }
inline_ BOOL AABB::Intersect ( const AABB a) const
inline

Computes the intersection between two AABBs.

Parameters
a[in] the other AABB
Returns
true on intersection

Definition at line 378 of file IceAABB.h.

379  {
380  float tx = mCenter.x - a.mCenter.x; float ex = a.mExtents.x + mExtents.x; if(AIR(tx) > IR(ex)) return FALSE;
381  float ty = mCenter.y - a.mCenter.y; float ey = a.mExtents.y + mExtents.y; if(AIR(ty) > IR(ey)) return FALSE;
382  float tz = mCenter.z - a.mCenter.z; float ez = a.mExtents.z + mExtents.z; if(AIR(tz) > IR(ez)) return FALSE;
383  return TRUE;
384  }
inline_ BOOL AABB::Intersect ( const AABB a,
udword  axis 
) const
inline

Computes the 1D-intersection between two AABBs, on a given axis.

Parameters
a[in] the other AABB
axis[in] the axis (0, 1, 2)
Returns
true on intersection

Definition at line 409 of file IceAABB.h.

410  {
411  float t = mCenter[axis] - a.mCenter[axis];
412  float e = a.mExtents[axis] + mExtents[axis];
413  if(AIR(t) > IR(e)) return FALSE;
414  return TRUE;
415  }
inline_ BOOL AABB::IsValid ( ) const
inline

Checks the AABB is valid.

Returns
true if the box is valid

Definition at line 450 of file IceAABB.h.

451  {
452  // Consistency condition for (Center, Extents) boxes: Extents >= 0
453  if(mExtents.x < 0.0f) return FALSE;
454  if(mExtents.y < 0.0f) return FALSE;
455  if(mExtents.z < 0.0f) return FALSE;
456  return TRUE;
457  }
inline_ AABB& AABB::operator*= ( float  s)
inline

Operator for AABB *= float. Scales the extents, keeps same center.

Definition at line 460 of file IceAABB.h.

460 { mExtents*=s; return *this; }
inline_ AABB& AABB::operator+= ( const Point trans)
inline

Operator for AABB += Point. Translates the box.

Definition at line 466 of file IceAABB.h.

467  {
468  mCenter+=trans;
469  return *this;
470  }
inline_ AABB& AABB::operator/= ( float  s)
inline

Operator for AABB /= float. Scales the extents, keeps same center.

Definition at line 463 of file IceAABB.h.

463 { mExtents/=s; return *this; }
inline_ void AABB::Rotate ( const Matrix4x4 mtx,
AABB aabb 
) const
inline

Recomputes the AABB after an arbitrary transform by a 4x4 matrix.

Parameters
mtx[in] the transform matrix
aabb[out] the transformed AABB [can be *this]

Definition at line 424 of file IceAABB.h.

425  {
426  // Compute new center
427  aabb.mCenter = mCenter * mtx;
428 
429  // Compute new extents. FPU code & CPU code have been interleaved for improved performance.
430  Point Ex(mtx.m[0][0] * mExtents.x, mtx.m[0][1] * mExtents.x, mtx.m[0][2] * mExtents.x);
431  IR(Ex.x)&=0x7fffffff; IR(Ex.y)&=0x7fffffff; IR(Ex.z)&=0x7fffffff;
432 
433  Point Ey(mtx.m[1][0] * mExtents.y, mtx.m[1][1] * mExtents.y, mtx.m[1][2] * mExtents.y);
434  IR(Ey.x)&=0x7fffffff; IR(Ey.y)&=0x7fffffff; IR(Ey.z)&=0x7fffffff;
435 
436  Point Ez(mtx.m[2][0] * mExtents.z, mtx.m[2][1] * mExtents.z, mtx.m[2][2] * mExtents.z);
437  IR(Ez.x)&=0x7fffffff; IR(Ez.y)&=0x7fffffff; IR(Ez.z)&=0x7fffffff;
438 
439  aabb.mExtents.x = Ex.x + Ey.x + Ez.x;
440  aabb.mExtents.y = Ex.y + Ey.y + Ez.y;
441  aabb.mExtents.z = Ex.z + Ey.z + Ez.z;
442  }
void AABB::SetCenterExtents ( const Point c,
const Point e 
)
inline

Setups an AABB from center & extents vectors.

Parameters
c[in] the center point
e[in] the extents vector

Definition at line 294 of file IceAABB.h.

294 { mCenter = c; mExtents = e; }
void AABB::SetEmpty ( )
inline

Setups an empty AABB.

Definition at line 301 of file IceAABB.h.

301 { mCenter.Zero(); mExtents.Set(MIN_FLOAT, MIN_FLOAT, MIN_FLOAT);}
void AABB::SetMinMax ( const Point min,
const Point max 
)
inline

Setups an AABB from min & max vectors.

Parameters
min[in] the min point
max[in] the max point

Definition at line 285 of file IceAABB.h.

Referenced by ComputeAABB().

285 { mCenter = (max + min)*0.5f; mExtents = (max - min)*0.5f; }
void AABB::SetPoint ( const Point pt)
inline

Setups a point AABB.

Definition at line 308 of file IceAABB.h.

308 { mCenter = pt; mExtents.Zero(); }

Member Data Documentation

AABB::AABB_COMMON_METHODS

Type-independent methods.

Definition at line 276 of file IceAABB.h.


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