![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsBoundingVolume.hpp 00003 00004 BoundingVolume class is an abstract class for a bounding volume. 00005 00006 SUKITTI PUNAK (08/21/2006) 00007 UPDATE (08/28/20100) 00008 ******************************************************************************/ 00009 #include "TAPsBoundingVolume.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs 00015 //----------------------------------------------------------------------------- 00016 // static initialization 00017 template <typename T> int BoundingVolume<T>::m_iTotal = 0; 00018 //============================================================================= 00019 // Constructor(s) and Destructor 00020 //----------------------------------------------------------------------------- 00021 template <typename T> 00022 BoundingVolume<T>::BoundingVolume ( Enum::CD type ) 00023 : m_pPhysicsSupport( NULL) //PhysicsSupport<T>() 00024 , m_eType( type ) 00025 , m_iID( m_iTotal ) 00026 , m_strName( "" ) 00027 { 00028 ++m_iTotal; 00029 } 00030 //----------------------------------------------------------------------------- 00031 template <typename T> 00032 BoundingVolume<T>::BoundingVolume ( Enum::CD type, int id ) 00033 : m_pPhysicsSupport( NULL ) //PhysicsSupport<T>() 00034 , m_eType( type ) 00035 , m_iID( id ) 00036 , m_strName( "" ) 00037 { 00038 ++m_iTotal; 00039 } 00040 //----------------------------------------------------------------------------- 00041 template <typename T> 00042 BoundingVolume<T>::BoundingVolume ( BoundingVolume<T> const & orig ) 00043 : m_pPhysicsSupport( NULL ) //PhysicsSupport<T>() 00044 , m_eType( orig.m_eType ) 00045 , m_iID( orig.m_iID ) 00046 , m_strName( orig.m_strName ) 00047 , m_Transform( orig.m_Transform ) 00048 { 00049 ++m_iTotal; 00050 } 00051 //----------------------------------------------------------------------------- 00052 template <typename T> 00053 BoundingVolume<T>::~BoundingVolume () 00054 { 00055 --m_iTotal; 00056 } 00057 //----------------------------------------------------------------------------- 00058 // Return this object info as a string 00059 template <typename T> 00060 std::string BoundingVolume<T>::StrInfo () const 00061 { 00062 std::string str = "The Bounding Object Type is "; 00063 switch ( m_eType ) { 00064 case Enum::UNDEFINED_TYPE: 00065 str += "\"UNDEFINED_TYPE\""; 00066 break; 00067 case Enum::BOUNDING_SPHERE: 00068 str += "\"BOUNDING_SPHERE\""; 00069 break; 00070 case Enum::BOUNDING_HALF_SPHERE: 00071 str += "\"BOUNDING_HALF_SPHERE\""; 00072 break; 00073 case Enum::BOUNDING_BOX: 00074 str += "\"BOUNDING_BOX\""; 00075 break; 00076 case Enum::BOUNDING_CYLINDER: 00077 str += "\"BOUNDING_CYLINDER\""; 00078 break; 00079 case Enum::BOUNDING_CONE: 00080 str += "\"BOUNDING_CONE\""; 00081 break; 00082 case Enum::BOUNDING_ELLIPSOID: 00083 str += "\"BOUNDING_ELLIPSOID\""; 00084 break; 00085 case Enum::BOUNDING_HALF_ELLIPSOID: 00086 str += "\"BOUNDING_HALF_ELLIPSOID\""; 00087 break; 00088 case Enum::BOUNDING_CAPSULE: 00089 str += "\"BOUNDING_CAPSULE\""; 00090 break; 00091 case Enum::BOUNDING_POLYTOPE: 00092 str += "\"BOUNDING_POLYTOPE\""; 00093 break; 00094 default: 00095 str += "\nUnrecognized Type!"; 00096 break; 00097 } 00098 str += " of type " + std::string( typeid(T).name() ) + "."; 00099 //------------------------------------------- 00100 // Properties 00101 std::ostringstream ss; 00102 ss << "\n ID: " << m_iID; 00103 ss << "\n Name: \"" << m_strName << "\""; 00104 ss << "\n Trx: " << m_Transform; 00105 ss << "\n Center: " << m_vCenter[0] << ", " << m_vCenter[1] << ", " << m_vCenter[2]; 00106 str += ss.str(); 00107 00108 return str; 00109 } 00110 //----------------------------------------------------------------------------- 00111 // Assignment Operator 00112 template <typename T> 00113 inline BoundingVolume<T> & BoundingVolume<T>::operator= ( BoundingVolume<T> const & orig ) 00114 { 00115 if ( this != &orig ) { 00116 m_eType = orig.m_eType; 00117 m_iID = orig.m_iID; 00118 m_strName = orig.m_strName; 00119 m_Transform = orig.m_Transform; 00120 } 00121 return *this; 00122 } 00123 //----------------------------------------------------------------------------- 00124 // Get/Set Fns 00125 template <typename T> 00126 int BoundingVolume<T>::GetID () const 00127 { 00128 return m_iID; 00129 } 00130 //----------------------------------------------------------------------------- 00131 template <typename T> 00132 void BoundingVolume<T>::SetID ( int id ) 00133 { 00134 m_iID = id; 00135 } 00136 //----------------------------------------------------------------------------- 00137 template <typename T> 00138 std::string const & BoundingVolume<T>::GetName () const 00139 { 00140 return m_strName; 00141 } 00142 //----------------------------------------------------------------------------- 00143 template <typename T> 00144 void BoundingVolume<T>::SetName ( std::string const & name ) 00145 { 00146 m_strName = name; 00147 } 00148 //----------------------------------------------------------------------------- 00149 template <typename T> 00150 Enum::CD BoundingVolume<T>::GetType () const 00151 { 00152 return m_eType; 00153 } 00154 //----------------------------------------------------------------------------- 00155 //============================================================================= 00156 // Operations 00157 /* 00158 //----------------------------------------------------------------------------- 00159 // TestOverlapWith 00160 template <typename T> 00161 T BVHNode<T>::TestOverlapWith ( BVHNode<T> const * const that ) const 00162 { 00163 switch ( m_eType ) { 00164 case Enum::BVH_NODE_BINARY_SPHERE: 00165 case Enum::BVH_NODE_QUAD_SPHERE: 00166 case Enum::BVH_NODE_OCTANT_SPHERE: 00167 case Enum::BVH_NODE_GENERIC_SPHERE: 00168 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00169 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00170 switch ( that->m_eType ) { 00171 case Enum::BVH_NODE_BINARY_SPHERE: 00172 case Enum::BVH_NODE_QUAD_SPHERE: 00173 case Enum::BVH_NODE_OCTANT_SPHERE: 00174 case Enum::BVH_NODE_GENERIC_SPHERE: 00175 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00176 return ( GetCenter() - that->GetCenter() ).Length() 00177 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00178 break; 00179 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00180 return ( GetCenter() - that->GetCenter() ).Length() 00181 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00182 break; 00183 default: 00184 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00185 assert( false ); 00186 break; 00187 } 00188 break; 00189 default: 00190 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00191 assert( false ); 00192 break; 00193 } 00194 return -777; // -777 is an Error Code 00195 } 00196 //*/ 00197 /* 00198 //----------------------------------------------------------------------------- 00199 // TestOverlapWithTillLeafNodes 00200 template <typename T> 00201 T BVHNode<T>::TestOverlapWithTillLeafNodes ( BVHNode<T> const * const that ) const 00202 { 00203 switch ( m_eType ) { 00204 case Enum::BVH_NODE_BINARY_SPHERE: 00205 case Enum::BVH_NODE_QUAD_SPHERE: 00206 case Enum::BVH_NODE_OCTANT_SPHERE: 00207 case Enum::BVH_NODE_GENERIC_SPHERE: 00208 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00209 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00210 switch ( that->m_eType ) { 00211 case Enum::BVH_NODE_BINARY_SPHERE: 00212 case Enum::BVH_NODE_QUAD_SPHERE: 00213 case Enum::BVH_NODE_OCTANT_SPHERE: 00214 case Enum::BVH_NODE_GENERIC_SPHERE: 00215 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00216 return ( GetCenter() - that->GetCenter() ).Length() 00217 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00218 break; 00219 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00220 return ( GetCenter() - that->GetCenter() ).Length() 00221 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00222 break; 00223 default: 00224 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00225 assert( false ); 00226 break; 00227 } 00228 break; 00229 default: 00230 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00231 assert( false ); 00232 break; 00233 } 00234 return -777; // -777 is an Error Code 00235 } 00236 //*/ 00237 /* 00238 //----------------------------------------------------------------------------- 00239 // TestOverlapSphereWithSphere #1 00240 template <typename T> 00241 T BVHNode<T>::TestOverlapSphereWithSphere ( BVHNode<T> const * const that ) const 00242 { 00243 return ( GetCenter() - that->GetCenter() ).Length() 00244 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00245 } 00246 //----------------------------------------------------------------------------- 00247 // TestOverlapSphereWithSphere #2 00248 template <typename T> 00249 T BVHNode<T>::TestOverlapSphereWithSphere ( 00250 BVHNode<T> const * const that, 00251 Matrix4x4<T> const & thatTransform ) const 00252 { 00253 return ( GetCenter() 00254 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00255 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00256 } 00257 //----------------------------------------------------------------------------- 00258 // TestOverlapSphereWithSphere #3 00259 template <typename T> 00260 T BVHNode<T>::TestOverlapSphereWithSphere ( 00261 Matrix4x4<T> const & thisTransform, 00262 BVHNode<T> const * const that ) const 00263 { 00264 return ( (thisTransform*GetCenter()).GetVector3() 00265 - that->GetCenter() ).Length() 00266 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00267 } 00268 //----------------------------------------------------------------------------- 00269 // TestOverlapSphereWithSphere #4 00270 template <typename T> 00271 T BVHNode<T>::TestOverlapSphereWithSphere ( 00272 Matrix4x4<T> const & thisTransform, 00273 BVHNode<T> const * const that, 00274 Matrix4x4<T> const & thatTransform ) const 00275 { 00276 return ( (thisTransform*GetCenter()).GetVector3() 00277 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00278 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00279 } 00280 //----------------------------------------------------------------------------- 00281 // TestOverlapSphereWithSphereTillLeafNodes #1 00282 template <typename T> 00283 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( BVHNode<T> const * const that ) const 00284 { 00285 return ( GetCenter() - that->GetCenter() ).Length() 00286 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00287 } 00288 //----------------------------------------------------------------------------- 00289 // TestOverlapSphereWithSphereTillLeafNodes #2 00290 template <typename T> 00291 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00292 BVHNode<T> const * const that, 00293 Matrix4x4<T> const & thatTransform ) const 00294 { 00295 return ( GetCenter() 00296 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00297 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00298 } 00299 //----------------------------------------------------------------------------- 00300 // TestOverlapSphereWithSphereTillLeafNodes #3 00301 template <typename T> 00302 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00303 Matrix4x4<T> const & thisTransform, 00304 BVHNode<T> const * const that ) const 00305 { 00306 return ( (thisTransform*GetCenter()).GetVector3() 00307 - that->GetCenter() ).Length() 00308 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00309 } 00310 //----------------------------------------------------------------------------- 00311 // TestOverlapSphereWithSphereTillLeafNodes #4 00312 template <typename T> 00313 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00314 Matrix4x4<T> const & thisTransform, 00315 BVHNode<T> const * const that, 00316 Matrix4x4<T> const & thatTransform ) const 00317 { 00318 return ( (thisTransform*GetCenter()).GetVector3() 00319 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00320 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00321 } 00322 //*/ 00323 //----------------------------------------------------------------------------- 00324 //#if defined(__gl_h_) || defined(__GL_H__) 00325 //============================================================================= 00326 // DrawByOpenGL 00327 //----------------------------------------------------------------------------- 00328 //template <typename T> GLuint BVHNode<T>::m_uiDisplayList = 0; 00329 //----------------------------------------------------------------------------- 00330 //template <typename T> 00331 //void BVHNode<T>::DrawByOpenGL ( Vector4<T> color ) 00332 //{} 00333 //----------------------------------------------------------------------------- 00334 //#endif 00335 //============================================================================= 00336 END_NAMESPACE_TAPs 00337 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00338 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----