• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

OOBox.h

Go to the documentation of this file.
00001 // GMTL is (C) Copyright 2001-2010 by Allen Bierbaum
00002 // Distributed under the GNU Lesser General Public License 2.1 with an
00003 // addendum covering inlined code. (See accompanying files LICENSE and
00004 // LICENSE.addendum or http://www.gnu.org/copyleft/lesser.txt)
00005 
00006 #ifndef _GMTL_OOBox_H_
00007 #define _GMTL_OOBox_H_
00008 
00009 #include <gmtl/Vec3.h>
00010 #include <gmtl/Point3.h>
00011 #include <gmtl/matVecFuncs.h>
00012 
00013 namespace gmtl
00014 {
00015 
00016 // AABox : Defines an object aligned box
00017 //
00018 // For definition of an OOB, see pg 293-294 of Real-Time Rendering
00019 class  OOBox
00020 {
00021 
00022 public:
00023    OOBox()
00024    { ident(); }
00025 
00026    OOBox(OOBox& box);
00027 
00028 public:
00029    // Accessors
00030    Point3& center();
00031    const Point3& center() const;
00032 
00033    Vec3& axis (int i);
00034    const Vec3& axis (int i) const;
00035    Vec3* axes ();
00036    const Vec3* axes () const;
00037 
00038    float& halfLen(int i);
00039    const float& halfLen(int i) const;
00040    float* halfLens();
00041    const float* halfLens() const;
00042 
00043    // Assignment
00044    OOBox& operator=(const OOBox& box);
00045 
00046    // Comparison
00047    bool operator==(const OOBox& box) const;
00048 
00049    //  return the verts that define the box
00050    // Order: XYZ: 000, 100, 110, 010,
00051    //             001, 101, 111, 011
00052    void getVerts(Point3 verts[8]) const;
00053 
00054    // Merge current box with other box to get new box covering both
00055    void mergeWith(const OOBox& box);
00056 
00057    void ident()
00058    {
00059       mCenter = ZeroVec3;
00060       mAxis[0] = XUnitVec3;
00061       mAxis[1] = YUnitVec3;
00062       mAxis[2] = ZUnitVec3;
00063       mHalfLen[0] = mHalfLen[1] = mHalfLen[2] = 0.0f;
00064    }
00065 
00066 public:
00067    Point3  mCenter;     // The center point of the box
00068    Vec3    mAxis[3];    // The axes of the oriented box (xAxis, yAxis, zAxis)
00069    float   mHalfLen[3]; // Half lengths of the box  ASSERT: HalfLens >= 0.0f
00070 };
00071 
00072 
00073 // ------------------------------------------------- //
00074 // --------------- Member definitions -------------- //
00075 // ------------------------------------------------- //
00076 inline
00077 OOBox::OOBox(OOBox& box)
00078 {
00079    mCenter = box.mCenter;
00080    mAxis[0] = box.mAxis[0];
00081    mAxis[1] = box.mAxis[1];
00082    mAxis[2] = box.mAxis[2];
00083    mHalfLen[0] = box.mHalfLen[0];
00084    mHalfLen[1] = box.mHalfLen[1];
00085    mHalfLen[2] = box.mHalfLen[2];
00086 }
00087 
00088 // Accessors
00089 inline Point3& OOBox::center()
00090 {
00091    return mCenter;
00092 }
00093 
00094 inline const Point3& OOBox::center() const
00095 {
00096    return mCenter;
00097 }
00098 
00099 inline Vec3& OOBox::axis (int i)
00100 {
00101    return mAxis[i];
00102 }
00103 
00104 inline const Vec3& OOBox::axis (int i) const
00105 {
00106    return mAxis[i];
00107 }
00108 
00109 inline Vec3* OOBox::axes ()
00110 {
00111    return mAxis;
00112 }
00113 
00114 inline const Vec3* OOBox::axes () const
00115 {
00116    return mAxis;
00117 }
00118 
00119 inline float& OOBox::halfLen(int i)
00120 {
00121    return mHalfLen[i];
00122 }
00123 
00124 inline const float& OOBox::halfLen(int i) const
00125 {
00126    return mHalfLen[i];
00127 }
00128 
00129 inline float* OOBox::halfLens()
00130 {
00131    return mHalfLen;
00132 }
00133 
00134 inline const float* OOBox::halfLens() const
00135 {
00136    return mHalfLen;
00137 }
00138 
00139 // Assignment
00140 inline OOBox& OOBox::operator=(const OOBox& box)
00141 {
00142    mCenter = box.mCenter;
00143    mAxis[0] = box.mAxis[0];
00144    mAxis[1] = box.mAxis[1];
00145    mAxis[2] = box.mAxis[2];
00146    mHalfLen[0] = box.mHalfLen[0];
00147    mHalfLen[1] = box.mHalfLen[1];
00148    mHalfLen[2] = box.mHalfLen[2];
00149    return *this;
00150 }
00151 
00152 // Comparison
00153 inline bool OOBox::operator==(const OOBox& box) const
00154 {
00155    return ((mCenter == box.mCenter) &&
00156            (mAxis[0] == box.mAxis[0]) &&
00157            (mAxis[1] == box.mAxis[1]) &&
00158            (mAxis[2] == box.mAxis[2]) &&
00159            (mHalfLen[0] == box.mHalfLen[0]) &&
00160            (mHalfLen[1] == box.mHalfLen[1]) &&
00161            (mHalfLen[2] == box.mHalfLen[2]));
00162 }
00163 
00164 inline void OOBox::getVerts(Point3 verts[8]) const
00165 {
00166    Vec3 x_half_axis = mAxis[0]*mHalfLen[0];
00167    Vec3 y_half_axis = mAxis[1]*mHalfLen[1];
00168    Vec3 z_half_axis = mAxis[2]*mHalfLen[2];
00169 
00170    verts[0] = mCenter - x_half_axis - y_half_axis - z_half_axis;
00171    verts[1] = mCenter + x_half_axis - y_half_axis - z_half_axis;
00172    verts[2] = mCenter + x_half_axis + y_half_axis - z_half_axis;
00173    verts[3] = mCenter - x_half_axis + y_half_axis - z_half_axis;
00174    verts[4] = mCenter - x_half_axis - y_half_axis + z_half_axis;
00175    verts[5] = mCenter + x_half_axis - y_half_axis + z_half_axis;
00176    verts[6] = mCenter + x_half_axis + y_half_axis + z_half_axis;
00177    verts[7] = mCenter - x_half_axis + y_half_axis + z_half_axis;
00178 }
00179 
00180 };
00181 
00182 #endif

Generated on Sun Sep 19 2010 14:35:14 for GenericMathTemplateLibrary by  doxygen 1.7.1