Jolt Physics
A multi core friendly Game Physics Engine
|
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rigid body. More...
#include <Constraint.h>
Public Member Functions | |
JPH_OVERRIDE_NEW_DELETE | Constraint (const ConstraintSettings &inSettings) |
Constructor. | |
virtual | ~Constraint ()=default |
Virtual destructor. | |
virtual EConstraintType | GetType () const |
Get the type of a constraint. | |
virtual EConstraintSubType | GetSubType () const =0 |
Get the sub type of a constraint. | |
uint32 | GetConstraintPriority () const |
void | SetConstraintPriority (uint32 inPriority) |
void | SetNumVelocityStepsOverride (uint inN) |
Used only when the constraint is active. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island. | |
uint | GetNumVelocityStepsOverride () const |
void | SetNumPositionStepsOverride (uint inN) |
Used only when the constraint is active. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island. | |
uint | GetNumPositionStepsOverride () const |
void | SetEnabled (bool inEnabled) |
bool | GetEnabled () const |
Test if a constraint is enabled. | |
uint64 | GetUserData () const |
Access to the user data, can be used for anything by the application. | |
void | SetUserData (uint64 inUserData) |
virtual void | NotifyShapeChanged (const BodyID &inBodyID, Vec3Arg inDeltaCOM)=0 |
virtual void | ResetWarmStart ()=0 |
virtual void | BuildIslands (uint32 inConstraintIndex, IslandBuilder &ioBuilder, BodyManager &inBodyManager)=0 |
Link bodies that are connected by this constraint in the island builder. | |
virtual uint | BuildIslandSplits (LargeIslandSplitter &ioSplitter) const =0 |
Link bodies that are connected by this constraint in the same split. Returns the split index. | |
virtual void | DrawConstraint (DebugRenderer *inRenderer) const =0 |
virtual void | DrawConstraintLimits (DebugRenderer *inRenderer) const |
virtual void | DrawConstraintReferenceFrame (DebugRenderer *inRenderer) const |
float | GetDrawConstraintSize () const |
Size of constraint when drawing it through the debug renderer. | |
void | SetDrawConstraintSize (float inSize) |
virtual void | SaveState (StateRecorder &inStream) const |
Saving state for replay. | |
virtual void | RestoreState (StateRecorder &inStream) |
Restoring state for replay. | |
virtual Ref< ConstraintSettings > | GetConstraintSettings () const =0 |
Debug function to convert a constraint to its settings, note that this will not save to which bodies the constraint is connected to. | |
Solver interface | |
virtual bool | IsActive () const |
virtual void | SetupVelocityConstraint (float inDeltaTime)=0 |
virtual void | WarmStartVelocityConstraint (float inWarmStartImpulseRatio)=0 |
virtual bool | SolveVelocityConstraint (float inDeltaTime)=0 |
virtual bool | SolvePositionConstraint (float inDeltaTime, float inBaumgarte)=0 |
Public Member Functions inherited from RefTarget< Constraint > | |
RefTarget ()=default | |
Constructor. | |
RefTarget (const RefTarget &) | |
~RefTarget () | |
assert no one is referencing us | |
void | SetEmbedded () const |
RefTarget & | operator= (const RefTarget &) |
Assignment operator. | |
uint32 | GetRefCount () const |
Get current refcount of this object. | |
void | AddRef () const |
Add or release a reference to this object. | |
void | Release () const |
Public Member Functions inherited from NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
void | operator= (const NonCopyable &)=delete |
Protected Member Functions | |
void | ToConstraintSettings (ConstraintSettings &outSettings) const |
Helper function to copy settings back to constraint settings for this base class. | |
Protected Attributes | |
float | mDrawConstraintSize |
Size of constraint when drawing it through the debug renderer. | |
Protected Attributes inherited from RefTarget< Constraint > | |
atomic< uint32 > | mRefCount |
Current reference count. | |
Friends | |
class | ConstraintManager |
Additional Inherited Members | |
Static Public Member Functions inherited from RefTarget< Constraint > | |
static int | sInternalGetRefCountOffset () |
INTERNAL HELPER FUNCTION USED BY SERIALIZATION. | |
Static Protected Attributes inherited from RefTarget< Constraint > | |
static constexpr uint32 | cEmbedded |
A large value that gets added to the refcount to mark the object as embedded. | |
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rigid body.
|
inlineexplicit |
Constructor.
|
virtualdefault |
Virtual destructor.
|
pure virtual |
Link bodies that are connected by this constraint in the island builder.
Implemented in TwoBodyConstraint, and VehicleConstraint.
|
pure virtual |
Link bodies that are connected by this constraint in the same split. Returns the split index.
Implemented in TwoBodyConstraint, and VehicleConstraint.
|
pure virtual |
|
inlinevirtual |
Reimplemented in ConeConstraint, HingeConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
inlinevirtual |
Reimplemented in TwoBodyConstraint.
|
inline |
Priority of the constraint when solving. Higher numbers have are more likely to be solved correctly. Note that if you want a deterministic simulation and you cannot guarantee the order in which constraints are added/removed, you can make the priority for all constraints unique to get a deterministic ordering.
|
pure virtual |
Debug function to convert a constraint to its settings, note that this will not save to which bodies the constraint is connected to.
Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
inline |
Size of constraint when drawing it through the debug renderer.
|
inline |
Test if a constraint is enabled.
|
inline |
|
inline |
|
pure virtual |
Get the sub type of a constraint.
Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
inlinevirtual |
Get the type of a constraint.
Reimplemented in TwoBodyConstraint.
|
inline |
Access to the user data, can be used for anything by the application.
|
inlinevirtual |
Reimplemented in PathConstraint, TwoBodyConstraint, and VehicleConstraint.
|
pure virtual |
Notify the constraint that the shape of a body has changed and that its center of mass has moved by inDeltaCOM. Bodies don't know which constraints are connected to them so the user is responsible for notifying the relevant constraints when a body changes.
inBodyID | ID of the body that has changed |
inDeltaCOM | The delta of the center of mass of the body (shape->GetCenterOfMass() - shape_before_change->GetCenterOfMass()) |
Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
pure virtual |
Notify the system that the configuration of the bodies and/or constraint has changed enough so that the warm start impulses should not be applied the next frame. You can use this function for example when repositioning a ragdoll through Ragdoll::SetPose in such a way that the orientation of the bodies completely changes so that the previous frame impulses are no longer a good approximation of what the impulses will be in the next frame. Calling this function when there are no big changes will result in the constraints being much 'softer' than usual so they are more easily violated (e.g. a long chain of bodies might sag a bit if you call this every frame).
Implemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
virtual |
Restoring state for replay.
Reimplemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
virtual |
Saving state for replay.
Reimplemented in ConeConstraint, DistanceConstraint, FixedConstraint, GearConstraint, HingeConstraint, PathConstraint, PointConstraint, PulleyConstraint, RackAndPinionConstraint, SixDOFConstraint, SliderConstraint, SwingTwistConstraint, and VehicleConstraint.
|
inline |
|
inline |
|
inline |
Enable / disable this constraint. This can e.g. be used to implement a breakable constraint by detecting that the constraint impulse (see e.g. PointConstraint::GetTotalLambdaPosition) went over a certain limit and then disabling the constraint. Note that although a disabled constraint will not affect the simulation in any way anymore, it does incur some processing overhead. Alternatively you can remove a constraint from the constraint manager (which may be more costly if you want to disable the constraint for a short while).
|
inline |
Used only when the constraint is active. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island.
|
inline |
Used only when the constraint is active. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.
|
pure virtual |
|
inline |
|
pure virtual |
|
pure virtual |
|
protected |
Helper function to copy settings back to constraint settings for this base class.
|
pure virtual |
|
friend |
|
protected |
Size of constraint when drawing it through the debug renderer.