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
28 RVec3 mPoint1 = RVec3::sZero();
29
32 RVec3 mPoint2 = RVec3::sZero();
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 ResetWarmStart() override;
53 virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override;
54 virtual bool SolveVelocityConstraint(float inDeltaTime) override;
55 virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override;
56#ifdef JPH_DEBUG_RENDERER
57 virtual void DrawConstraint(DebugRenderer *inRenderer) const override;
58#endif // JPH_DEBUG_RENDERER
59 virtual void SaveState(StateRecorder &inStream) const override;
60 virtual void RestoreState(StateRecorder &inStream) override;
61 virtual Ref<ConstraintSettings> GetConstraintSettings() const override;
62
64 void SetPoint1(EConstraintSpace inSpace, RVec3Arg inPoint1);
65
67 void SetPoint2(EConstraintSpace inSpace, RVec3Arg inPoint2);
68
70 inline Vec3 GetLocalSpacePoint1() const { return mLocalSpacePosition1; }
71
73 inline Vec3 GetLocalSpacePoint2() const { return mLocalSpacePosition2; }
74
75 // See: TwoBodyConstraint
76 virtual Mat44 GetConstraintToBody1Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition1); }
77 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.
78
80 inline Vec3 GetTotalLambdaPosition() const { return mPointConstraintPart.GetTotalLambda(); }
81
82private:
83 // Internal helper function to calculate the values below
84 void CalculateConstraintProperties();
85
86 // Local space constraint positions
87 Vec3 mLocalSpacePosition1;
88 Vec3 mLocalSpacePosition2;
89
90 // The constraint part
91 PointConstraintPart mPointConstraintPart;
92};
93
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:227
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#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
Definition: DebugRenderer.h:47
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:77
virtual EConstraintSubType GetSubType() const override
Get the sub type of a constraint.
Definition: PointConstraint.h:49
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:76
Vec3 GetTotalLambdaPosition() const
Definition: PointConstraint.h:80
Vec3 GetLocalSpacePoint1() const
Get the attachment point for body 1 relative to body 1 COM.
Definition: PointConstraint.h:70
Vec3 GetLocalSpacePoint2() const
Get the attachment point for body 2 relative to body 2 COM.
Definition: PointConstraint.h:73
Definition: PointConstraintPart.h:41
Point constraint settings, used to create a point constraint.
Definition: PointConstraint.h:14
Definition: Reference.h:101
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 sZero()
Vector with all zeros.
Definition: Vec3.inl:107