BoundingBox.pkg 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. $#include "BoundingBox.h"
  2. /// Three-dimensional axis-aligned bounding box.
  3. class BoundingBox
  4. {
  5. public:
  6. /// Construct with zero size.
  7. BoundingBox();
  8. /// Copy-construct from another bounding box.
  9. BoundingBox(const BoundingBox& box);
  10. /// Construct from a rect, with the Z dimension left zero.
  11. BoundingBox(const Rect& rect);
  12. /// Construct from minimum and maximum vectors.
  13. BoundingBox(const Vector3& min, const Vector3& max);
  14. /// Construct from minimum and maximum floats (all dimensions same.)
  15. BoundingBox(float min, float max);
  16. /// Construct from an array of vertices.
  17. BoundingBox(const Vector3* vertices, unsigned count);
  18. /// Construct from a frustum.
  19. BoundingBox(const Frustum& frustum);
  20. /// Construct from a polyhedron.
  21. BoundingBox(const Polyhedron& poly);
  22. /// Construct from a sphere.
  23. BoundingBox(const Sphere& sphere);
  24. /// Test for equality with another bounding box.
  25. bool operator == (const BoundingBox& rhs) const;
  26. /// Define from another bounding box.
  27. void Define(const BoundingBox& box);
  28. /// Define from a Rect.
  29. void Define(const Rect& rect);
  30. /// Define from minimum and maximum vectors.
  31. void Define(const Vector3& min, const Vector3& max);
  32. /// Define from minimum and maximum floats (all dimensions same.)
  33. void Define(float min, float max);
  34. /// Define from a point.
  35. void Define(const Vector3& point);
  36. /// Merge a point.
  37. void Merge(const Vector3& point);
  38. /// Merge another bounding box.
  39. void Merge(const BoundingBox& box);
  40. /// Define from an array of vertices.
  41. void Define(const Vector3* vertices, unsigned count);
  42. /// Define from a frustum.
  43. void Define(const Frustum& frustum);
  44. /// Define from a polyhedron.
  45. void Define(const Polyhedron& poly);
  46. /// Define from a sphere.
  47. void Define(const Sphere& sphere);
  48. /// Merge an array of vertices.
  49. void Merge(const Vector3* vertices, unsigned count);
  50. /// Merge a frustum.
  51. void Merge(const Frustum& frustum);
  52. /// Merge a polyhedron.
  53. void Merge(const Polyhedron& poly);
  54. /// Merge a sphere.
  55. void Merge(const Sphere& sphere);
  56. /// Clip with another bounding box.
  57. void Clip(const BoundingBox& box);
  58. /// Transform with a 3x3 matrix.
  59. void Transform(const Matrix3& transform);
  60. /// Transform with a 3x4 matrix.
  61. void Transform(const Matrix3x4& transform);
  62. /// Clear to undefined state.
  63. void Clear();
  64. /// Return center.
  65. Vector3 Center() const;
  66. /// Return size.
  67. Vector3 Size() const;
  68. /// Return half-size.
  69. Vector3 HalfSize() const;
  70. /// Return transformed by a 3x3 matrix.
  71. BoundingBox Transformed(const Matrix3& transform) const;
  72. /// Return transformed by a 3x4 matrix.
  73. BoundingBox Transformed(const Matrix3x4& transform) const;
  74. /// Return projected by a 4x4 projection matrix.
  75. Rect Projected(const Matrix4& projection) const;
  76. /// Test if a point is inside.
  77. Intersection IsInside(const Vector3& point) const;
  78. /// Test if another bounding box is inside, outside or intersects.
  79. Intersection IsInside(const BoundingBox& box) const;
  80. /// Test if another bounding box is (partially) inside or outside.
  81. Intersection IsInsideFast(const BoundingBox& box) const;
  82. /// Test if a sphere is inside, outside or intersects.
  83. Intersection IsInside(const Sphere& sphere) const;
  84. /// Test if a sphere is (partially) inside or outside.
  85. Intersection IsInsideFast(const Sphere& sphere) const;
  86. /// Minimum vector.
  87. Vector3 min_ @ min;
  88. /// Maximum vector.
  89. Vector3 max_ @ max;
  90. };