CastConvexVsTriangles.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Physics/Collision/Shape/ConvexShape.h>
  5. #include <Jolt/Physics/Collision/ShapeCast.h>
  6. JPH_NAMESPACE_BEGIN
  7. /// Collision detection helper that casts a convex object vs one or more triangles
  8. class CastConvexVsTriangles
  9. {
  10. public:
  11. /// Constructor
  12. /// @param inShapeCast The shape to cast against the triangles and its start and direction
  13. /// @param inShapeCastSettings Settings for performing the cast
  14. /// @param inScale Local space scale for the shape to cast against.
  15. /// @param inShapeFilter Determines if sub shapes of the shape can collide
  16. /// @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.
  17. /// @param inSubShapeIDCreator1 Class that tracks the current sub shape ID for the casting shape
  18. /// @param ioCollector The collector that receives the results.
  19. CastConvexVsTriangles(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Vec3 &inScale, const ShapeFilter &inShapeFilter, const Mat44 &inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, CastShapeCollector &ioCollector);
  20. /// Cast convex object with a single triangle
  21. /// @param inV0 , inV1 , inV2: CCW triangle vertices
  22. /// @param inActiveEdges bit 0 = edge v0..v1 is active, bit 1 = edge v1..v2 is active, bit 2 = edge v2..v0 is active
  23. /// 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
  24. /// @param inSubShapeID2 The sub shape ID for the triangle
  25. void Cast(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2, uint8 inActiveEdges, const SubShapeID &inSubShapeID2);
  26. protected:
  27. const ShapeCast & mShapeCast;
  28. const ShapeCastSettings & mShapeCastSettings;
  29. const ShapeFilter & mShapeFilter;
  30. const Mat44 & mCenterOfMassTransform2;
  31. Vec3 mScale;
  32. SubShapeIDCreator mSubShapeIDCreator1;
  33. CastShapeCollector & mCollector;
  34. private:
  35. ConvexShape::SupportBuffer mSupportBuffer; ///< Buffer that holds the support function of the cast shape
  36. const ConvexShape::Support * mSupport = nullptr; ///< Support function of the cast shape
  37. float mScaleSign; ///< Sign of the scale, -1 if object is inside out, 1 if not
  38. };
  39. JPH_NAMESPACE_END