BsRect3.h 2.3 KB

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