BsCapsule.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 "Prerequisites/BsPrerequisitesUtil.h"
  5. #include "Math/BsVector3.h"
  6. #include "Math/BsLineSegment3.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Math
  10. * @{
  11. */
  12. /** Represents a capsule with a line segment and a radius. */
  13. class BS_UTILITY_EXPORT Capsule
  14. {
  15. public:
  16. Capsule();
  17. Capsule(const LineSegment3& segment, float radius);
  18. /**
  19. * Ray/capsule intersection.
  20. *
  21. * @return Boolean result and distance to the nearest intersection point.
  22. */
  23. std::pair<bool, float> intersects(const Ray& ray) const;
  24. /**
  25. * Returns the line segment along which the capsule lies. All capsule points are at equal distance from this
  26. * segment.
  27. */
  28. const LineSegment3& getSegment() const { return mSegment; }
  29. /** Returns the radius of the capsule. It defines the distance of the capsule from its line segment. */
  30. float getRadius() const { return mRadius; }
  31. /**
  32. * Returns the height of the capsule. The height is the distance between centers of the hemispheres that form the
  33. * capsule's ends.
  34. */
  35. float getHeight() const { return mSegment.getLength(); }
  36. /** Returns the center point of the capsule. */
  37. Vector3 getCenter() const { return mSegment.getCenter(); }
  38. private:
  39. LineSegment3 mSegment;
  40. float mRadius;
  41. };
  42. /** @} */
  43. }