Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
PointConstraint.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
9
11
14{
15public:
17
18 // See: ConstraintSettings::SaveBinaryState
19 virtual void SaveBinaryState(StreamOut &inStream) const override;
20
22 virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override;
23
25 EConstraintSpace mSpace = EConstraintSpace::WorldSpace;
26
29
33
34protected:
35 // See: ConstraintSettings::RestoreBinaryState
36 virtual void RestoreBinaryState(StreamIn &inStream) override;
37};
38
41{
42public:
44
46 PointConstraint(Body &inBody1, Body &inBody2, const PointConstraintSettings &inSettings);
47
48 // Generic interface of a constraint
49 virtual EConstraintSubType GetSubType() const override { return EConstraintSubType::Point; }
50 virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override;
51 virtual void SetupVelocityConstraint(float inDeltaTime) override;
52 virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override;
53 virtual bool SolveVelocityConstraint(float inDeltaTime) override;
54 virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override;
55#ifdef JPH_DEBUG_RENDERER
56 virtual void DrawConstraint(DebugRenderer *inRenderer) const override;
57#endif // JPH_DEBUG_RENDERER
58 virtual void SaveState(StateRecorder &inStream) const override;
59 virtual void RestoreState(StateRecorder &inStream) override;
60 virtual Ref<ConstraintSettings> GetConstraintSettings() const override;
61
63 void SetPoint1(EConstraintSpace inSpace, RVec3Arg inPoint1);
64
66 void SetPoint2(EConstraintSpace inSpace, RVec3Arg inPoint2);
67
69 inline Vec3 GetLocalSpacePoint1() const { return mLocalSpacePosition1; }
70
72 inline Vec3 GetLocalSpacePoint2() const { return mLocalSpacePosition2; }
73
74 // See: TwoBodyConstraint
75 virtual Mat44 GetConstraintToBody1Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition1); }
76 virtual Mat44 GetConstraintToBody2Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition2); } // Note: Incorrect rotation as we don't track the original rotation difference, should not matter though as the constraint is not limiting rotation.
77
79 inline Vec3 GetTotalLambdaPosition() const { return mPointConstraintPart.GetTotalLambda(); }
80
81private:
82 // Internal helper function to calculate the values below
83 void CalculateConstraintProperties();
84
85 // Local space constraint positions
86 Vec3 mLocalSpacePosition1;
87 Vec3 mLocalSpacePosition2;
88
89 // The constraint part
90 PointConstraintPart mPointConstraintPart;
91};
92
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_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(class_name)
Definition: SerializableObject.h:100
Definition: Body.h:33
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
Simple triangle renderer for debugging purposes.
Definition: DebugRenderer.h:25
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
A point constraint constrains 2 bodies on a single point (removing 3 degrees of freedom)
Definition: PointConstraint.h:41
virtual Mat44 GetConstraintToBody2Matrix() const override
Calculates the transform that transforms from constraint space to body 2 space. The first column of t...
Definition: PointConstraint.h:76
virtual EConstraintSubType GetSubType() const override
Get the sub type of a constraint.
Definition: PointConstraint.h:49
virtual void SetupVelocityConstraint(float inDeltaTime) override
Definition: PointConstraint.cpp:95
virtual Mat44 GetConstraintToBody1Matrix() const override
Calculates the transform that transforms from constraint space to body 1 space. The first column of t...
Definition: PointConstraint.h:75
void SetPoint2(EConstraintSpace inSpace, RVec3Arg inPoint2)
Update the attachment point for body 2.
Definition: PointConstraint.cpp:82
virtual bool SolveVelocityConstraint(float inDeltaTime) override
Definition: PointConstraint.cpp:106
Vec3 GetTotalLambdaPosition() const
Definition: PointConstraint.h:79
virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override
Definition: PointConstraint.cpp:100
virtual void RestoreState(StateRecorder &inStream) override
Restoring state for replay.
Definition: PointConstraint.cpp:135
virtual Ref< ConstraintSettings > GetConstraintSettings() const override
Debug function to convert a constraint to its settings, note that this will not save to which bodies ...
Definition: PointConstraint.cpp:142
Vec3 GetLocalSpacePoint1() const
Get the attachment point for body 1 relative to body 1 COM.
Definition: PointConstraint.h:69
virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override
Definition: PointConstraint.cpp:66
virtual void SaveState(StateRecorder &inStream) const override
Saving state for replay.
Definition: PointConstraint.cpp:128
void SetPoint1(EConstraintSpace inSpace, RVec3Arg inPoint1)
Update the attachment point for body 1.
Definition: PointConstraint.cpp:74
virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override
Definition: PointConstraint.cpp:111
virtual void DrawConstraint(DebugRenderer *inRenderer) const override
Definition: PointConstraint.cpp:120
Vec3 GetLocalSpacePoint2() const
Get the attachment point for body 2 relative to body 2 COM.
Definition: PointConstraint.h:72
Definition: PointConstraintPart.h:41
Vec3 GetTotalLambda() const
Return lagrange multiplier.
Definition: PointConstraintPart.h:199
Point constraint settings, used to create a point constraint.
Definition: PointConstraint.h:14
virtual void RestoreBinaryState(StreamIn &inStream) override
This function should not be called directly, it is used by sRestoreFromBinaryState.
Definition: PointConstraint.cpp:36
virtual void SaveBinaryState(StreamOut &inStream) const override
Saves the contents of the constraint settings in binary form to inStream.
Definition: PointConstraint.cpp:27
RVec3 mPoint1
Body 1 constraint position (space determined by mSpace).
Definition: PointConstraint.h:28
RVec3 mPoint2
Definition: PointConstraint.h:32
EConstraintSpace mSpace
This determines in which space the constraint is setup, all properties below should be in the specifi...
Definition: PointConstraint.h:25
virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override
Create an an instance of this constraint.
Definition: PointConstraint.cpp:45
Definition: Reference.h:101
Definition: StateRecorder.h:15
Simple binary input stream.
Definition: StreamIn.h:11
Simple binary output stream.
Definition: StreamOut.h:11
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
Definition: Vec3.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107