Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/SoftBody/SoftBodyUpdateContext.h
9912 views
1
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2
// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3
// SPDX-License-Identifier: MIT
4
5
#pragma once
6
7
#include <Jolt/Core/NonCopyable.h>
8
#include <Jolt/Physics/Body/MotionProperties.h>
9
10
JPH_NAMESPACE_BEGIN
11
12
class Body;
13
class SoftBodyMotionProperties;
14
class SoftBodyContactListener;
15
class SimShapeFilter;
16
17
/// Temporary data used by the update of a soft body
18
class SoftBodyUpdateContext : public NonCopyable
19
{
20
public:
21
static constexpr uint cVertexCollisionBatch = 64; ///< Number of vertices to process in a batch in DetermineCollisionPlanes
22
static constexpr uint cVertexConstraintBatch = 256; ///< Number of vertices to group for processing batches of constraints in ApplyEdgeConstraints
23
24
// Input
25
Body * mBody; ///< Body that is being updated
26
SoftBodyMotionProperties * mMotionProperties; ///< Motion properties of that body
27
SoftBodyContactListener * mContactListener; ///< Contact listener to fire callbacks to
28
const SimShapeFilter * mSimShapeFilter; ///< Shape filter to use for collision detection
29
RMat44 mCenterOfMassTransform; ///< Transform of the body relative to the soft body
30
Vec3 mGravity; ///< Gravity vector in local space of the soft body
31
Vec3 mDisplacementDueToGravity; ///< Displacement of the center of mass due to gravity in the current time step
32
float mDeltaTime; ///< Delta time for the current time step
33
float mSubStepDeltaTime; ///< Delta time for each sub step
34
35
/// Describes progress in the current update
36
enum class EState
37
{
38
DetermineCollisionPlanes, ///< Determine collision planes for vertices in parallel
39
DetermineSensorCollisions, ///< Determine collisions with sensors in parallel
40
ApplyConstraints, ///< Apply constraints in parallel
41
Done ///< Update is finished
42
};
43
44
// State of the update
45
atomic<EState> mState { EState::DetermineCollisionPlanes };///< Current state of the update
46
atomic<uint> mNextCollisionVertex { 0 }; ///< Next vertex to process for DetermineCollisionPlanes
47
atomic<uint> mNumCollisionVerticesProcessed { 0 }; ///< Number of vertices processed by DetermineCollisionPlanes, used to determine if we can go to the next step
48
atomic<uint> mNextSensorIndex { 0 }; ///< Next sensor to process for DetermineCollisionPlanes
49
atomic<uint> mNumSensorsProcessed { 0 }; ///< Number of sensors processed by DetermineSensorCollisions, used to determine if we can go to the next step
50
atomic<uint> mNextIteration { 0 }; ///< Next simulation iteration to process
51
atomic<uint> mNextConstraintGroup { 0 }; ///< Next constraint group to process
52
atomic<uint> mNumConstraintGroupsProcessed { 0 }; ///< Number of groups processed, used to determine if we can go to the next iteration
53
54
// Output
55
Vec3 mDeltaPosition; ///< Delta position of the body in the current time step, should be applied after the update
56
ECanSleep mCanSleep; ///< Can the body sleep? Should be applied after the update
57
};
58
59
JPH_NAMESPACE_END
60
61