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

OSGDynamicVolume.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 
00040 //---------------------------------------------------------------------------
00041 //  Includes
00042 //---------------------------------------------------------------------------
00043 
00044 #include "OSGConfig.h"
00045 
00046 #include "new"
00047 
00048 // Class declarations
00049 #include "OSGDynamicVolume.h"
00050 #include "OSGBoxVolume.h"
00051 #include "OSGSphereVolume.h"
00052 #include "OSGCylinderVolume.h"
00053 
00054 OSG_USING_NAMESPACE
00055 
00056 
00057 /*-------------------------- constructor ----------------------------------*/
00058 
00059 DynamicVolume::DynamicVolume(Type type) :
00060     Volume()
00061 {
00062     setVolumeType(type);
00063 }
00064 
00065 DynamicVolume::DynamicVolume(const DynamicVolume &obj) :
00066      Volume(obj      ),
00067     _type  (obj._type)
00068 {
00069     switch(_type) 
00070     {
00071         case BOX_VOLUME:
00072             new (_volumeMem) 
00073                 BoxVolume   (*((OSG::BoxVolume    *)(obj._volumeMem)));
00074             break;
00075 
00076         case SPHERE_VOLUME:
00077             new (_volumeMem) 
00078                 SphereVolume(*((OSG::SphereVolume *)(obj._volumeMem)));
00079             break;
00080     }
00081 }
00082 
00083 void DynamicVolume::setVolumeType(Type type)
00084 {
00085     _type = type;
00086 
00087     switch(type)
00088     {
00089         case BOX_VOLUME:
00090             new (_volumeMem) BoxVolume;
00091             break;
00092         case SPHERE_VOLUME:
00093             new (_volumeMem) SphereVolume;
00094             break;
00095     }
00096 
00097     instanceChanged();
00098 }
00099 
00100 void DynamicVolume::morphToType(Type type)
00101 {
00102     Pnt3f         min;
00103     Pnt3f         max;
00104     Vec3f         vec;
00105     BoxVolume    *bv;
00106     SphereVolume *sv;
00107 
00108     if(type == _type)
00109     {
00110         return;
00111     }
00112     else
00113     {
00114         switch(type) 
00115         {
00116             case BOX_VOLUME:
00117 
00118                 getBounds(min, max);
00119 
00120                 bv = new (_volumeMem) BoxVolume;
00121 
00122                 bv->setBounds(min,max);
00123 
00124                 break;
00125 
00126             case SPHERE_VOLUME:
00127 
00128                 getBounds(min, max);
00129 
00130                 sv = new (_volumeMem) SphereVolume;
00131 
00132                 vec.setValues(max.x(), max.y(), max.z());
00133 
00134                 vec -= Vec3f(min.x(), min.y(), min.z());
00135 
00136                 sv->setValue(vec, vec.length()/2);
00137 
00138                 break;
00139         }
00140     }
00141 
00142     instanceChanged();
00143 }
00144 
00147 void DynamicVolume::getCenter(Pnt3f &center) const
00148 {
00149     getInstance().getCenter(center);
00150 }
00151 
00152 
00155 Real32 DynamicVolume::getScalarVolume(void) const
00156 {
00157     return getInstance().getScalarVolume();
00158 }
00159 
00160 
00163 void DynamicVolume::getBounds(Pnt3f &min, Pnt3f &max) const
00164 {
00165     getInstance().getBounds(min,max);
00166 }
00167 
00168 
00171 void DynamicVolume::extendBy(const Pnt3f &pt)
00172 {
00173     getInstance    ().extendBy(pt);
00174     instanceChanged();
00175 }
00176 
00177 
00180 void DynamicVolume::extendBy(const Volume &volume)
00181 {
00182     getInstance    ().extendBy(volume);
00183     instanceChanged();
00184 }
00185 
00186 
00189 bool DynamicVolume::intersect(const Pnt3f &point) const
00190 {
00191     return getInstance().intersect(point);
00192 }
00193 
00196 bool DynamicVolume::intersect(const Line &line ) const
00197 {
00198     return getInstance().intersect(line);
00199 }
00200 
00203 bool DynamicVolume::intersect(const Line   &line,
00204                                     Real32 &enter, 
00205                                     Real32 &exit ) const
00206 {
00207     return getInstance().intersect(line, enter, exit);
00208 }
00209 
00212 bool DynamicVolume::intersect(const Volume &volume) const
00213 {
00214     return getInstance().intersect(volume);
00215 }
00216 
00219 bool DynamicVolume::isOnSurface(const Pnt3f &point) const
00220 {
00221     return getInstance().isOnSurface(point);
00222 }
00223 
00226 void DynamicVolume::transform(const Matrix &matrix)
00227 {
00228     getInstance    ().transform(matrix);
00229     instanceChanged();
00230 }
00231 
00234 void DynamicVolume::dump(UInt32 uiIndent, const BitVector bvFlags) const
00235 {
00236     PLOG << "Dyn:";
00237     
00238     getInstance().dump(uiIndent, bvFlags);
00239 }
00240 
00241 
00242 bool 
00243     DynamicVolume::operator ==(const DynamicVolume &OSG_CHECK_ARG(other)) const
00244 {
00245     return false; 
00246 }
00247 
00248 
00249 DynamicVolume &DynamicVolume::operator =(const DynamicVolume &source)
00250 {
00251     _type = source._type;
00252 
00253     switch(_type)
00254     {
00255         case BOX_VOLUME:
00256             new (_volumeMem)
00257                 BoxVolume   (*((OSG::BoxVolume    *)(source._volumeMem)));
00258             break;
00259 
00260         case SPHERE_VOLUME:
00261             new (_volumeMem)
00262                 SphereVolume(*((OSG::SphereVolume *)(source._volumeMem)));
00263             break;
00264     }
00265 
00266     instanceChanged();
00267 
00268     return *this;
00269 }
00270 
00271 /***************************************************************************\
00272  *                           Instance methods                              *
00273 \***************************************************************************/

Generated on Thu Aug 25 04:04:37 2005 for OpenSG by  doxygen 1.4.3