Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ConeConstraint.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{
17
18public:
19 // See: ConstraintSettings::SaveBinaryState
20 virtual void SaveBinaryState(StreamOut &inStream) const override;
21
23 virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override;
24
27
29 RVec3 mPoint1 = RVec3::sZero();
30 Vec3 mTwistAxis1 = Vec3::sAxisX();
31
33 RVec3 mPoint2 = RVec3::sZero();
34 Vec3 mTwistAxis2 = Vec3::sAxisX();
35
37 float mHalfConeAngle = 0.0f;
38
39protected:
40 // See: ConstraintSettings::RestoreBinaryState
41 virtual void RestoreBinaryState(StreamIn &inStream) override;
42};
43
70{
71public:
73
75 ConeConstraint(Body &inBody1, Body &inBody2, const ConeConstraintSettings &inSettings);
76
77 // Generic interface of a constraint
78 virtual EConstraintSubType GetSubType() const override { return EConstraintSubType::Cone; }
79 virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override;
80 virtual void SetupVelocityConstraint(float inDeltaTime) override;
81 virtual void ResetWarmStart() override;
82 virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override;
83 virtual bool SolveVelocityConstraint(float inDeltaTime) override;
84 virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override;
85#ifdef JPH_DEBUG_RENDERER
86 virtual void DrawConstraint(DebugRenderer *inRenderer) const override;
87 virtual void DrawConstraintLimits(DebugRenderer *inRenderer) const override;
88#endif // JPH_DEBUG_RENDERER
89 virtual void SaveState(StateRecorder &inStream) const override;
90 virtual void RestoreState(StateRecorder &inStream) override;
91 virtual Ref<ConstraintSettings> GetConstraintSettings() const override;
92
93 // See: TwoBodyConstraint
94 virtual Mat44 GetConstraintToBody1Matrix() const override;
95 virtual Mat44 GetConstraintToBody2Matrix() const override;
96
98 void SetHalfConeAngle(float inHalfConeAngle) { JPH_ASSERT(inHalfConeAngle >= 0.0f && inHalfConeAngle <= JPH_PI); mCosHalfConeAngle = Cos(inHalfConeAngle); }
99 float GetCosHalfConeAngle() const { return mCosHalfConeAngle; }
100
102 inline Vec3 GetTotalLambdaPosition() const { return mPointConstraintPart.GetTotalLambda(); }
103 inline float GetTotalLambdaRotation() const { return mAngleConstraintPart.GetTotalLambda(); }
104
105private:
106 // Internal helper function to calculate the values below
107 void CalculateRotationConstraintProperties(Mat44Arg inRotation1, Mat44Arg inRotation2);
108
109 // CONFIGURATION PROPERTIES FOLLOW
110
111 // Local space constraint positions
112 Vec3 mLocalSpacePosition1;
113 Vec3 mLocalSpacePosition2;
114
115 // Local space constraint axis
116 Vec3 mLocalSpaceTwistAxis1;
117 Vec3 mLocalSpaceTwistAxis2;
118
119 // Angular limits
120 float mCosHalfConeAngle;
121
122 // RUN TIME PROPERTIES FOLLOW
123
124 // Axis and angle of rotation between the two bodies
125 Vec3 mWorldSpaceRotationAxis;
126 float mCosTheta;
127
128 // The constraint parts
129 PointConstraintPart mPointConstraintPart;
130 AngleConstraintPart mAngleConstraintPart;
131};
132
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
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:31
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:109
JPH_INLINE float Cos(float inX)
Cosine of x (input in radians)
Definition Trigonometry.h:20
Definition AngleConstraintPart.h:37
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
Definition ConeConstraint.h:70
float GetTotalLambdaRotation() const
Definition ConeConstraint.h:103
float GetCosHalfConeAngle() const
Definition ConeConstraint.h:99
virtual EConstraintSubType GetSubType() const override
Get the sub type of a constraint.
Definition ConeConstraint.h:78
void SetHalfConeAngle(float inHalfConeAngle)
Update maximum angle between body 1 and 2 (see ConeConstraintSettings)
Definition ConeConstraint.h:98
Vec3 GetTotalLambdaPosition() const
Definition ConeConstraint.h:102
Cone constraint settings, used to create a cone constraint.
Definition ConeConstraint.h:15
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
Definition PointConstraintPart.h:41
Definition Reference.h:107
Definition StateRecorder.h:105
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:17
static JPH_INLINE Vec3 sAxisX()
Vectors with the principal axis.
Definition Vec3.h:53
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:107