CollideSphereVsTriangles.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Physics/Collision/Shape/Shape.h>
  5. #include <Physics/Collision/Shape/SubShapeID.h>
  6. #include <Physics/Collision/Shape/SphereShape.h>
  7. namespace JPH {
  8. class CollideShapeSettings;
  9. /// Collision detection helper that collides a sphere vs one or more triangles
  10. class CollideSphereVsTriangles
  11. {
  12. public:
  13. /// Constructor
  14. /// @param inShape1 The sphere to collide against triangles
  15. /// @param inScale1 Local space scale for the sphere
  16. /// @param inScale2 Local space scale for the triangles
  17. /// @param inCenterOfMassTransform1 Transform that takes the center of mass of 1 into world space
  18. /// @param inCenterOfMassTransform2 Transform that takes the center of mass of 2 into world space
  19. /// @param inSubShapeID1 Sub shape ID of the convex object
  20. /// @param inCollideShapeSettings Settings for the collide shape query
  21. /// @param ioCollector The collector that will receive the results
  22. CollideSphereVsTriangles(const SphereShape *inShape1, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeID &inSubShapeID1, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector);
  23. /// Collide sphere with a single triangle
  24. /// @param inV0 , inV1 , inV2: CCW triangle vertices
  25. /// @param inActiveEdges bit 0 = edge v0..v1 is active, bit 1 = edge v1..v2 is active, bit 2 = edge v2..v0 is active
  26. /// 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
  27. /// @param inSubShapeID2 The sub shape ID for the triangle
  28. void Collide(Vec3Arg inV0, Vec3Arg inV1, Vec3Arg inV2, uint8 inActiveEdges, const SubShapeID &inSubShapeID2);
  29. protected:
  30. const CollideShapeSettings & mCollideShapeSettings; ///< Settings for this collision operation
  31. CollideShapeCollector & mCollector; ///< The collector that will receive the results
  32. const SphereShape * mShape1; ///< The shape that we're colliding with
  33. Vec3 mScale2; ///< The scale of the shape (in shape local space) of the shape we're colliding against
  34. Mat44 mTransform2; ///< Transform of the shape we're colliding against
  35. Vec3 mSphereCenterIn2; ///< The center of the sphere in the space of 2
  36. SubShapeID mSubShapeID1; ///< Sub shape ID of colliding shape
  37. float mScaleSign2; ///< Sign of the scale of object 2, -1 if object is inside out, 1 if not
  38. float mRadius; ///< Radius of the sphere
  39. float mRadiusPlusMaxSeparationSq; ///< (Radius + Max SeparationDistance)^2
  40. };
  41. } // JPH