CollideConvexVsTriangles.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Geometry/AABox.h>
  5. #include <Physics/Collision/Shape/Shape.h>
  6. #include <Physics/Collision/Shape/SubShapeID.h>
  7. #include <Physics/Collision/Shape/ConvexShape.h>
  8. #include <atomic>
  9. namespace JPH {
  10. class CollideShapeSettings;
  11. /// Collision detection helper that collides a convex object vs one or more triangles
  12. class CollideConvexVsTriangles
  13. {
  14. public:
  15. /// Constructor
  16. /// @param inShape1 The convex shape to collide against triangles
  17. /// @param inScale1 Local space scale for the convex object
  18. /// @param inScale2 Local space scale for the triangles
  19. /// @param inCenterOfMassTransform1 Transform that takes the center of mass of 1 into world space
  20. /// @param inCenterOfMassTransform2 Transform that takes the center of mass of 2 into world space
  21. /// @param inSubShapeID1 Sub shape ID of the convex object
  22. /// @param inCollideShapeSettings Settings for the collide shape query
  23. /// @param ioCollector The collector that will receive the results
  24. CollideConvexVsTriangles(const ConvexShape *inShape1, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeID &inSubShapeID1, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector);
  25. /// Collide convex object with a single triangle
  26. /// @param inV0 , inV1 , inV2: CCW triangle vertices
  27. /// @param inActiveEdges bit 0 = edge v0..v1 is active, bit 1 = edge v1..v2 is active, bit 2 = edge v2..v0 is active
  28. /// 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
  29. /// @param inSubShapeID2 The sub shape ID for the triangle
  30. void Collide(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2, uint8 inActiveEdges, const SubShapeID &inSubShapeID2);
  31. protected:
  32. const CollideShapeSettings & mCollideShapeSettings; ///< Settings for this collision operation
  33. CollideShapeCollector & mCollector; ///< The collector that will receive the results
  34. const ConvexShape * mShape1; ///< The shape that we're colliding with
  35. Vec3 mScale1; ///< The scale of the shape (in shape local space) of the shape we're colliding with
  36. Vec3 mScale2; ///< The scale of the shape (in shape local space) of the shape we're colliding against
  37. Mat44 mTransform1; ///< Transform of the shape we're colliding with
  38. Mat44 mTransform2To1; ///< Transform that takes a point in space of the colliding shape to the shape we're colliding with
  39. AABox mBoundsOf1; ///< Bounds of the colliding shape in local space
  40. AABox mBoundsOf1InSpaceOf2; ///< Bounds of the colliding shape in space of shape we're colliding with
  41. SubShapeID mSubShapeID1; ///< Sub shape ID of colliding shape
  42. float mScaleSign2; ///< Sign of the scale of object 2, -1 if object is inside out, 1 if not
  43. ConvexShape::SupportBuffer mBufferExCvxRadius; ///< Buffer that holds the support function data excluding convex radius
  44. ConvexShape::SupportBuffer mBufferIncCvxRadius; ///< Buffer that holds the support function data including convex radius
  45. const ConvexShape::Support * mShape1ExCvxRadius = nullptr; ///< Actual support function object excluding convex radius
  46. const ConvexShape::Support * mShape1IncCvxRadius = nullptr; ///< Actual support function object including convex radius
  47. };
  48. } // JPH