BsLine2.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "BsVector2.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Math
  9. * @{
  10. */
  11. /** A line in 2D space represented with an origin and direction. */
  12. class BS_UTILITY_EXPORT Line2
  13. {
  14. public:
  15. Line2()
  16. :mOrigin(Vector2::ZERO), mDirection(Vector2::UNIT_X)
  17. { }
  18. Line2(const Vector2& origin, const Vector2& direction)
  19. :mOrigin(origin), mDirection(direction)
  20. { }
  21. void setOrigin(const Vector2& origin) { mOrigin = origin; }
  22. const Vector2& getOrigin(void) const { return mOrigin; }
  23. void setDirection(const Vector2& dir) { mDirection = dir; }
  24. const Vector2& getDirection(void) const {return mDirection;}
  25. /** Gets the position of a point t units along the line. */
  26. Vector2 getPoint(float t) const
  27. {
  28. return Vector2(mOrigin + (mDirection * t));
  29. }
  30. /** Gets the position of a point t units along the line. */
  31. Vector2 operator*(float t) const
  32. {
  33. return getPoint(t);
  34. }
  35. /** Line/Line intersection, returns boolean result and distance to intersection point. */
  36. std::pair<bool, float> intersects(const Line2& line) const;
  37. protected:
  38. Vector2 mOrigin;
  39. Vector2 mDirection;
  40. };
  41. /** @} */
  42. }