CastResult.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. /// Reset this result so it can be reused for a new cast.
  16. inline void Reset() { mBodyID = BodyID(); mFraction = 1.0f + FLT_EPSILON; }
  17. BodyID mBodyID; ///< Body that was hit
  18. float mFraction = 1.0f + FLT_EPSILON; ///< Hit fraction of the ray/object [0, 1], HitPoint = Start + mFraction * (End - Start)
  19. };
  20. /// Specialization of cast result against a shape
  21. class RayCastResult : public BroadPhaseCastResult
  22. {
  23. public:
  24. JPH_OVERRIDE_NEW_DELETE
  25. SubShapeID mSubShapeID2; ///< Sub shape ID of shape that we collided against
  26. };
  27. JPH_NAMESPACE_END