BsRect3.h 2.4 KB

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