CastSphereVsTriangles.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Physics/Collision/ShapeCast.h>
  5. JPH_NAMESPACE_BEGIN
  6. /// Collision detection helper that casts a sphere vs one or more triangles
  7. class CastSphereVsTriangles
  8. {
  9. public:
  10. /// Constructor
  11. /// @param inShapeCast The sphere to cast against the triangles and its start and direction
  12. /// @param inShapeCastSettings Settings for performing the cast
  13. /// @param inScale Local space scale for the shape to cast against.
  14. /// @param inShapeFilter Determines if sub shapes of the shape can collide
  15. /// @param inCenterOfMassTransform2 Is the center of mass transform of shape 2 (excluding scale), this is used to provide a transform to the shape cast result so that local quantities can be transformed into world space.
  16. /// @param inSubShapeIDCreator1 Class that tracks the current sub shape ID for the casting shape
  17. /// @param ioCollector The collector that receives the results.
  18. CastSphereVsTriangles(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Vec3 &inScale, const ShapeFilter &inShapeFilter, const Mat44 &inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, CastShapeCollector &ioCollector);
  19. /// Cast sphere with a single triangle
  20. /// @param inV0 , inV1 , inV2: CCW triangle vertices
  21. /// @param inActiveEdges bit 0 = edge v0..v1 is active, bit 1 = edge v1..v2 is active, bit 2 = edge v2..v0 is active
  22. /// An active edge is an edge that is not connected to another triangle in such a way that it is impossible to collide with the edge
  23. /// @param inSubShapeID2 The sub shape ID for the triangle
  24. void Cast(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2, uint8 inActiveEdges, const SubShapeID &inSubShapeID2);
  25. protected:
  26. Vec3 mStart; ///< Starting location of the sphere
  27. Vec3 mDirection; ///< Direction and length of movement of sphere
  28. float mRadius; ///< Scaled radius of sphere
  29. const ShapeCastSettings & mShapeCastSettings;
  30. const ShapeFilter & mShapeFilter;
  31. const Mat44 & mCenterOfMassTransform2;
  32. Vec3 mScale;
  33. SubShapeIDCreator mSubShapeIDCreator1;
  34. CastShapeCollector & mCollector;
  35. private:
  36. void AddHit(bool inBackFacing, const SubShapeID &inSubShapeID2, float inFraction, Vec3Arg inContactPointA, Vec3Arg inContactPointB, Vec3Arg inContactNormal);
  37. void AddHitWithActiveEdgeDetection(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2, bool inBackFacing, Vec3Arg inTriangleNormal, uint8 inActiveEdges, const SubShapeID &inSubShapeID2, float inFraction, Vec3Arg inContactPointA, Vec3Arg inContactPointB, Vec3Arg inContactNormal);
  38. float RayCylinder(Vec3Arg inRayDirection, Vec3Arg inCylinderA, Vec3Arg inCylinderB, float inRadius) const;
  39. float mScaleSign; ///< Sign of the scale, -1 if object is inside out, 1 if not
  40. };
  41. JPH_NAMESPACE_END