- Timestamp:
- 02/18/09 08:01:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
r3243 r3318 25 25 SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {} 26 26 27 Vector3 Extrap( constfloat t) const27 Vector3 Extrap(float t) const 28 28 { 29 29 return mOrigin + mDirection * t; … … 41 41 /** Axis alignedd box class. 42 42 This is a box in 3-space, defined by min and max 43 corner vectors. 43 corner vectors. Many useful operations are defined. 44 44 */ 45 45 class AxisAlignedBox3 … … 70 70 /** Computes the mid point in the given axis. 71 71 */ 72 float Center( constint axis) const;72 float Center(int axis) const; 73 73 /** The vertex of the box with the smallest values in all dimensions. 74 74 */ 75 float Min( constint axis) const;75 float Min(int axis) const; 76 76 /** The vertex of the box with the largest values in all dimensions. 77 77 */ 78 float Max( constint axis) const;78 float Max(int axis) const; 79 79 /** The extent of the box in the given axis. 80 80 */ 81 float Size( constint axis) const;81 float Size(int axis) const; 82 82 /** Returns axis where box has largest extent. 83 83 */ … … 138 138 /** Expand the axis-aligned box to include given values in particular axis. 139 139 */ 140 void Include( const int &axis, const float &newBound);140 void Include(int axis, float newBound); 141 141 /** Includes returns true if a includes b (completely) 142 142 */ … … 243 243 /** Returns the supporting plane of this face. 244 244 */ 245 Plane3 GetPlane( constint face) const;245 Plane3 GetPlane(int face) const; 246 246 /** Returns 247 247 0 if box intersects plane … … 358 358 359 359 360 // -------------------------------------------------------------------------- 361 // Implementation of inline (member) functions 360 361 ///////////////////////////////////////////////////////// 362 //-- Implementation of inline (member) functions 363 362 364 363 365 inline float AxisAlignedBox3::Radius() const … … 373 375 374 376 375 inline bool 376 Overlap(const AxisAlignedBox3 &x,const AxisAlignedBox3 &y)377 inline bool Overlap(const AxisAlignedBox3 &x, 378 const AxisAlignedBox3 &y) 377 379 { 378 380 if (x.mMax.x < y.mMin.x || … … 381 383 x.mMin.y > y.mMax.y || 382 384 x.mMax.z < y.mMin.z || 383 x.mMin.z > y.mMax.z) { 385 x.mMin.z > y.mMax.z) 386 { 384 387 return false; 385 388 } 389 386 390 return true; 387 391 } 388 392 389 inline bool 390 OverlapS(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 393 394 inline bool OverlapS(const AxisAlignedBox3 &x, 395 const AxisAlignedBox3 &y) 391 396 { 392 397 if (x.mMax.x <= y.mMin.x || … … 395 400 x.mMin.y >= y.mMax.y || 396 401 x.mMax.z <= y.mMin.z || 397 x.mMin.z >= y.mMax.z) { 402 x.mMin.z >= y.mMax.z) 403 { 398 404 return false; 399 405 } 406 400 407 return true; 401 408 } 402 409 403 inline bool 404 Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y, float eps) 405 { 406 if ( (x.mMax.x - eps) < y.mMin.x || 410 411 inline bool Overlap(const AxisAlignedBox3 &x, 412 const AxisAlignedBox3 &y, 413 float eps) 414 { 415 if ((x.mMax.x - eps) < y.mMin.x || 407 416 (x.mMin.x + eps) > y.mMax.x || 408 417 (x.mMax.y - eps) < y.mMin.y || 409 418 (x.mMin.y + eps) > y.mMax.y || 410 419 (x.mMax.z - eps) < y.mMin.z || 411 (x.mMin.z + eps) > y.mMax.z ) { 420 (x.mMin.z + eps) > y.mMax.z ) 421 { 412 422 return false; 413 423 } 424 414 425 return true; 415 426 } 416 427 417 inline AxisAlignedBox3 418 Intersect(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 419 { 420 if (x.Unbounded()) 428 429 inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x, 430 const AxisAlignedBox3 &y) 431 { 432 if (x.Unbounded()) 433 { 421 434 return y; 435 } 422 436 else 423 if (y.Unbounded()) 424 return x; 437 { 438 if (y.Unbounded()) return x; 439 } 440 425 441 AxisAlignedBox3 ret = x; 426 if (Overlap(ret, y)) { 442 443 if (Overlap(ret, y)) 444 { 427 445 Maximize(ret.mMin, y.mMin); 428 446 Minimize(ret.mMax, y.mMax); 447 429 448 return ret; 430 449 } 431 else // Null intersection. 450 else // Null intersection 451 { 432 452 return AxisAlignedBox3(Vector3(0), Vector3(0)); 433 // return AxisAlignedBox3(Vector3(0), Vector3(-1)); 434 } 435 436 inline AxisAlignedBox3 437 Union(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y) 453 } 454 } 455 456 457 inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x, 458 const AxisAlignedBox3 &y) 438 459 { 439 460 Vector3 min = x.mMin; 440 461 Vector3 max = x.mMax; 462 441 463 Minimize(min, y.mMin); 442 464 Maximize(max, y.mMax); 465 443 466 return AxisAlignedBox3(min, max); 444 467 } 445 468 446 inline AxisAlignedBox3 447 Transform(const AxisAlignedBox3 &box, const Matrix4x4 &tform) 448 { 449 Vector3 mmin(MAXFLOAT); 450 Vector3 mmax(-MAXFLOAT); 469 470 inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 471 const Matrix4x4 &tform) 472 { 473 const Vector3 mmin(MAXFLOAT); 474 const Vector3 mmax(-MAXFLOAT); 451 475 452 476 AxisAlignedBox3 ret(mmin, mmax); … … 464 488 } 465 489 466 inline float RatioOfOverlap(const AxisAlignedBox3 &box1, const AxisAlignedBox3 &box2) 490 491 inline float RatioOfOverlap(const AxisAlignedBox3 &box1, 492 const AxisAlignedBox3 &box2) 467 493 { 468 494 // return ratio of intersection to union … … 473 499 } 474 500 475 inline int operator==(const AxisAlignedBox3 &A, const AxisAlignedBox3 &B) 501 502 inline int operator==(const AxisAlignedBox3 &A, 503 const AxisAlignedBox3 &B) 476 504 { 477 505 return (A.mMin == B.mMin) && (A.mMax == B.mMax);
Note: See TracChangeset
for help on using the changeset viewer.