NarrowPhaseQuery.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Physics/Body/BodyFilter.h>
  5. #include <Physics/Body/BodyLock.h>
  6. #include <Physics/Body/BodyLockInterface.h>
  7. #include <Physics/Collision/ShapeFilter.h>
  8. #include <Physics/Collision/BroadPhase/BroadPhase.h>
  9. #include <Physics/Collision/BackFaceMode.h>
  10. namespace JPH {
  11. class Shape;
  12. class CollideShapeSettings;
  13. class RayCastResult;
  14. /// Class that provides an interface for doing precise collision detection against the broad and then the narrow phase
  15. class NarrowPhaseQuery : public NonCopyable
  16. {
  17. public:
  18. /// Constructor
  19. NarrowPhaseQuery() = default;
  20. NarrowPhaseQuery(BodyLockInterface &inBodyLockInterface, BroadPhase &inBroadPhase) : mBodyLockInterface(&inBodyLockInterface), mBroadPhase(&inBroadPhase) { }
  21. /// Cast a ray, returns true if it finds a hit closer than ioHit.mFraction and updates ioHit in that case.
  22. bool CastRay(const RayCast &inRay, RayCastResult &ioHit, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
  23. /// Cast a ray, allows collecting multiple hits
  24. void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, CastRayCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
  25. /// Check if inPoint is inside any shapes. For this tests all shapes are treated as if they were solid.
  26. /// For a mesh shape, this test will only provide sensible information if the mesh is a closed manifold.
  27. /// For each shape that collides, ioCollector will receive a hit
  28. void CollidePoint(Vec3Arg inPoint, CollidePointCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
  29. /// Collide a shape with the system
  30. void CollideShape(const Shape *inShape, Vec3Arg inShapeScale, Mat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
  31. /// Cast a shape and report any hits to ioCollector
  32. void CastShape(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, CastShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }, const ShapeFilter &inShapeFilter = { }) const;
  33. /// Collect all leaf transformed shapes that fall inside world space box inBox
  34. void CollectTransformedShapes(const AABox &inBox, TransformedShapeCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter = { }, const ObjectLayerFilter &inObjectLayerFilter = { }, const BodyFilter &inBodyFilter = { }) const;
  35. private:
  36. BodyLockInterface * mBodyLockInterface = nullptr;
  37. BroadPhase * mBroadPhase = nullptr;
  38. };
  39. } // JPH