RayCast.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Physics/Collision/BackFaceMode.h>
  5. JPH_NAMESPACE_BEGIN
  6. /// Structure that holds a single ray cast
  7. struct RayCast
  8. {
  9. JPH_OVERRIDE_NEW_DELETE
  10. /// Transform this ray using inTransform
  11. RayCast Transformed(Mat44Arg inTransform) const
  12. {
  13. Vec3 ray_origin = inTransform * mOrigin;
  14. Vec3 ray_direction = inTransform * (mOrigin + mDirection) - ray_origin;
  15. return { ray_origin, ray_direction };
  16. }
  17. /// Get point with fraction inFraction on ray (0 = start of ray, 1 = end of ray)
  18. inline Vec3 GetPointOnRay(float inFraction) const
  19. {
  20. return mOrigin + inFraction * mDirection;
  21. }
  22. Vec3 mOrigin; ///< Origin of the ray
  23. Vec3 mDirection; ///< Direction and length of the ray (anything beyond this length will not be reported as a hit)
  24. };
  25. /// Settings to be passed with a ray cast
  26. class RayCastSettings
  27. {
  28. public:
  29. JPH_OVERRIDE_NEW_DELETE
  30. /// How backfacing triangles should be treated
  31. EBackFaceMode mBackFaceMode = EBackFaceMode::IgnoreBackFaces;
  32. /// If convex shapes should be treated as solid. When true, a ray starting inside a convex shape will generate a hit at fraction 0.
  33. bool mTreatConvexAsSolid = true;
  34. };
  35. JPH_NAMESPACE_END