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