| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Constraints/TwoBodyConstraint.h> |
| 8 |
#include <Jolt/Physics/Constraints/ConstraintPart/IndependentAxisConstraintPart.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
class JPH_EXPORT PulleyConstraintSettings final : public TwoBodyConstraintSettings |
| 19 |
{ |
| 20 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PulleyConstraintSettings) |
| 21 |
|
| 22 |
public: |
| 23 |
|
| 24 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 25 |
|
| 26 |
|
| 27 |
virtual TwoBodyConstraint * Create(Body &inBody1, Body &inBody2) const override; |
| 28 |
|
| 29 |
|
| 30 |
EConstraintSpace mSpace = EConstraintSpace::WorldSpace; |
| 31 |
|
| 32 |
|
| 33 |
RVec3 mBodyPoint1 = RVec3::sZero(); |
| 34 |
|
| 35 |
|
| 36 |
RVec3 mFixedPoint1 = RVec3::sZero(); |
| 37 |
|
| 38 |
|
| 39 |
RVec3 mBodyPoint2 = RVec3::sZero(); |
| 40 |
|
| 41 |
|
| 42 |
RVec3 mFixedPoint2 = RVec3::sZero(); |
| 43 |
|
| 44 |
|
| 45 |
float mRatio = 1.0f; |
| 46 |
|
| 47 |
|
| 48 |
float mMinLength = 0.0f; |
| 49 |
|
| 50 |
|
| 51 |
float mMaxLength = -1.0f; |
| 52 |
|
| 53 |
protected: |
| 54 |
|
| 55 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
class JPH_EXPORT PulleyConstraint final : public TwoBodyConstraint |
| 60 |
{ |
| 61 |
public: |
| 62 |
JPH_OVERRIDE_NEW_DELETE |
| 63 |
|
| 64 |
|
| 65 |
PulleyConstraint(Body &inBody1, Body &inBody2, const PulleyConstraintSettings &inSettings); |
| 66 |
|
| 67 |
|
| 68 |
virtual EConstraintSubType GetSubType() const override { return EConstraintSubType::Pulley; } |
| 69 |
virtual void NotifyShapeChanged(const BodyID &inBodyID, Vec3Arg inDeltaCOM) override; |
| 70 |
virtual void SetupVelocityConstraint(float inDeltaTime) override; |
| 71 |
virtual void ResetWarmStart() override; |
| 72 |
virtual void WarmStartVelocityConstraint(float inWarmStartImpulseRatio) override; |
| 73 |
virtual bool SolveVelocityConstraint(float inDeltaTime) override; |
| 74 |
virtual bool SolvePositionConstraint(float inDeltaTime, float inBaumgarte) override; |
| 75 |
#ifdef JPH_DEBUG_RENDERER |
| 76 |
virtual void DrawConstraint(DebugRenderer *inRenderer) const override; |
| 77 |
#endif |
| 78 |
virtual void SaveState(StateRecorder &inStream) const override; |
| 79 |
virtual void RestoreState(StateRecorder &inStream) override; |
| 80 |
virtual Ref<ConstraintSettings> GetConstraintSettings() const override; |
| 81 |
|
| 82 |
|
| 83 |
virtual Mat44 GetConstraintToBody1Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition1); } |
| 84 |
virtual Mat44 GetConstraintToBody2Matrix() const override { return Mat44::sTranslation(mLocalSpacePosition2); } |
| 85 |
|
| 86 |
|
| 87 |
void SetLength(float inMinLength, float inMaxLength) { JPH_ASSERT(inMinLength >= 0.0f && inMinLength <= inMaxLength); mMinLength = inMinLength; mMaxLength = inMaxLength; } |
| 88 |
float GetMinLength() const { return mMinLength; } |
| 89 |
float GetMaxLength() const { return mMaxLength; } |
| 90 |
|
| 91 |
|
| 92 |
float GetCurrentLength() const { return Vec3(mWorldSpacePosition1 - mFixedPosition1).Length() + mRatio * Vec3(mWorldSpacePosition2 - mFixedPosition2).Length(); } |
| 93 |
|
| 94 |
|
| 95 |
inline float GetTotalLambdaPosition() const { return mIndependentAxisConstraintPart.GetTotalLambda(); } |
| 96 |
|
| 97 |
private: |
| 98 |
|
| 99 |
float CalculatePositionsNormalsAndLength(); |
| 100 |
|
| 101 |
|
| 102 |
void CalculateConstraintProperties(); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
Vec3 mLocalSpacePosition1; |
| 108 |
Vec3 mLocalSpacePosition2; |
| 109 |
|
| 110 |
|
| 111 |
RVec3 mFixedPosition1; |
| 112 |
RVec3 mFixedPosition2; |
| 113 |
|
| 114 |
|
| 115 |
float mRatio; |
| 116 |
|
| 117 |
|
| 118 |
float mMinLength; |
| 119 |
float mMaxLength; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
RVec3 mWorldSpacePosition1; |
| 125 |
RVec3 mWorldSpacePosition2; |
| 126 |
Vec3 mWorldSpaceNormal1; |
| 127 |
Vec3 mWorldSpaceNormal2; |
| 128 |
|
| 129 |
|
| 130 |
float mMinLambda; |
| 131 |
float mMaxLambda; |
| 132 |
|
| 133 |
|
| 134 |
IndependentAxisConstraintPart mIndependentAxisConstraintPart; |
| 135 |
}; |
| 136 |
|
| 137 |
JPH_NAMESPACE_END |