60 float mMaxFriction[EAxis::Num] = { 0, 0, 0, 0, 0, 0 };
69 float mLimitMin[EAxis::Num] = { -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX };
70 float mLimitMax[EAxis::Num] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX };
77 void MakeFreeAxis(
EAxis inAxis) { mLimitMin[inAxis] = -FLT_MAX; mLimitMax[inAxis] = FLT_MAX; }
78 bool IsFreeAxis(
EAxis inAxis)
const {
return mLimitMin[inAxis] == -FLT_MAX && mLimitMax[inAxis] == FLT_MAX; }
82 bool IsFixedAxis(
EAxis inAxis)
const {
return mLimitMin[inAxis] >= mLimitMax[inAxis]; }
109 virtual void NotifyShapeChanged(
const BodyID &inBodyID,
Vec3Arg inDeltaCOM)
override;
110 virtual void SetupVelocityConstraint(
float inDeltaTime)
override;
111 virtual void WarmStartVelocityConstraint(
float inWarmStartImpulseRatio)
override;
112 virtual bool SolveVelocityConstraint(
float inDeltaTime)
override;
113 virtual bool SolvePositionConstraint(
float inDeltaTime,
float inBaumgarte)
override;
114#ifdef JPH_DEBUG_RENDERER
115 virtual void DrawConstraint(
DebugRenderer *inRenderer)
const override;
116 virtual void DrawConstraintLimits(
DebugRenderer *inRenderer)
const override;
118 virtual void SaveState(
StateRecorder &inStream)
const override;
127 void SetTranslationLimits(
Vec3Arg inLimitMin,
Vec3Arg inLimitMax);
137 inline bool IsFreeAxis(
EAxis inAxis)
const {
return (mFreeAxis & (1 << inAxis)) != 0; }
144 void SetMaxFriction(EAxis inAxis,
float inFriction);
148 Quat GetRotationInConstraintSpace()
const;
157 void SetMotorState(EAxis inAxis,
EMotorState inState);
173 void SetTargetOrientationCS(
QuatArg inOrientation);
181 inline Vec3 GetTotalLambdaPosition()
const {
return IsTranslationFullyConstrained()? mPointConstraintPart.GetTotalLambda() :
Vec3(mTranslationConstraintPart[0].GetTotalLambda(), mTranslationConstraintPart[1].GetTotalLambda(), mTranslationConstraintPart[2].GetTotalLambda()); }
182 inline Vec3 GetTotalLambdaRotation()
const {
return IsRotationFullyConstrained()? mRotationConstraintPart.GetTotalLambda() :
Vec3(mSwingTwistConstraintPart.GetTotalTwistLambda(), mSwingTwistConstraintPart.GetTotalSwingYLambda(), mSwingTwistConstraintPart.GetTotalSwingZLambda()); }
183 inline Vec3 GetTotalLambdaMotorTranslation()
const {
return Vec3(mMotorTranslationConstraintPart[0].GetTotalLambda(), mMotorTranslationConstraintPart[1].GetTotalLambda(), mMotorTranslationConstraintPart[2].GetTotalLambda()); }
184 inline Vec3 GetTotalLambdaMotorRotation()
const {
return Vec3(mMotorRotationConstraintPart[0].GetTotalLambda(), mMotorRotationConstraintPart[1].GetTotalLambda(), mMotorRotationConstraintPart[2].GetTotalLambda()); }
188 inline void GetPositionConstraintProperties(
Vec3 &outR1PlusU,
Vec3 &outR2,
Vec3 &outU)
const;
191 inline void UpdateRotationLimits();
194 void CacheTranslationMotorActive();
197 void CacheRotationMotorActive();
200 void CacheRotationPositionMotorActive();
203 void CacheHasSpringLimits();
206 inline bool IsTranslationConstrained()
const {
return (mFreeAxis & 0b111) != 0b111; }
207 inline bool IsTranslationFullyConstrained()
const {
return (mFixedAxis & 0b111) == 0b111 && !mHasSpringLimits; }
208 inline bool IsRotationConstrained()
const {
return (mFreeAxis & 0b111000) != 0b111000; }
209 inline bool IsRotationFullyConstrained()
const {
return (mFixedAxis & 0b111000) == 0b111000; }
210 inline bool HasFriction(EAxis inAxis)
const {
return !IsFixedAxis(inAxis) && mMaxFriction[inAxis] > 0.0f; }
215 Vec3 mLocalSpacePosition1;
216 Vec3 mLocalSpacePosition2;
219 Quat mConstraintToBody1;
220 Quat mConstraintToBody2;
225 bool mTranslationMotorActive =
false;
226 bool mRotationMotorActive =
false;
227 uint8 mRotationPositionMotorActive = 0;
228 bool mHasSpringLimits =
false;
229 float mLimitMin[EAxis::Num];
230 float mLimitMax[EAxis::Num];
237 float mMaxFriction[EAxis::Num];
249 Vec3 mTranslationAxis[3];
250 Vec3 mRotationAxis[3];
253 float mDisplacement[3];
@ TranslationZ
Body cannot move in world space Z axis.
EConstraintSpace
Certain constraints support setting them up in local or world space. This governs what is used.
Definition Constraint.h:58
@ WorldSpace
All constraint properties are specified in world space.
EConstraintSubType
Enum to identify constraint sub type.
Definition Constraint.h:34
std::uint8_t uint8
Definition Core.h:427
#define JPH_EXPORT
Definition Core.h:214
#define JPH_NAMESPACE_END
Definition Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition Core.h:348
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:29
EMotorState
Definition MotorSettings.h:17
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:100
Definition AngleConstraintPart.h:37
Definition AxisConstraintPart.h:43
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
virtual void SaveBinaryState(StreamOut &inStream) const
Saves the contents of the constraint settings in binary form to inStream.
Definition Constraint.cpp:26
virtual void RestoreBinaryState(StreamIn &inStream)
This function should not be called directly, it is used by sRestoreFromBinaryState.
Definition Constraint.cpp:36
Simple triangle renderer for debugging purposes.
Definition DebugRenderer.h:30
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT)
Get matrix that rotates and translates.
Definition Mat44.inl:149
Definition MotorSettings.h:26
Definition PointConstraintPart.h:41
static JPH_INLINE Quat sIdentity()
Definition Quat.h:103
Definition Reference.h:101
Definition RotationEulerConstraintPart.h:36
6 Degree Of Freedom Constraint. Allows control over each of the 6 degrees of freedom.
Definition SixDOFConstraint.h:97
Vec3 GetTotalLambdaPosition() const
Definition SixDOFConstraint.h:181
void SetLimitsSpringSettings(EAxis inAxis, const SpringSettings &inLimitsSpringSettings)
Definition SixDOFConstraint.h:141
const MotorSettings & GetMotorSettings(EAxis inAxis) const
Definition SixDOFConstraint.h:152
float GetLimitsMin(EAxis inAxis) const
Get constraint Limits.
Definition SixDOFConstraint.h:133
Vec3 GetTotalLambdaMotorTranslation() const
Definition SixDOFConstraint.h:183
void SetTargetOrientationBS(QuatArg inOrientation)
Definition SixDOFConstraint.h:178
MotorSettings & GetMotorSettings(EAxis inAxis)
Motor settings.
Definition SixDOFConstraint.h:151
void SetTargetAngularVelocityCS(Vec3Arg inAngularVelocity)
Set the target angular velocity in body 2 constraint space (!)
Definition SixDOFConstraint.h:165
Vec3 GetTargetPositionCS() const
Set the target position in body 1 constraint space.
Definition SixDOFConstraint.h:169
Vec3 GetTotalLambdaRotation() const
Definition SixDOFConstraint.h:182
const SpringSettings & GetLimitsSpringSettings(EAxis inAxis) const
Update the limits spring settings.
Definition SixDOFConstraint.h:140
float GetLimitsMax(EAxis inAxis) const
Definition SixDOFConstraint.h:134
void SetTargetPositionCS(Vec3Arg inPosition)
Definition SixDOFConstraint.h:170
Vec3 GetTotalLambdaMotorRotation() const
Definition SixDOFConstraint.h:184
float GetMaxFriction(EAxis inAxis) const
Definition SixDOFConstraint.h:145
virtual Mat44 GetConstraintToBody2Matrix() const override
Calculates the transform that transforms from constraint space to body 2 space. The first column of t...
Definition SixDOFConstraint.h:124
bool IsFixedAxis(EAxis inAxis) const
Definition SixDOFConstraint.h:136
virtual Mat44 GetConstraintToBody1Matrix() const override
Calculates the transform that transforms from constraint space to body 1 space. The first column of t...
Definition SixDOFConstraint.h:123
void SetTargetVelocityCS(Vec3Arg inVelocity)
Definition SixDOFConstraint.h:162
Vec3 GetTargetAngularVelocityCS() const
Definition SixDOFConstraint.h:166
bool IsFreeAxis(EAxis inAxis) const
Definition SixDOFConstraint.h:137
Quat GetTargetOrientationCS() const
Definition SixDOFConstraint.h:174
EMotorState GetMotorState(EAxis inAxis) const
Definition SixDOFConstraint.h:158
Vec3 GetTargetVelocityCS() const
Set the target velocity in body 1 constraint space.
Definition SixDOFConstraint.h:161
virtual EConstraintSubType GetSubType() const override
Generic interface of a constraint.
Definition SixDOFConstraint.h:108
6 Degree Of Freedom Constraint setup structure. Allows control over each of the 6 degrees of freedom.
Definition SixDOFConstraint.h:19
bool IsFixedAxis(EAxis inAxis) const
Definition SixDOFConstraint.h:82
void MakeFreeAxis(EAxis inAxis)
Make axis free (unconstrained)
Definition SixDOFConstraint.h:77
EAxis
Constraint is split up into translation/rotation around X, Y and Z axis.
Definition SixDOFConstraint.h:25
@ TranslationY
Definition SixDOFConstraint.h:27
@ RotationX
When limited: MinLimit needs to be [-PI, 0], MaxLimit needs to be [0, PI].
Definition SixDOFConstraint.h:30
@ TranslationZ
Definition SixDOFConstraint.h:28
@ TranslationX
Definition SixDOFConstraint.h:26
@ RotationY
When limited: MaxLimit between [0, PI]. MinLimit = -MaxLimit. Forms a cone shaped limit with Z.
Definition SixDOFConstraint.h:31
@ Num
Definition SixDOFConstraint.h:34
@ RotationZ
When limited: MaxLimit between [0, PI]. MinLimit = -MaxLimit. Forms a cone shaped limit with Y.
Definition SixDOFConstraint.h:32
void SetLimitedAxis(EAxis inAxis, float inMin, float inMax)
Set a valid range for the constraint.
Definition SixDOFConstraint.h:85
void MakeFixedAxis(EAxis inAxis)
Make axis fixed (fixed at value 0)
Definition SixDOFConstraint.h:81
bool IsFreeAxis(EAxis inAxis) const
Definition SixDOFConstraint.h:78
Settings for a linear or angular spring.
Definition SpringSettings.h:23
Definition StateRecorder.h:48
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition SwingTwistConstraintPart.h:26
Base class for all constraints that involve 2 bodies. Body1 is usually considered the parent,...
Definition TwoBodyConstraint.h:27
Base class for settings for all constraints that involve 2 bodies.
Definition TwoBodyConstraint.h:16
virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const =0
static JPH_INLINE Vec3 sAxisX()
Vectors with the principal axis.
Definition Vec3.h:52
static JPH_INLINE Vec3 sAxisY()
Definition Vec3.h:53
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107