BsLineSegment3.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector3.h"
  6. namespace bs
  7. {
  8. /** @addtogroup Math
  9. * @{
  10. */
  11. /** Represents a line segment in three dimensional space defined by a start and an end point. */
  12. class BS_UTILITY_EXPORT LineSegment3
  13. {
  14. public:
  15. LineSegment3();
  16. LineSegment3(const Vector3& start, const Vector3& end);
  17. /**
  18. * Find the nearest point on the line segment and the provided ray.
  19. *
  20. * @return Set of nearest points and distance from the points. First nearest point is a point along the ray,
  21. * while the second is along the line segment.
  22. *
  23. * @note If segment and ray are parallel the set of points at the segment origin are returned.
  24. */
  25. std::pair<std::array<Vector3, 2>, float> getNearestPoint(const Ray& ray) const;
  26. /** Returns the starting point of the line segment. */
  27. const Vector3& getStart() const { return mStart; }
  28. /** Returns the ending point of the line segment. */
  29. const Vector3& getEnd() const { return mEnd; }
  30. /** Returns the length of the line segment. */
  31. float getLength() const { return mStart.distance(mEnd); }
  32. /** Returns the center point along the line segment. */
  33. Vector3 getCenter() const { return mStart + (mEnd - mStart) * 0.5f; }
  34. private:
  35. Vector3 mStart, mEnd;
  36. };
  37. /** @} */
  38. }