![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsBoundingCylinder.hpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (08/22/2006) 00009 UPDATE (12/30/2010) 00010 ******************************************************************************/ 00011 #include "TAPsBoundingCylinder.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 // Constructor(s) and Destructor 00019 //----------------------------------------------------------------------------- 00020 template <typename T> 00021 BoundingCylinder<T>::BoundingCylinder () 00022 : BoundingVolume<T>( Enum::BOUNDING_CYLINDER ), 00023 m_tRadius( 1 ), 00024 m_tHeight( 1 ) 00025 {} 00026 //----------------------------------------------------------------------------- 00027 template <typename T> 00028 BoundingCylinder<T>::BoundingCylinder ( int id ) 00029 : BoundingVolume<T>( Enum::BOUNDING_CYLINDER, id ), 00030 m_tRadius( 1 ), 00031 m_tHeight( 1 ) 00032 {} 00033 //----------------------------------------------------------------------------- 00034 template <typename T> 00035 BoundingCylinder<T>::BoundingCylinder ( BoundingCylinder<T> const & orig ) 00036 : BoundingVolume<T>( orig ), 00037 m_tRadius( orig.m_tRadius ), 00038 m_tHeight( orig.m_tHeight ) 00039 { 00040 m_vCenter = orig.m_vCenter; 00041 } 00042 //----------------------------------------------------------------------------- 00043 template <typename T> 00044 BoundingCylinder<T>::~BoundingCylinder () 00045 {} 00046 //----------------------------------------------------------------------------- 00047 // Return this object info as a string 00048 template <typename T> 00049 std::string BoundingCylinder<T>::StrInfo () const 00050 { 00051 std::string str = BoundingVolume<T>::StrInfo(); 00052 std::ostringstream ss; 00053 ss << "\n Radius: " << m_tRadius; 00054 ss << "\n Height: " << m_tHeight; 00055 return str + ss.str() + "\n"; 00056 } 00057 //----------------------------------------------------------------------------- 00058 // Assignment Operator 00059 template <typename T> 00060 inline TAPs::BoundingCylinder<T> & TAPs::BoundingCylinder<T>::operator= ( 00061 TAPs::BoundingCylinder<T> const & orig ) 00062 { 00063 if ( this != &orig ) { 00064 m_vCenter = orig.m_vCenter; 00065 m_tRadius = orig.m_tRadius; 00066 m_tHeight = orig.m_tHeight; 00067 } 00068 return *this; 00069 } 00070 //----------------------------------------------------------------------------- 00071 //----------------------------------------------------------------------------- 00072 // virtual void TransformByTranslationRatationAndScale (); 00073 //template <typename T> 00074 //void BoundingCylinder<T>::TransformByTranslationRatationAndScale () 00075 //{} 00076 //----------------------------------------------------------------------------- 00077 template <typename T> 00078 void BoundingCylinder<T>::ScaledBy ( T val ) 00079 { 00080 assert( 0.0 <= val ); 00081 GetTransform().PreApplyUniformScale( val ); 00082 } 00083 //----------------------------------------------------------------------------- 00084 //============================================================================= 00085 // Operations 00086 //----------------------------------------------------------------------------- 00087 template <typename T> 00088 bool BoundingCylinder<T>::TestPointLocation ( 00089 Vector3<T> const & point, 00090 Vector3<T> * const pvDistance ) const 00091 { 00092 bool isThePointInsideTheCylinder = false; 00093 //--------------------------------------------------------------- 00094 // In the local coordinate of the bounding cylinder, 00095 // the cylinder axis is parallel to z-axis 00096 // where it is shifted by the cylinder center. 00097 // The cylinder has radius, height and center. 00098 // Its height is measured from -z and +z axis 00099 // where its center is situated between height/2 in -z and +z axis. 00100 //--------------------------------------------------------------- 00101 // Transform point to the cylinder BV local coordinate 00102 Vector3<T> location = point; 00103 location = (GetTransform().GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3(); 00104 // Shift the location of point by the cylinder BV center 00105 // i.e. shift the cylinder BV to the origin (0,0,0) 00106 location -= GetCenter(); 00107 //--------------------------------------------------------------- 00108 // Now the cylinder BV is centered at the origin with its axis on the z-axis 00109 // where its height is from -height/2 to +height/2. 00110 // And the input point has been transformed into the cylinder coordinate. 00111 // The test can be performed below 00112 T halfHeight = GetHeight()/2.0; 00113 T ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] ); 00114 //=============================================================== 00115 // If the point is INSIDE the cylinder 00116 //--------------------------------------------------------------- 00117 // If the point is within the cylinder radius 00118 if ( ptRadius <= GetRadius() ) { 00119 // If the point is within the cylinder height 00120 if ( -halfHeight <= location[2] && location[2] <= halfHeight ) { 00121 // Find the shortest distance vector from the point to the surface 00122 // of the cylinder 00123 if ( pvDistance ) { 00124 T difRadius = GetRadius() - ptRadius; 00125 T difHeight = halfHeight - fabs( location[2] ); 00126 if ( difRadius <= difHeight ) { 00127 // If the point is on the z-axis (degenerate case) 00128 if ( difRadius >= GetRadius() ) { 00129 (*pvDistance).SetXYZ( 0, GetRadius(), 0 ); 00130 } 00131 // If the point is NOT on the z-axis 00132 else { 00133 Vector2<T> difDirection = Vector2<T>( location[0], location[1] ); 00134 difDirection.Normalized(); 00135 difDirection *= difRadius; 00136 (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 ); 00137 } 00138 } 00139 else { 00140 (*pvDistance).SetXYZ( 0, 0, location[2] >= 0 ? difHeight : -difHeight ); 00141 } 00142 //------------------------- 00143 // Now rotate it back by the rotation matrix (from the transform matrix). 00144 // REMARK: Translation (from the transform matrix) is NOT applied back, 00145 // because pvDistance represents a displacement vector from 00146 // the input point to the cylinder surface. 00147 (*pvDistance) = GetTransform().GetMatrixRotation() * (*pvDistance); 00148 } 00149 //------------------------- 00150 isThePointInsideTheCylinder = true; 00151 } 00152 } 00153 //=============================================================== 00154 // If the point is NOT INSIDE the cylinder radius 00155 //--------------------------------------------------------------- 00156 else { 00157 if ( pvDistance ) { 00158 (*pvDistance).SetXYZ( 0, 0, 0 ); 00159 } 00160 } 00161 //--------------------------------------------------------------- 00162 return isThePointInsideTheCylinder; 00163 } 00164 //----------------------------------------------------------------------------- 00165 template <typename T> 00166 bool BoundingCylinder<T>::TestPointLocation ( 00167 Vector3<T> const & point, 00168 TransformationSupport<T> const * const pTransform, 00169 Vector3<T> * const pvDistance ) const 00170 { 00171 bool isThePointInsideTheCylinder = false; 00172 //--------------------------------------------------------------- 00173 TransformationSupport<T> transform; // default ctor is an identity 00174 //Matrix4x4<T> pureRotation; 00175 //pureRotation *= pTransform->GetMatrixRotation(); 00176 transform.RefToMatrixTransform() *= pTransform->GetMatrixTransform(); 00177 // The above statement is equivalent to the below statement 00178 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * pTransform->GetMatrixTransform(); 00179 //pureRotation *= GetTransform().GetMatrixRotation(); 00180 transform.RefToMatrixTransform() *= GetTransform().GetMatrixTransform(); 00181 // The above statement is equivalent to the below statement 00182 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * GetTransform().GetMatrixTransform(); 00183 //--------------------------------------------------------------- 00184 // In the local coordinate of the bounding cylinder, 00185 // the cylinder axis is parallel to z-axis 00186 // where it is shifted by the cylinder center. 00187 // The cylinder has radius, height and center. 00188 // Its height is measured from -z and +z axis 00189 // where its center is situated between height/2 in -z and +z axis. 00190 //--------------------------------------------------------------- 00191 // Transform point to the cylinder local coordinate 00192 Vector3<T> location = point; 00193 //location -= transform.GetTranslation(); 00194 //location = transform.GetMatrixRotation().GetInverse() * location; 00195 location = (transform.GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3(); 00196 // Shift the location of point by the cylinder center 00197 // i.e. shift the cylinder to the origin (0,0,0) 00198 location -= GetCenter(); 00199 //--------------------------------------------------------------- 00200 // Now the cylinder is centered at the origin with its axis on the z-axis 00201 // where its height is from -height/2 to +height/2. 00202 // And the input point has been transformed into the cylinder coordinate. 00203 // The test can be performed below 00204 T halfHeight = GetHeight()/2.0; 00205 T ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] ); 00206 //=============================================================== 00207 // If the point is INSIDE the cylinder 00208 //--------------------------------------------------------------- 00209 // If the point is within the cylinder radius 00210 if ( ptRadius <= GetRadius() ) { 00211 // If the point is within the cylinder height 00212 if ( -halfHeight <= location[2] && location[2] <= halfHeight ) { 00213 // Find the shortest distance vector from the point to the surface 00214 // of the cylinder 00215 if ( pvDistance ) { 00216 //(*pvDistance).SetXYZ( 0, 0, 0 ); 00217 T difRadius = GetRadius() - ptRadius; 00218 T difHeight = halfHeight - fabs( location[2] ); 00219 if ( difRadius <= difHeight ) { 00220 // If the point is on the z-axis (degenerate case) 00221 if ( difRadius >= GetRadius() ) { 00222 (*pvDistance).SetXYZ( 0, GetRadius(), 0 ); 00223 } 00224 // If the point is NOT on the z-axis 00225 else { 00226 Vector2<T> difDirection = Vector2<T>( location[0], location[1] ); 00227 difDirection.Normalized(); 00228 difDirection *= difRadius; 00229 (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 ); 00230 } 00231 } 00232 else { 00233 (*pvDistance).SetXYZ( 0, 0, location[2] >= 0 ? difHeight : -difHeight ); 00234 } 00235 //------------------------- 00236 // Now rotate it back by the rotation matrix (from the transform matrix). 00237 // REMARK: Translation (from the transform matrix) is NOT applied back, 00238 // because pvDistance represents a displacement vector from 00239 // the input point to the cylinder surface. 00240 (*pvDistance) = transform.GetMatrixRotation() * (*pvDistance); 00241 //(*pvDistance) = pureRotation * (*pvDistance); 00242 } 00243 //------------------------- 00244 isThePointInsideTheCylinder = true; 00245 } 00246 } 00247 //=============================================================== 00248 // If the point is NOT INSIDE the cylinder radius 00249 //--------------------------------------------------------------- 00250 else { 00251 if ( pvDistance ) { 00252 (*pvDistance).SetXYZ( 0, 0, 0 ); 00253 } 00254 } 00255 //--------------------------------------------------------------- 00256 return isThePointInsideTheCylinder; 00257 } 00258 //----------------------------------------------------------------------------- 00259 template <typename T> 00260 bool BoundingCylinder<T>::TestSphereLocation ( 00261 Vector3<T> const & sphereCenter, 00262 T sphereRadius, 00263 Vector3<T> * const pvDistance ) const 00264 { 00265 bool isThePointInsideTheCylinder = false; 00266 //--------------------------------------------------------------- 00267 // In the local coordinate of the bounding cylinder, 00268 // the cylinder axis is parallel to z-axis 00269 // where it is shifted by the cylinder center. 00270 // The cylinder has radius, height and center. 00271 // Its height is measured from -z and +z axis 00272 // where its center is situated between height/2 in -z and +z axis. 00273 //--------------------------------------------------------------- 00274 // Transform the sphere center to the cylinder BV local coordinate 00275 Vector3<T> location = sphereCenter; 00276 location = (GetTransform().GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3(); 00277 // Shift the location of sphere center by the cylinder BV center 00278 // i.e. shift the cylinder BV to the origin (0,0,0) 00279 location -= GetCenter(); 00280 //--------------------------------------------------------------- 00281 // Now the cylinder BV is centered at the origin with its axis on the z-axis 00282 // where its height is from -height/2 to +height/2. 00283 // And the input sphere center has been transformed into the cylinder coordinate. 00284 // The test can be performed below 00285 T halfHeight = GetHeight()/2.0; 00286 T ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] ) - sphereRadius; 00287 //=============================================================== 00288 // If the point is INSIDE the cylinder 00289 //--------------------------------------------------------------- 00290 // If the point is within the cylinder radius 00291 if ( ptRadius <= GetRadius() ) { 00292 // If the point is within the cylinder height 00293 if ( -halfHeight <= location[2] && location[2] <= halfHeight ) { 00294 // Find the shortest distance vector from the point to the surface 00295 // of the cylinder 00296 if ( pvDistance ) { 00297 T difRadius = GetRadius() - ptRadius; 00298 T difHeight = halfHeight - fabs( location[2] - sphereRadius ); 00299 if ( difRadius <= difHeight ) { 00300 // If the point is on the z-axis (degenerate case) 00301 if ( difRadius >= GetRadius() ) { 00302 (*pvDistance).SetXYZ( 0, GetRadius(), 0 ); 00303 } 00304 // If the point is NOT on the z-axis 00305 else { 00306 Vector2<T> difDirection = Vector2<T>( location[0], location[1] ); 00307 difDirection.Normalized(); 00308 difDirection *= difRadius; 00309 (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 ); 00310 } 00311 } 00312 else { 00313 (*pvDistance).SetXYZ( 0, 0, location[2] + sphereRadius >= 0 ? difHeight + sphereRadius : -difHeight - sphereRadius ); 00314 } 00315 //------------------------- 00316 // Now rotate it back by the rotation matrix (from the transform matrix). 00317 // REMARK: Translation (from the transform matrix) is NOT applied back, 00318 // because pvDistance represents a displacement vector from 00319 // the input point to the cylinder surface. 00320 (*pvDistance) = GetTransform().GetMatrixRotation() * (*pvDistance); 00321 } 00322 //------------------------- 00323 isThePointInsideTheCylinder = true; 00324 } 00325 } 00326 //=============================================================== 00327 // If the point is NOT INSIDE the cylinder radius 00328 //--------------------------------------------------------------- 00329 else { 00330 if ( pvDistance ) { 00331 (*pvDistance).SetXYZ( 0, 0, 0 ); 00332 } 00333 } 00334 //--------------------------------------------------------------- 00335 return isThePointInsideTheCylinder; 00336 } 00337 //----------------------------------------------------------------------------- 00338 template <typename T> 00339 bool BoundingCylinder<T>::TestSphereLocation ( 00340 Vector3<T> const & sphereCenter, 00341 T sphereRadius, 00342 TransformationSupport<T> const * const pTransform, 00343 Vector3<T> * const pvDistance ) const 00344 { 00345 bool isThePointInsideTheCylinder = false; 00346 //--------------------------------------------------------------- 00347 TransformationSupport<T> transform; // default ctor is an identity 00348 //Matrix4x4<T> pureRotation; 00349 //pureRotation *= pTransform->GetMatrixRotation(); 00350 transform.RefToMatrixTransform() *= pTransform->GetMatrixTransform(); 00351 // The above statement is equivalent to the below statement 00352 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * pTransform->GetMatrixTransform(); 00353 //pureRotation *= GetTransform().GetMatrixRotation(); 00354 transform.RefToMatrixTransform() *= GetTransform().GetMatrixTransform(); 00355 // The above statement is equivalent to the below statement 00356 //transform.ReturnMatrixTransform() = transform.GetMatrixTransform() * GetTransform().GetMatrixTransform(); 00357 //--------------------------------------------------------------- 00358 // In the local coordinate of the bounding cylinder, 00359 // the cylinder axis is parallel to z-axis 00360 // where it is shifted by the cylinder center. 00361 // The cylinder has radius, height and center. 00362 // Its height is measured from -z and +z axis 00363 // where its center is situated between height/2 in -z and +z axis. 00364 //--------------------------------------------------------------- 00365 // Transform the sphere center to the cylinder local coordinate 00366 Vector3<T> location = sphereCenter; 00367 location = (transform.GetMatrixTransform().GetInverse() * Vector4<T>( location )).GetVector3(); 00368 // Shift the location of sphere center by the cylinder center 00369 // i.e. shift the cylinder to the origin (0,0,0) 00370 location -= GetCenter(); 00371 //--------------------------------------------------------------- 00372 // Now the cylinder is centered at the origin with its axis on the z-axis 00373 // where its height is from -height/2 to +height/2. 00374 // And the input sphere center has been transformed into the cylinder coordinate. 00375 // The test can be performed below 00376 T halfHeight = GetHeight()/2.0; 00377 T ptRadius = sqrt( location[0]*location[0] + location[1]*location[1] ) - sphereRadius; 00378 //=============================================================== 00379 // If the point is INSIDE the cylinder 00380 //--------------------------------------------------------------- 00381 // If the point is within the cylinder radius 00382 if ( ptRadius <= GetRadius() ) { 00383 // If the point is within the cylinder height 00384 if ( -halfHeight <= location[2] && location[2] <= halfHeight ) { 00385 // Find the shortest distance vector from the point to the surface 00386 // of the cylinder 00387 if ( pvDistance ) { 00388 //(*pvDistance).SetXYZ( 0, 0, 0 ); 00389 T difRadius = GetRadius() - ptRadius; 00390 T difHeight = halfHeight - fabs( location[2] ); 00391 if ( difRadius <= difHeight ) { 00392 // If the point is on the z-axis (degenerate case) 00393 if ( difRadius >= GetRadius() ) { 00394 (*pvDistance).SetXYZ( 0, GetRadius(), 0 ); 00395 } 00396 // If the point is NOT on the z-axis 00397 else { 00398 Vector2<T> difDirection = Vector2<T>( location[0], location[1] ); 00399 difDirection.Normalized(); 00400 difDirection *= difRadius; 00401 (*pvDistance).SetXYZ( difDirection[0], difDirection[1], 0 ); 00402 } 00403 } 00404 else { 00405 (*pvDistance).SetXYZ( 0, 0, location[2] + sphereRadius >= 0 ? difHeight + sphereRadius : -difHeight - sphereRadius ); 00406 } 00407 //------------------------- 00408 // Now rotate it back by the rotation matrix (from the transform matrix). 00409 // REMARK: Translation (from the transform matrix) is NOT applied back, 00410 // because pvDistance represents a displacement vector from 00411 // the input point to the cylinder surface. 00412 (*pvDistance) = transform.GetMatrixRotation() * (*pvDistance); 00413 //(*pvDistance) = pureRotation * (*pvDistance); 00414 } 00415 //------------------------- 00416 isThePointInsideTheCylinder = true; 00417 } 00418 } 00419 //=============================================================== 00420 // If the point is NOT INSIDE the cylinder radius 00421 //--------------------------------------------------------------- 00422 else { 00423 if ( pvDistance ) { 00424 (*pvDistance).SetXYZ( 0, 0, 0 ); 00425 } 00426 } 00427 //--------------------------------------------------------------- 00428 return isThePointInsideTheCylinder; 00429 } 00430 //----------------------------------------------------------------------------- 00431 // TestOverlapWith 00432 template <typename T> 00433 T BoundingCylinder<T>::TestOverlapWith ( BoundingVolume<T> const * const that ) const 00434 { 00435 std::cout << "BoundingCylinder<T>::TestOverlapWith( BoundingVolume<T> ) -- NOT IMPLEMENTED YET!!!\n"; 00436 00437 switch ( that->GetType() ) { 00438 case Enum::BOUNDING_CYLINDER: 00439 break; 00440 case Enum::BOUNDING_SPHERE: 00441 break; 00442 case Enum::BOUNDING_BOX: 00443 break; 00444 } 00445 00446 return 0; 00447 } 00448 /* 00449 //----------------------------------------------------------------------------- 00450 // TestOverlapWith 00451 template <typename T> 00452 T BVHNode<T>::TestOverlapWith ( BVHNode<T> const * const that ) const 00453 { 00454 switch ( m_eType ) { 00455 case Enum::BVH_NODE_BINARY_SPHERE: 00456 case Enum::BVH_NODE_QUAD_SPHERE: 00457 case Enum::BVH_NODE_OCTANT_SPHERE: 00458 case Enum::BVH_NODE_GENERIC_SPHERE: 00459 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00460 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00461 switch ( that->m_eType ) { 00462 case Enum::BVH_NODE_BINARY_SPHERE: 00463 case Enum::BVH_NODE_QUAD_SPHERE: 00464 case Enum::BVH_NODE_OCTANT_SPHERE: 00465 case Enum::BVH_NODE_GENERIC_SPHERE: 00466 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00467 return ( GetCenter() - that->GetCenter() ).Length() 00468 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00469 break; 00470 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00471 return ( GetCenter() - that->GetCenter() ).Length() 00472 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00473 break; 00474 default: 00475 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00476 assert( false ); 00477 break; 00478 } 00479 break; 00480 default: 00481 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00482 assert( false ); 00483 break; 00484 } 00485 return -777; // -777 is an Error Code 00486 } 00487 //*/ 00488 /* 00489 //----------------------------------------------------------------------------- 00490 // TestOverlapWithTillLeafNodes 00491 template <typename T> 00492 T BVHNode<T>::TestOverlapWithTillLeafNodes ( BVHNode<T> const * const that ) const 00493 { 00494 switch ( m_eType ) { 00495 case Enum::BVH_NODE_BINARY_SPHERE: 00496 case Enum::BVH_NODE_QUAD_SPHERE: 00497 case Enum::BVH_NODE_OCTANT_SPHERE: 00498 case Enum::BVH_NODE_GENERIC_SPHERE: 00499 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00500 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00501 switch ( that->m_eType ) { 00502 case Enum::BVH_NODE_BINARY_SPHERE: 00503 case Enum::BVH_NODE_QUAD_SPHERE: 00504 case Enum::BVH_NODE_OCTANT_SPHERE: 00505 case Enum::BVH_NODE_GENERIC_SPHERE: 00506 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_APRIM: 00507 return ( GetCenter() - that->GetCenter() ).Length() 00508 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00509 break; 00510 case Enum::BVH_NODE_LEAF_SPHERE_HALFEDGE_PRIMS: 00511 return ( GetCenter() - that->GetCenter() ).Length() 00512 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00513 break; 00514 default: 00515 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00516 assert( false ); 00517 break; 00518 } 00519 break; 00520 default: 00521 std::cout << "Error: BVHNode<T>::TestOverlapWith Fn!" << std::endl; 00522 assert( false ); 00523 break; 00524 } 00525 return -777; // -777 is an Error Code 00526 } 00527 //*/ 00528 /* 00529 //----------------------------------------------------------------------------- 00530 // TestOverlapSphereWithSphere #1 00531 template <typename T> 00532 T BVHNode<T>::TestOverlapSphereWithSphere ( BVHNode<T> const * const that ) const 00533 { 00534 return ( GetCenter() - that->GetCenter() ).Length() 00535 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00536 } 00537 //----------------------------------------------------------------------------- 00538 // TestOverlapSphereWithSphere #2 00539 template <typename T> 00540 T BVHNode<T>::TestOverlapSphereWithSphere ( 00541 BVHNode<T> const * const that, 00542 Matrix4x4<T> const & thatTransform ) const 00543 { 00544 return ( GetCenter() 00545 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00546 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00547 } 00548 //----------------------------------------------------------------------------- 00549 // TestOverlapSphereWithSphere #3 00550 template <typename T> 00551 T BVHNode<T>::TestOverlapSphereWithSphere ( 00552 Matrix4x4<T> const & thisTransform, 00553 BVHNode<T> const * const that ) const 00554 { 00555 return ( (thisTransform*GetCenter()).GetVector3() 00556 - that->GetCenter() ).Length() 00557 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00558 } 00559 //----------------------------------------------------------------------------- 00560 // TestOverlapSphereWithSphere #4 00561 template <typename T> 00562 T BVHNode<T>::TestOverlapSphereWithSphere ( 00563 Matrix4x4<T> const & thisTransform, 00564 BVHNode<T> const * const that, 00565 Matrix4x4<T> const & thatTransform ) const 00566 { 00567 return ( (thisTransform*GetCenter()).GetVector3() 00568 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00569 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00570 } 00571 //----------------------------------------------------------------------------- 00572 // TestOverlapSphereWithSphereTillLeafNodes #1 00573 template <typename T> 00574 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( BVHNode<T> const * const that ) const 00575 { 00576 return ( GetCenter() - that->GetCenter() ).Length() 00577 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00578 } 00579 //----------------------------------------------------------------------------- 00580 // TestOverlapSphereWithSphereTillLeafNodes #2 00581 template <typename T> 00582 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00583 BVHNode<T> const * const that, 00584 Matrix4x4<T> const & thatTransform ) const 00585 { 00586 return ( GetCenter() 00587 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00588 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00589 } 00590 //----------------------------------------------------------------------------- 00591 // TestOverlapSphereWithSphereTillLeafNodes #3 00592 template <typename T> 00593 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00594 Matrix4x4<T> const & thisTransform, 00595 BVHNode<T> const * const that ) const 00596 { 00597 return ( (thisTransform*GetCenter()).GetVector3() 00598 - that->GetCenter() ).Length() 00599 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00600 } 00601 //----------------------------------------------------------------------------- 00602 // TestOverlapSphereWithSphereTillLeafNodes #4 00603 template <typename T> 00604 T BVHNode<T>::TestOverlapSphereWithSphereTillLeafNodes ( 00605 Matrix4x4<T> const & thisTransform, 00606 BVHNode<T> const * const that, 00607 Matrix4x4<T> const & thatTransform ) const 00608 { 00609 return ( (thisTransform*GetCenter()).GetVector3() 00610 - (thatTransform*that->GetCenter()).GetVector3() ).Length() 00611 - ( GetRadius() + that->GetRadius() ); // m_vW[0] is m_tRadius 00612 } 00613 //*/ 00614 //----------------------------------------------------------------------------- 00615 #if defined(__gl_h_) || defined(__GL_H__) 00616 //============================================================================= 00617 // DrawByOpenGL 00618 //----------------------------------------------------------------------------- 00619 template <typename T> GLuint BoundingCylinder<T>::g_uiDisplayList = 0; 00620 template <typename T> GLenum BoundingCylinder<T>::g_eDrawStyle = GLU_FILL; 00621 //----------------------------------------------------------------------------- 00622 template <typename T> 00623 void BoundingCylinder<T>::Draw ( GLenum drawStyle, Vector4<T> color ) 00624 { 00625 //----------------------------------------------------- 00626 //std::cout << "Draw CYLINDER Bounding Volume\n"; 00627 if ( drawStyle != g_eDrawStyle ) { 00628 g_eDrawStyle = drawStyle; 00629 if ( g_uiDisplayList ) { 00630 glDeleteLists( g_uiDisplayList, 1 ); 00631 g_uiDisplayList = 0; 00632 } 00633 } 00634 if ( !g_uiDisplayList ) { 00635 g_uiDisplayList = glGenLists( 1 ); 00636 GLUquadricObj *qObj = gluNewQuadric(); 00637 glNewList( g_uiDisplayList, GL_COMPILE ); 00638 // GLenum drawStyle 00639 // GLU_FILL 00640 // GLU_LINE 00641 // GLU_SILHOUETTE 00642 // GLU_POINT 00643 gluQuadricDrawStyle( qObj, drawStyle ); // wireframe 00644 //glPushMatrix(); 00645 //----------------------------------- 00646 //-------------------------- 00647 // Draw Center Point 00648 gluSphere( qObj, 0.02, 9, 9 ); 00649 //-------------------------- 00650 // Draw Axis Line 00651 glBegin( GL_LINES ); 00652 glVertex3f( 0, 0, -0.5 ); 00653 glVertex3f( 0, 0, 0.5 ); 00654 glEnd(); 00655 //-------------------------- 00656 // Draw Bottom Cap 00657 glTranslatef( 0.0, 0.0, -0.5 ); 00658 gluDisk( 00659 qObj, 00660 0, // Inner Radius 00661 1, // Outer Radius 00662 20, // #slices (#subdivisions around the z axis) 00663 10 // #loops (#concentric rings about the origin) 00664 ); 00665 //-------------------------- 00666 // Draw Cylinder 00667 gluCylinder( 00668 qObj, 00669 1, // Base Radius 00670 1, // Top Radius 00671 1, // Height 00672 20, // #slices 00673 1 // #stacks 00674 ); 00675 //-------------------------- 00676 glTranslatef( 0.0, 0.0, 1.0 ); 00677 // Draw Top Cap 00678 gluDisk( 00679 qObj, 00680 0, // Inner Radius 00681 1, // Outer Radius 00682 20, // #slices (#subdivisions around the z axis) 00683 10 // #loops (#concentric rings about the origin) 00684 ); 00685 //----------------------------------- 00686 //glPopMatrix(); 00687 glEndList(); 00688 gluDeleteQuadric( qObj ); 00689 } 00690 //----------------------------------------------------- 00691 glPushMatrix(); 00692 //--------------------------------------- 00693 GetTransform().TransformByOpenGLForDrawing(); 00694 //--------------------------------------- 00695 glColor4fv( color.GetDataFloat() ); 00696 glTranslatef( GetCenter()[0], GetCenter()[1], GetCenter()[2] ); 00697 glScalef( GetRadius(), GetRadius(), GetHeight() ); 00698 glCallList( g_uiDisplayList ); 00699 glPopMatrix(); 00700 } 00701 //----------------------------------------------------------------------------- 00702 #endif 00703 //============================================================================= 00704 END_NAMESPACE_TAPs 00705 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00706 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----