CastResult.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Physics/Body/BodyID.h>
  6. #include <Jolt/Physics/Collision/Shape/SubShapeID.h>
  7. JPH_NAMESPACE_BEGIN
  8. /// Structure that holds a ray cast or other object cast hit
  9. class BroadPhaseCastResult
  10. {
  11. public:
  12. JPH_OVERRIDE_NEW_DELETE
  13. /// Function required by the CollisionCollector. A smaller fraction is considered to be a 'better hit'. For rays/cast shapes we can just use the collision fraction.
  14. inline float GetEarlyOutFraction() const { return mFraction; }
  15. BodyID mBodyID; ///< Body that was hit
  16. float mFraction = 1.0f + FLT_EPSILON; ///< Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start)
  17. };
  18. /// Specialization of cast result against a shape
  19. class RayCastResult : public BroadPhaseCastResult
  20. {
  21. public:
  22. JPH_OVERRIDE_NEW_DELETE
  23. SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against
  24. };
  25. JPH_NAMESPACE_END