# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

aabbox.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_AABBOX_H
00027 #define NL_AABBOX_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/vector.h"
00031 #include "nel/misc/plane.h"
00032 #include "nel/misc/common.h"
00033 #include "nel/misc/stream.h"
00034 
00035 
00036 namespace NL3D {
00037 
00038 
00039 using   NLMISC::CVector;
00040 using   NLMISC::CPlane;
00041 
00042 
00043 // ***************************************************************************
00051 class CAABBox
00052 {
00053 protected:
00055         CVector                 Center;
00057         CVector                 HalfSize;
00058 
00059 public:
00060 
00062         CAABBox() : Center(0,0,0), HalfSize(0,0,0) {}
00063 
00064 
00066         // @{
00067         void                    setCenter(const CVector &center) {Center= center;}
00068         void                    setHalfSize(const CVector &hs) {HalfSize= hs;}
00069         void                    setSize(const CVector &s) {HalfSize= s/2;}
00071         void                    setMinMax(const CVector &bmin, const CVector &bmax)
00072         {
00073                 Center= (bmin+bmax)/2;
00074                 HalfSize= bmax-Center;
00075         }
00080         void                    extend(const CVector &v);
00082 
00083 
00085         // @{
00086         CVector                 getMin() const {return Center-HalfSize;}
00087         CVector                 getMax() const {return Center+HalfSize;}
00088         CVector                 getCenter() const {return Center;}
00089         CVector                 getHalfSize() const {return HalfSize;}
00091         CVector                 getSize() const {return HalfSize*2;}
00093         float                   getRadius() const {return HalfSize.norm();}
00094         // @}
00095 
00097         // @{
00099         bool                    clipFront(const CPlane &p) const;
00101         bool                    clipBack(const CPlane &p) const;
00103         bool                    include(const CVector &a) const;
00105         bool                    intersect(const CVector &a, const CVector &b, const CVector &c) const;
00106         // @}
00107 
00109         // @{
00111         void                    makePyramid(CPlane      planes[6]) const;
00112         // @}
00113 
00114         void                    serial(NLMISC::IStream &f);
00115 };
00116 
00117 
00118 // ***************************************************************************
00125 class   CAABBoxExt : private CAABBox
00126 {
00127 protected:
00128         float                   RadiusMin, RadiusMax;
00129 
00130         void                    updateRadius()
00131         {
00132                 // The bounding sphere.
00133                 RadiusMax= CAABBox::getRadius();
00134                 // The including sphere.
00135                 RadiusMin= NLMISC::minof((float)fabs(HalfSize.x), (float)fabs(HalfSize.y), (float)fabs(HalfSize.z));
00136         }
00137 
00138 public:
00140         CAABBoxExt() {RadiusMin= RadiusMax=0;}
00142         CAABBoxExt(const CAABBox &o) {RadiusMin= RadiusMax=0; *this=o;}
00143 
00144 
00146         // @{
00147         void                    setCenter(const CVector &center) {Center= center;}
00148         void                    setHalfSize(const CVector &hs) {HalfSize= hs; updateRadius();}
00149         void                    setSize(const CVector &s) {HalfSize= s/2;  updateRadius();}
00151         void                    setMinMax(const CVector &bmin, const CVector &bmax)
00152         {
00153                 Center= (bmin+bmax)/2;
00154                 HalfSize= bmax-Center;
00155                 updateRadius();
00156         }
00157         CAABBoxExt              &operator=(const CAABBox &o) {Center= o.getCenter(); HalfSize= o.getHalfSize(); updateRadius(); return (*this);}
00159 
00160 
00162         // @{
00163         CVector                 getMin() const {return CAABBox::getMin();}
00164         CVector                 getMax() const {return CAABBox::getMax();}
00165         CVector                 getCenter() const {return Center;}
00166         CVector                 getHalfSize() const {return HalfSize;}
00168         CVector                 getSize() const {return HalfSize*2;}
00170         float                   getRadius() const {return RadiusMax;}
00171         // @}
00172 
00174         // @{
00176         bool                    clipFront(const CPlane &p) const;
00178         bool                    clipBack(const CPlane &p) const;
00180         bool                    intersect(const CVector &a, const CVector &b, const CVector &c) const
00181                 {return CAABBox::intersect(a,b,c);}
00182         // @}
00183 
00184         void                    serial(NLMISC::IStream &f);
00185 };
00186 
00187 
00188 } // NL3D
00189 
00190 
00191 #endif // NL_AABBOX_H
00192 
00193 /* End of aabbox.h */