Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
FixedConstraint.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
10
12
15{
16public:
18
19 // See: ConstraintSettings::SaveBinaryState
20 virtual void SaveBinaryState(StreamOut &inStream) const override;
21
23 virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override;
24
26 EConstraintSpace mSpace = EConstraintSpace::WorldSpace;
27
29 bool mAutoDetectPoint = false;
30
32 RVec3 mPoint1 = RVec3::sZero();
33 Vec3 mAxisX1 = Vec3::sAxisX();
34 Vec3 mAxisY1 = Vec3::sAxisY();
35
37 RVec3 mPoint2 = RVec3::sZero();
38 Vec3 mAxisX2 = Vec3::sAxisX();
39 Vec3 mAxisY2 = Vec3::sAxisY();
40
41protected:
42 // See: ConstraintSettings::RestoreBinaryState
43 virtual void RestoreBinaryState(StreamIn &inStream) override;
44};
45
49{
50public:
52
54 FixedConstraint(Body &inBody1, Body &inBody2, const FixedConstraintSettings &inSettings);
55
56 // Generic interface of a constraint
57 virtual EConstraintSubType GetSubType() const override { return EConstraintSubType::Fixed; }
58 virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override;
59 virtual void SetupVelocityConstraint(float inDeltaTime) override;
60 virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override;
61 virtual bool SolveVelocityConstraint(float inDeltaTime) override;
62 virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override;
63#ifdef JPH_DEBUG_RENDERER
64 virtual void DrawConstraint(DebugRenderer *inRenderer) const override;
65#endif // JPH_DEBUG_RENDERER
66 virtual void SaveState(StateRecorder &inStream) const override;
67 virtual void RestoreState(StateRecorder &inStream) override;
68 virtual Ref<ConstraintSettings> GetConstraintSettings() const override;
69
70 // See: TwoBodyConstraint
71 virtual Mat44 GetConstraintToBody1Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition1); }
72 virtual Mat44 GetConstraintToBody2Matrix() const override { return Mat44::sRotationTranslation(mInvInitialOrientation, mLocalSpacePosition2); }
73
75 inline Vec3 GetTotalLambdaPosition() const { return mPointConstraintPart.GetTotalLambda(); }
76 inline Vec3 GetTotalLambdaRotation() const { return mRotationConstraintPart.GetTotalLambda(); }
77
78private:
79 // CONFIGURATION PROPERTIES FOLLOW
80
81 // Local space constraint positions
82 Vec3 mLocalSpacePosition1;
83 Vec3 mLocalSpacePosition2;
84
85 // Inverse of initial rotation from body 1 to body 2 in body 1 space
86 Quat mInvInitialOrientation;
87
88 // RUN TIME PROPERTIES FOLLOW
89
90 // The constraint parts
91 RotationEulerConstraintPart mRotationConstraintPart;
92 PointConstraintPart mPointConstraintPart;
93};
94
EConstraintSpace
Certain constraints support setting them up in local or world space. This governs what is used.
Definition: Constraint.h:58
EConstraintSubType
Enum to identify constraint sub type.
Definition: Constraint.h:34
#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_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:100
Definition: Body.h:35
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
Definition: FixedConstraint.h:49
Vec3 GetTotalLambdaPosition() const
Definition: FixedConstraint.h:75
Vec3 GetTotalLambdaRotation() const
Definition: FixedConstraint.h:76
virtual Mat44 GetConstraintToBody2Matrix() const override
Calculates the transform that transforms from constraint space to body 2 space. The first column of t...
Definition: FixedConstraint.h:72
virtual Mat44 GetConstraintToBody1Matrix() const override
Calculates the transform that transforms from constraint space to body 1 space. The first column of t...
Definition: FixedConstraint.h:71
virtual EConstraintSubType GetSubType() const override
Get the sub type of a constraint.
Definition: FixedConstraint.h:57
Fixed constraint settings, used to create a fixed constraint.
Definition: FixedConstraint.h:15
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 sTranslation(Vec3Arg inV)
Get matrix that translates.
Definition: Mat44.inl:144
static JPH_INLINE Mat44 sRotationTranslation(QuatArg inR, Vec3Arg inT)
Get matrix that rotates and translates.
Definition: Mat44.inl:149
Definition: PointConstraintPart.h:41
Definition: Quat.h:33
Definition: Reference.h:101
Definition: RotationEulerConstraintPart.h:36
Definition: StateRecorder.h:48
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
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
Definition: Vec3.h:16
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