Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OOBox.h

Go to the documentation of this file.
00001 /************************************************************** ggt-head beg
00002  *
00003  * GGT: Generic Graphics Toolkit
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile: OOBox.h,v $
00010  * Date modified: $Date: 2002/05/20 22:39:22 $
00011  * Version:       $Revision: 1.5 $
00012  * -----------------------------------------------------------------
00013  *
00014  *********************************************************** ggt-head end */
00015 /*************************************************************** ggt-cpr beg
00016 *
00017 * GGT: The Generic Graphics Toolkit
00018 * Copyright (C) 2001,2002 Allen Bierbaum
00019 *
00020 * This library is free software; you can redistribute it and/or
00021 * modify it under the terms of the GNU Lesser General Public
00022 * License as published by the Free Software Foundation; either
00023 * version 2.1 of the License, or (at your option) any later version.
00024 *
00025 * This library is distributed in the hope that it will be useful,
00026 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00028 * Lesser General Public License for more details.
00029 *
00030 * You should have received a copy of the GNU Lesser General Public
00031 * License along with this library; if not, write to the Free Software
00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033 *
00034  ************************************************************ ggt-cpr end */
00035 #ifndef _GMTL_OOBox_H_
00036 #define _GMTL_OOBox_H_
00037 
00038 #include <gmtl/Vec3.h>
00039 #include <gmtl/Point3.h>
00040 #include <gmtl/matVecFuncs.h>
00041 
00042 namespace gmtl
00043 {
00044 
00045 // AABox : Defines an object aligned box
00046 //
00047 // For definition of an OOB, see pg 293-294 of Real-Time Rendering
00048 class  OOBox
00049 {
00050 
00051 public:
00052    OOBox()
00053    { ident(); }
00054 
00055    OOBox(OOBox& box);
00056 
00057 public:
00058    // Accessors
00059    Point3& center();
00060    const Point3& center() const;
00061 
00062    Vec3& axis (int i);
00063    const Vec3& axis (int i) const;
00064    Vec3* axes ();
00065    const Vec3* axes () const;
00066 
00067    float& halfLen(int i);
00068    const float& halfLen(int i) const;
00069    float* halfLens();
00070    const float* halfLens() const;
00071 
00072    // Assignment
00073    OOBox& operator=(const OOBox& box);
00074 
00075    // Comparison
00076    bool operator==(const OOBox& box) const;
00077 
00078    //  return the verts that define the box
00079    // Order: XYZ: 000, 100, 110, 010,
00080    //             001, 101, 111, 011
00081    void getVerts(Point3 verts[8]) const;
00082 
00083    // Merge current box with other box to get new box covering both
00084    void mergeWith(const OOBox& box);
00085 
00086    void ident()
00087    {
00088       mCenter = ZeroVec3;
00089       mAxis[0] = XUnitVec3;
00090       mAxis[1] = YUnitVec3;
00091       mAxis[2] = ZUnitVec3;
00092       mHalfLen[0] = mHalfLen[1] = mHalfLen[2] = 0.0f;
00093    }
00094 
00095 public:
00096    Point3  mCenter;     // The center point of the box
00097    Vec3    mAxis[3];    // The axes of the oriented box (xAxis, yAxis, zAxis)
00098    float   mHalfLen[3]; // Half lengths of the box  ASSERT: HalfLens >= 0.0f
00099 };
00100 
00101 
00102 // ------------------------------------------------- //
00103 // --------------- Member definitions -------------- //
00104 // ------------------------------------------------- //
00105 inline
00106 OOBox::OOBox(OOBox& box)
00107 {
00108    mCenter = box.mCenter;
00109    mAxis[0] = box.mAxis[0];
00110    mAxis[1] = box.mAxis[1];
00111    mAxis[2] = box.mAxis[2];
00112    mHalfLen[0] = box.mHalfLen[0];
00113    mHalfLen[1] = box.mHalfLen[1];
00114    mHalfLen[2] = box.mHalfLen[2];
00115 }
00116 
00117 // Accessors
00118 inline Point3& OOBox::center()
00119 {
00120    return mCenter;
00121 }
00122 
00123 inline const Point3& OOBox::center() const
00124 {
00125    return mCenter;
00126 }
00127 
00128 inline Vec3& OOBox::axis (int i)
00129 {
00130    return mAxis[i];
00131 }
00132 
00133 inline const Vec3& OOBox::axis (int i) const
00134 {
00135    return mAxis[i];
00136 }
00137 
00138 inline Vec3* OOBox::axes ()
00139 {
00140    return mAxis;
00141 }
00142 
00143 inline const Vec3* OOBox::axes () const
00144 {
00145    return mAxis;
00146 }
00147 
00148 inline float& OOBox::halfLen(int i)
00149 {
00150    return mHalfLen[i];
00151 }
00152 
00153 inline const float& OOBox::halfLen(int i) const
00154 {
00155    return mHalfLen[i];
00156 }
00157 
00158 inline float* OOBox::halfLens()
00159 {
00160    return mHalfLen;
00161 }
00162 
00163 inline const float* OOBox::halfLens() const
00164 {
00165    return mHalfLen;
00166 }
00167 
00168 // Assignment
00169 inline OOBox& OOBox::operator=(const OOBox& box)
00170 {
00171    mCenter = box.mCenter;
00172    mAxis[0] = box.mAxis[0];
00173    mAxis[1] = box.mAxis[1];
00174    mAxis[2] = box.mAxis[2];
00175    mHalfLen[0] = box.mHalfLen[0];
00176    mHalfLen[1] = box.mHalfLen[1];
00177    mHalfLen[2] = box.mHalfLen[2];
00178    return *this;
00179 }
00180 
00181 // Comparison
00182 inline bool OOBox::operator==(const OOBox& box) const
00183 {
00184    return ((mCenter == box.mCenter) &&
00185            (mAxis[0] == box.mAxis[0]) &&
00186            (mAxis[1] == box.mAxis[1]) &&
00187            (mAxis[2] == box.mAxis[2]) &&
00188            (mHalfLen[0] == box.mHalfLen[0]) &&
00189            (mHalfLen[1] == box.mHalfLen[1]) &&
00190            (mHalfLen[2] == box.mHalfLen[2]));
00191 }
00192 
00193 inline void OOBox::getVerts(Point3 verts[8]) const
00194 {
00195    Vec3 x_half_axis = mAxis[0]*mHalfLen[0];
00196    Vec3 y_half_axis = mAxis[1]*mHalfLen[1];
00197    Vec3 z_half_axis = mAxis[2]*mHalfLen[2];
00198 
00199    verts[0] = mCenter - x_half_axis - y_half_axis - z_half_axis;
00200    verts[1] = mCenter + x_half_axis - y_half_axis - z_half_axis;
00201    verts[2] = mCenter + x_half_axis + y_half_axis - z_half_axis;
00202    verts[3] = mCenter - x_half_axis + y_half_axis - z_half_axis;
00203    verts[4] = mCenter - x_half_axis - y_half_axis + z_half_axis;
00204    verts[5] = mCenter + x_half_axis - y_half_axis + z_half_axis;
00205    verts[6] = mCenter + x_half_axis + y_half_axis + z_half_axis;
00206    verts[7] = mCenter - x_half_axis + y_half_axis + z_half_axis;
00207 }
00208 
00209 };
00210 
00211 #endif

Generated on Mon Apr 7 15:28:55 2003 for GenericMathTemplateLibrary by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002