TAPs 0.7.7.3
TAPsBVSupportFns.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsBVSupportFns.hpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (08/26/2010)
00009 UPDATE          (09/26/2010)
00010 ******************************************************************************/
00011 #include "TAPsBVSupportFns.hpp"
00012 // Using Inclusion Model (i.e. definitions are included in declarations)
00013 //                       (this name.cpp is included in name.hpp)
00014 // Each friend is defined directly inside its declaration.
00015 
00016 BEGIN_NAMESPACE_TAPs
00017 //=============================================================================
00018 //-----------------------------------------------------------------------------
00019 template <typename T>
00020 BoundingVolume<T> * BVSupportFns<T>::CreateBVOfType ( Enum::CD type )
00021 {
00022     switch ( type ) {
00023         case Enum::BOUNDING_SPHERE:
00024             return CreateBVSphere();
00025         case Enum::BOUNDING_CYLINDER:
00026             return CreateBVCylinder();
00027         case Enum::BOUNDING_BOX:
00028             return CreateBVBox();
00029         default:
00030             return NULL;
00031     }
00032 }
00033 //-----------------------------------------------------------------------------
00034 template <typename T>
00035 BoundingSphere<T> * BVSupportFns<T>::CreateBVSphere ()
00036 {
00037     return new BoundingSphere<T>();
00038 }
00039 //-----------------------------------------------------------------------------
00040 template <typename T>
00041 BoundingCylinder<T> * BVSupportFns<T>::CreateBVCylinder ()
00042 {
00043     return new BoundingCylinder<T>();
00044 }
00045 //-----------------------------------------------------------------------------
00046 template <typename T>
00047 BoundingBox<T> * BVSupportFns<T>::CreateBVBox ()
00048 {
00049     return new BoundingBox<T>();
00050 }
00051 //-----------------------------------------------------------------------------
00052 
00053 
00054 #if defined(__gl_h_) || defined(__GL_H__)
00055 //-----------------------------------------------------------------------------
00056 template <typename T>
00057 BoundingVolume<T> * BVSupportFns<T>::CreateBVOfType (
00058     Enum::CD type,
00059     OpenGL::OpenGLModel<T> * pModel
00060 )
00061 {
00062     BoundingVolume<T> * pBV;
00063     switch ( type ) {
00064         case Enum::BOUNDING_SPHERE:
00065             pBV = CreateBVSphere();
00066             break;
00067         case Enum::BOUNDING_CYLINDER:
00068             pBV = CreateBVCylinder();
00069             break;
00070         case Enum::BOUNDING_BOX:
00071             pBV = CreateBVBox();
00072             break;
00073         default:
00074             return NULL;
00075     }
00076     if ( !pBV ) return NULL;
00077 
00078     //
00079     // Find and set bounding data for the model
00080     //
00081     if ( pModel ) {
00082 
00083         switch ( type ) {
00084             case Enum::BOUNDING_SPHERE:
00085                 {
00086                     pModel->CalBoundingSphere();
00087                     Vector3<T> lowPt = pModel->GetBoundingAABBLowPoint();
00088                     Vector3<T> highPt = pModel->GetBoundingAABBHighPoint();
00089                     Vector3<T> center = ( highPt + lowPt ) * T(0.5);
00090                     pBV->SetCenter( center );
00091                     pBV->SetRadius( highPt.Length() );
00092                 }
00093                 break;
00094             case Enum::BOUNDING_CYLINDER:
00095                 break;
00096             case Enum::BOUNDING_BOX:
00097                 {
00098                     pModel->CalBoundingAABB();
00099                     Vector3<T> lowPt = pModel->GetBoundingAABBLowPoint();
00100                     Vector3<T> highPt = pModel->GetBoundingAABBHighPoint();
00101                     Vector3<T> center = ( highPt + lowPt ) * T(0.5);
00102                     pBV->SetCenter( center );
00103                     pBV->SetWidth(  highPt[0] - lowPt[0] );
00104                     pBV->SetHeight( highPt[1] - lowPt[1] );
00105                     pBV->SetDepth(  highPt[2] - lowPt[2] );
00106                 }
00107                 break;
00108             default:
00109                 break;
00110         }
00111     }
00112 
00113     std::cout << "BV: " << *pBV << "\n";
00114 
00115     return pBV;
00116 }
00117 //-----------------------------------------------------------------------------
00118 #endif
00119 
00120 
00121 //=============================================================================
00122 END_NAMESPACE_TAPs
00123 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00124 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines