BsRect3.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsVector3.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Represents a rectangle in three dimensional space. It is represented
  8. * by two axes that extend from the specified origin. Axes should be perpendicular
  9. * to each other and they extend in both positive and negative directions from the
  10. * origin by the amount specified by extents.
  11. */
  12. class BS_UTILITY_EXPORT Rect3
  13. {
  14. public:
  15. Rect3();
  16. Rect3(const Vector3& center, const std::array<Vector3, 2>& axes,
  17. const std::array<float, 2>& extents);
  18. /**
  19. * @brief Find the nearest points of the provided ray and the rectangle.
  20. *
  21. * @return A set of nearest points and nearest distance.
  22. * First value in the set corresponds to nearest point on the ray, and the second to the nearest point on the rectangle.
  23. * They are same in the case of intersection. When ray is parallel to the rectangle there are two sets of nearest points
  24. * but only one the set nearest to the ray origin is returned.
  25. */
  26. std::pair<std::array<Vector3, 2>, float> getNearestPoint(const Ray& ray) const;
  27. /**
  28. * @brief Find the nearest point on the rectangle to the provided point.
  29. *
  30. * @return Nearest point and distance to nearest point.
  31. */
  32. std::pair<Vector3, float> getNearestPoint(const Vector3& point) const;
  33. /**
  34. * @brief Ray/rectangle intersection.
  35. *
  36. * @return Boolean result and distance to intersection point.
  37. */
  38. std::pair<bool, float> intersects(const Ray& ray) const;
  39. /**
  40. * @brief Gets the origin of the rectangle.
  41. */
  42. const Vector3& getCenter() const { return mCenter; }
  43. /**
  44. * @brief Returns the rectangle's horizontal axis.
  45. */
  46. const Vector3& getAxisHorz() const { return mAxisHorz; }
  47. /**
  48. * @brief Returns the rectangle's vertical axis.
  49. */
  50. const Vector3& getAxisVert() const { return mAxisVert; }
  51. /**
  52. * @brief Gets the extent of the rectangle along its horizontal axis.
  53. */
  54. const float& getExtentHorz() const { return mExtentHorz; }
  55. /**
  56. * @brief Gets the extent of the rectangle along its vertical axis.
  57. */
  58. const float& getExtentVertical() const { return mExtentVert; }
  59. private:
  60. Vector3 mCenter;
  61. Vector3 mAxisHorz;
  62. Vector3 mAxisVert;
  63. float mExtentHorz;
  64. float mExtentVert;
  65. };
  66. }