CollideSphereVsTriangles.h 2.7 KB

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