CmAABox.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "CmPrerequisitesUtil.h"
  3. #include "CmVector3.h"
  4. #include "CmMatrix4.h"
  5. namespace CamelotFramework
  6. {
  7. class CM_UTILITY_EXPORT AABox
  8. {
  9. public:
  10. /*
  11. 1-----2
  12. /| /|
  13. / | / |
  14. 5-----4 |
  15. | 0--|--3
  16. | / | /
  17. |/ |/
  18. 6-----7
  19. */
  20. typedef enum CornerEnum {
  21. FAR_LEFT_BOTTOM = 0,
  22. FAR_LEFT_TOP = 1,
  23. FAR_RIGHT_TOP = 2,
  24. FAR_RIGHT_BOTTOM = 3,
  25. NEAR_RIGHT_BOTTOM = 7,
  26. NEAR_LEFT_BOTTOM = 6,
  27. NEAR_LEFT_TOP = 5,
  28. NEAR_RIGHT_TOP = 4
  29. };
  30. AABox();
  31. AABox(const AABox& copy);
  32. AABox(const Vector3& min, const Vector3& max);
  33. AABox& operator=(const AABox& rhs);
  34. ~AABox() { }
  35. const Vector3& getMin() const { return mMinimum; }
  36. const Vector3& getMax() const { return mMaximum; }
  37. void setMin(const Vector3& vec) { mMinimum = vec; }
  38. void setMax(const Vector3& vec) { mMaximum = vec; }
  39. void setExtents(const Vector3& min, const Vector3& max);
  40. void scale(const Vector3& s);
  41. Vector3 getCorner(CornerEnum cornerToGet) const;
  42. void merge(const AABox& rhs);
  43. void merge(const Vector3& point);
  44. void transform(const Matrix4& matrix);
  45. void transformAffine(const Matrix4& matrix);
  46. AABox intersection(const AABox& b2) const;
  47. bool intersects(const AABox& b2) const;
  48. bool intersects(const Sphere& s) const;
  49. bool intersects(const Plane& p) const;
  50. bool intersects(const Vector3& v) const;
  51. /**
  52. * @brief Ray / box intersection, returns boolean result and distance.
  53. */
  54. std::pair<bool, float> intersects(const Ray& ray) const;
  55. /**
  56. * @brief Ray / box intersection, returns boolean result and near and far intersection distance.
  57. */
  58. bool intersects(const Ray& ray, float& d1, float& d2) const;
  59. Vector3 getCenter() const;
  60. Vector3 getSize() const;
  61. Vector3 getHalfSize() const;
  62. float getRadius() const;
  63. float getVolume() const;
  64. bool contains(const Vector3& v) const;
  65. bool contains(const AABox& other) const;
  66. bool operator== (const AABox& rhs) const;
  67. bool operator!= (const AABox& rhs) const;
  68. static const AABox BOX_EMPTY;
  69. protected:
  70. Vector3 mMinimum;
  71. Vector3 mMaximum;
  72. };
  73. }