Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/SoftBody/SoftBodyManifold.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Physics/SoftBody/SoftBodyMotionProperties.h>
8
9 JPH_NAMESPACE_BEGIN
10
11 /// An interface to query which vertices of a soft body are colliding with other bodies
12 class SoftBodyManifold
13 {
14 public:
15 /// Get the vertices of the soft body for iterating
16 const Array<SoftBodyVertex> & GetVertices() const { return mVertices; }
17
18 /// Check if a vertex has collided with something in this update
19 JPH_INLINE bool HasContact(const SoftBodyVertex &inVertex) const
20 {
21 return inVertex.mHasContact;
22 }
23
24 /// Get the local space contact point (multiply by GetCenterOfMassTransform() of the soft body to get world space)
25 JPH_INLINE Vec3 GetLocalContactPoint(const SoftBodyVertex &inVertex) const
26 {
27 return inVertex.mPosition - inVertex.mCollisionPlane.SignedDistance(inVertex.mPosition) * inVertex.mCollisionPlane.GetNormal();
28 }
29
30 /// Get the contact normal for the vertex (assumes there is a contact).
31 JPH_INLINE Vec3 GetContactNormal(const SoftBodyVertex &inVertex) const
32 {
33 return -inVertex.mCollisionPlane.GetNormal();
34 }
35
36 /// Get the body with which the vertex has collided in this update
37 JPH_INLINE BodyID GetContactBodyID(const SoftBodyVertex &inVertex) const
38 {
39 return inVertex.mHasContact? mCollidingShapes[inVertex.mCollidingShapeIndex].mBodyID : BodyID();
40 }
41
42 /// Get the number of sensors that are in contact with the soft body
43 JPH_INLINE uint GetNumSensorContacts() const
44 {
45 return (uint)mCollidingSensors.size();
46 }
47
48 /// Get the i-th sensor that is in contact with the soft body
49 JPH_INLINE BodyID GetSensorContactBodyID(uint inIndex) const
50 {
51 return mCollidingSensors[inIndex].mBodyID;
52 }
53
54 private:
55 /// Allow SoftBodyMotionProperties to construct us
56 friend class SoftBodyMotionProperties;
57
58 /// Constructor
59 explicit SoftBodyManifold(const SoftBodyMotionProperties *inMotionProperties) :
60 mVertices(inMotionProperties->mVertices),
61 mCollidingShapes(inMotionProperties->mCollidingShapes),
62 mCollidingSensors(inMotionProperties->mCollidingSensors)
63 {
64 }
65
66 using CollidingShape = SoftBodyMotionProperties::CollidingShape;
67 using CollidingSensor = SoftBodyMotionProperties::CollidingSensor;
68
69 const Array<SoftBodyVertex> & mVertices;
70 const Array<CollidingShape> & mCollidingShapes;
71 const Array<CollidingSensor> & mCollidingSensors;
72 };
73
74 JPH_NAMESPACE_END