RayCast.h 1.0 KB

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