![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsMultiBoundingVolume.cpp 00003 ******************************************************************************/ 00008 /****************************************************************************** 00009 SUKITTI PUNAK (08/22/2006) 00010 UPDATE (12/01/2010) 00011 ******************************************************************************/ 00012 #include "TAPsMultiBoundingVolume.hpp" 00013 // Using Inclusion Model (i.e. definitions are included in declarations) 00014 // (this name.cpp is included in name.hpp) 00015 // Each friend is defined directly inside its declaration. 00016 00017 BEGIN_NAMESPACE_TAPs 00018 //----------------------------------------------------------------------------- 00019 // static initialization 00020 template <typename T> int MultiBoundingVolume<T>::m_iTotal = 0; 00021 template <typename T> TransformationSupport<T> MultiBoundingVolume<T>::g_dummyTransformation; 00022 //============================================================================= 00023 // Constructor(s) and Destructor 00024 //----------------------------------------------------------------------------- 00025 template <typename T> 00026 MultiBoundingVolume<T>::MultiBoundingVolume () 00027 : PhysicsSupport<T>(), 00028 m_iID( m_iTotal ), 00029 m_strName( "" ), 00030 m_refTransform( g_dummyTransformation ) 00031 { 00032 ++m_iTotal; 00033 } 00034 //----------------------------------------------------------------------------- 00035 template <typename T> 00036 MultiBoundingVolume<T>::MultiBoundingVolume ( int id ) 00037 : PhysicsSupport<T>(), 00038 m_iID( id ), 00039 m_strName( "" ), 00040 m_refTransform( g_dummyTransformation ) 00041 { 00042 ++m_iTotal; 00043 } 00044 //----------------------------------------------------------------------------- 00045 /* 00046 template <typename T> 00047 MultiBoundingVolume<T>::MultiBoundingVolume ( const MultiBoundingVolume<T> & orig ) 00048 : PhysicsSupport<T>( orig ), 00049 m_iID( orig.m_iID ), 00050 m_strName( orig.m_strName ), 00051 m_refTransform( &(orig.m_refTransform) ) 00052 { 00053 m_vBoundingVolumePtrList = orig.m_vBoundingVolumePtrList; 00054 ++m_iTotal; 00055 } 00056 //*/ 00057 //----------------------------------------------------------------------------- 00058 template <typename T> 00059 MultiBoundingVolume<T>::~MultiBoundingVolume () 00060 { 00061 --m_iTotal; 00062 for ( std::vector< BoundingVolume<T> * >::iterator it = GetBoundingVolumeList().begin(); it != GetBoundingVolumeList().end(); ++it ) { 00063 delete *it; 00064 } 00065 GetBoundingVolumeList().clear(); 00066 } 00067 //----------------------------------------------------------------------------- 00068 // Get/Set Fns 00069 template <typename T> 00070 int MultiBoundingVolume<T>::GetID () const 00071 { 00072 return m_iId; 00073 } 00074 //----------------------------------------------------------------------------- 00075 template <typename T> 00076 void MultiBoundingVolume<T>::SetID ( int id ) 00077 { 00078 m_iId = id; 00079 } 00080 //----------------------------------------------------------------------------- 00081 template <typename T> 00082 std::string const & MultiBoundingVolume<T>::GetName () const 00083 { 00084 return m_strName; 00085 } 00086 //----------------------------------------------------------------------------- 00087 template <typename T> 00088 void MultiBoundingVolume<T>::SetName ( std::string const & name ) 00089 { 00090 m_strName = name; 00091 } 00092 //----------------------------------------------------------------------------- 00093 //----------------------------------------------------------------------------- 00094 // virtual void TransformByTranslationRatationAndScale (); 00095 //template <typename T> 00096 //void MultiBoundingVolume<T>::TransformByTranslationRatationAndScale () 00097 //{} 00098 //----------------------------------------------------------------------------- 00099 template <typename T> 00100 void MultiBoundingVolume<T>::ScaledBy ( T val ) 00101 { 00102 assert( 0.0 <= val ); 00103 //--------------------------------------------------------------- 00104 std::vector< BoundingVolume<T> * >::iterator pos = 00105 m_vBoundingVolumePtrList.begin(); 00106 while ( pos != m_vBoundingVolumePtrList.end() ) { 00107 assert( *pos != NULL ); 00108 (*pos)->ScaledBy( val ); 00109 ++pos; 00110 } 00111 // GetTransform().MakeIdentity(); 00112 } 00113 //----------------------------------------------------------------------------- 00114 //============================================================================= 00115 // Operations 00116 //----------------------------------------------------------------------------- 00117 // TestOverlapWith 00118 template <typename T> 00119 T MultiBoundingVolume<T>::TestOverlapWith ( BoundingVolume<T> const * const that ) const 00120 { 00121 return 0; 00122 } 00123 //----------------------------------------------------------------------------- 00124 // TestOverlapWith 00125 template <typename T> 00126 T MultiBoundingVolume<T>::TestOverlapWith ( MultiBoundingVolume<T> const * const that ) const 00127 { 00128 return 0; 00129 } 00130 /* 00131 //----------------------------------------------------------------------------- 00132 // TestOverlapWith 00133 template <typename T> 00134 T BVHNode<T>::TestOverlapWith ( BVHNode<T> const * const that ) const 00135 { 00136 switch ( m_eType ) { 00137 case Enum::BVH_NODE_BINARY_SPHERE: 00138 case Enum::BVH_NODE_QUAD_SPHERE: 00139 case Enum::BVH_NODE_OCTANT_SPHERE: 00140 case Enum::BVH_NODE_GENERIC_SPHERE: 00141 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00142 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00143 switch ( that->m_eType ) { 00144 case Enum::BVH_NODE_BINARY_SPHERE: 00145 case Enum::BVH_NODE_QUAD_SPHERE: 00146 case Enum::BVH_NODE_OCTANT_SPHERE: 00147 case Enum::BVH_NODE_GENERIC_SPHERE: 00148 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00149 return ( GetCenter() - that->GetCenter() ).Length() 00150 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00151 break; 00152 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00153 return ( GetCenter() - that->GetCenter() ).Length() 00154 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00155 break; 00156 default: 00157 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00158 assert( false ); 00159 break; 00160 } 00161 break; 00162 default: 00163 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00164 assert( false ); 00165 break; 00166 } 00167 return -777; // -777 is an Error Code 00168 } 00169 //*/ 00170 /* 00171 //----------------------------------------------------------------------------- 00172 // TestOverlapWithTillLeafNodes 00173 template <typename T> 00174 T BVHNode<T>::TestOverlapWithTillLeafNodes ( BVHNode<T> const * const that ) const 00175 { 00176 switch ( m_eType ) { 00177 case Enum::BVH_NODE_BINARY_SPHERE: 00178 case Enum::BVH_NODE_QUAD_SPHERE: 00179 case Enum::BVH_NODE_OCTANT_SPHERE: 00180 case Enum::BVH_NODE_GENERIC_SPHERE: 00181 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00182 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00183 switch ( that->m_eType ) { 00184 case Enum::BVH_NODE_BINARY_SPHERE: 00185 case Enum::BVH_NODE_QUAD_SPHERE: 00186 case Enum::BVH_NODE_OCTANT_SPHERE: 00187 case Enum::BVH_NODE_GENERIC_SPHERE: 00188 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00189 return ( GetCenter() - that->GetCenter() ).Length() 00190 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00191 break; 00192 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00193 return ( GetCenter() - that->GetCenter() ).Length() 00194 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00195 break; 00196 default: 00197 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00198 assert( false ); 00199 break; 00200 } 00201 break; 00202 default: 00203 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00204 assert( false ); 00205 break; 00206 } 00207 return -777; // -777 is an Error Code 00208 } 00209 //*/ 00210 /* 00211 //----------------------------------------------------------------------------- 00212 // TestOverlapSphereWithSphere #1 00213 template <typename T> 00214 T BVHNode<T>::TestOverlapSphereWithSphere ( BVHNode<T> const * const that ) const 00215 { 00216 return ( GetCenter() - that->GetCenter() ).Length() 00217 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00218 } 00219 //----------------------------------------------------------------------------- 00220 // TestOverlapSphereWithSphere #2 00221 template <typename T> 00222 T BVHNode<T>::TestOverlapSphereWithSphere ( 00223 BVHNode<T> const * const that, 00224 Matrix4x4<T> const & thatTransform ) const 00225 { 00226 return ( GetCenter() 00227 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00228 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00229 } 00230 //----------------------------------------------------------------------------- 00231 // TestOverlapSphereWithSphere #3 00232 template <typename T> 00233 T BVHNode<T>::TestOverlapSphereWithSphere ( 00234 Matrix4x4<T> const & thisTransform, 00235 BVHNode<T> const * const that ) const 00236 { 00237 return ( (thisTransform*GetCenter()).GetVector3() 00238 - that->GetCenter() ).Length() 00239 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00240 } 00241 //----------------------------------------------------------------------------- 00242 // TestOverlapSphereWithSphere #4 00243 template <typename T> 00244 T BVHNode<T>::TestOverlapSphereWithSphere ( 00245 Matrix4x4<T> const & thisTransform, 00246 BVHNode<T> const * const that, 00247 Matrix4x4<T> const & thatTransform ) const 00248 { 00249 return ( (thisTransform*GetCenter()).GetVector3() 00250 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00251 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00252 } 00253 //----------------------------------------------------------------------------- 00254 // TestOverlapSphereWithSphereTillLeafNodes #1 00255 template <typename T> 00256 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( BVHNode<T> const * const that ) const 00257 { 00258 return ( GetCenter() - that->GetCenter() ).Length() 00259 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00260 } 00261 //----------------------------------------------------------------------------- 00262 // TestOverlapSphereWithSphereTillLeafNodes #2 00263 template <typename T> 00264 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00265 BVHNode<T> const * const that, 00266 Matrix4x4<T> const & thatTransform ) const 00267 { 00268 return ( GetCenter() 00269 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00270 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00271 } 00272 //----------------------------------------------------------------------------- 00273 // TestOverlapSphereWithSphereTillLeafNodes #3 00274 template <typename T> 00275 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00276 Matrix4x4<T> const & thisTransform, 00277 BVHNode<T> const * const that ) const 00278 { 00279 return ( (thisTransform*GetCenter()).GetVector3() 00280 - that->GetCenter() ).Length() 00281 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00282 } 00283 //----------------------------------------------------------------------------- 00284 // TestOverlapSphereWithSphereTillLeafNodes #4 00285 template <typename T> 00286 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00287 Matrix4x4<T> const & thisTransform, 00288 BVHNode<T> const * const that, 00289 Matrix4x4<T> const & thatTransform ) const 00290 { 00291 return ( (thisTransform*GetCenter()).GetVector3() 00292 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00293 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00294 } 00295 //*/ 00296 //----------------------------------------------------------------------------- 00297 #if defined(__gl_h_) || defined(__GL_H__) 00298 //============================================================================= 00299 // DrawByOpenGL 00300 //----------------------------------------------------------------------------- 00301 template <typename T> 00302 void MultiBoundingVolume<T>::Draw ( GLenum drawStyle, Vector4<T> color ) 00303 { 00304 //=============================================================== 00305 // Set Transparency 00306 glPushAttrib( GL_ENABLE_BIT | GL_LIGHTING ); 00307 //----------------------------------------------------------- 00308 glEnable( GL_BLEND ); 00309 glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); 00310 //glBlendFunc( GL_DST_ALPHA, GL_DST_ALPHA ); 00311 //glBlendFunc( GL_SRC_ALPHA, GL_SRC_ALPHA ); 00312 //----------------------------------------------------------- 00313 //TS.TransformByOpenGLForDrawing(); 00314 //----------------------------------------------------------- 00315 // Draw Bounding Volume 00316 TAPs::OpenGL::Material matBV( 00317 0.25f, 0.35f, 0.25f, 0.5f, // Ambient 00318 0.25f, 0.35f, 0.30f, 0.5f, // Diffuse 00319 0.25f, 0.25f, 0.35f, 0.5f, // Specular 00320 100.0f, // Shininess 00321 0.0f, 0.0f, 0.0f, 0.0f ); // Emission 00322 matBV.ApplyMaterial(); 00323 //-------------------------------------------------------- 00324 glPushMatrix(); 00325 //--------------------------------------- 00326 GetTransform().TransformByOpenGLForDrawing(); 00327 //--------------------------------------- 00328 std::vector< BoundingVolume<T> * >::const_iterator pos = 00329 m_vBoundingVolumePtrList.begin(); 00330 while ( pos != m_vBoundingVolumePtrList.end() ) { 00331 assert( *pos != NULL ); 00332 (*pos)->DrawByOpenGL( drawStyle, color ); 00333 ++pos; 00334 } 00335 glPopMatrix(); 00336 //-------------------------------------------------------- 00337 glPopAttrib(); 00338 } 00339 //----------------------------------------------------------------------------- 00340 #endif 00341 //============================================================================= 00342 END_NAMESPACE_TAPs 00343 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00344 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----