| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Vehicle/WheeledVehicleController.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
class JPH_EXPORT MotorcycleControllerSettings : public WheeledVehicleControllerSettings |
| 14 |
{ |
| 15 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, MotorcycleControllerSettings) |
| 16 |
|
| 17 |
public: |
| 18 |
|
| 19 |
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override; |
| 20 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 21 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 22 |
|
| 23 |
|
| 24 |
float mMaxLeanAngle = DegreesToRadians(45.0f); |
| 25 |
|
| 26 |
|
| 27 |
float mLeanSpringConstant = 5000.0f; |
| 28 |
|
| 29 |
|
| 30 |
float mLeanSpringDamping = 1000.0f; |
| 31 |
|
| 32 |
|
| 33 |
float mLeanSpringIntegrationCoefficient = 0.0f; |
| 34 |
|
| 35 |
|
| 36 |
float mLeanSpringIntegrationCoefficientDecay = 4.0f; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
float mLeanSmoothingFactor = 0.8f; |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
class JPH_EXPORT MotorcycleController : public WheeledVehicleController |
| 45 |
{ |
| 46 |
public: |
| 47 |
JPH_OVERRIDE_NEW_DELETE |
| 48 |
|
| 49 |
|
| 50 |
MotorcycleController(const MotorcycleControllerSettings &inSettings, VehicleConstraint &inConstraint); |
| 51 |
|
| 52 |
|
| 53 |
float GetWheelBase() const; |
| 54 |
|
| 55 |
|
| 56 |
void EnableLeanController(bool inEnable) { mEnableLeanController = inEnable; } |
| 57 |
|
| 58 |
|
| 59 |
bool IsLeanControllerEnabled() const { return mEnableLeanController; } |
| 60 |
|
| 61 |
|
| 62 |
void EnableLeanSteeringLimit(bool inEnable) { mEnableLeanSteeringLimit = inEnable; } |
| 63 |
bool IsLeanSteeringLimitEnabled() const { return mEnableLeanSteeringLimit; } |
| 64 |
|
| 65 |
|
| 66 |
void SetLeanSpringConstant(float inConstant) { mLeanSpringConstant = inConstant; } |
| 67 |
float GetLeanSpringConstant() const { return mLeanSpringConstant; } |
| 68 |
|
| 69 |
|
| 70 |
void SetLeanSpringDamping(float inDamping) { mLeanSpringDamping = inDamping; } |
| 71 |
float GetLeanSpringDamping() const { return mLeanSpringDamping; } |
| 72 |
|
| 73 |
|
| 74 |
void SetLeanSpringIntegrationCoefficient(float inCoefficient) { mLeanSpringIntegrationCoefficient = inCoefficient; } |
| 75 |
float GetLeanSpringIntegrationCoefficient() const { return mLeanSpringIntegrationCoefficient; } |
| 76 |
|
| 77 |
|
| 78 |
void SetLeanSpringIntegrationCoefficientDecay(float inDecay) { mLeanSpringIntegrationCoefficientDecay = inDecay; } |
| 79 |
float GetLeanSpringIntegrationCoefficientDecay() const { return mLeanSpringIntegrationCoefficientDecay; } |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
void SetLeanSmoothingFactor(float inFactor) { mLeanSmoothingFactor = inFactor; } |
| 84 |
float GetLeanSmoothingFactor() const { return mLeanSmoothingFactor; } |
| 85 |
|
| 86 |
|
| 87 |
virtual Ref<VehicleControllerSettings> GetSettings() const override; |
| 88 |
|
| 89 |
protected: |
| 90 |
|
| 91 |
virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override; |
| 92 |
virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) override; |
| 93 |
virtual void SaveState(StateRecorder &inStream) const override; |
| 94 |
virtual void RestoreState(StateRecorder &inStream) override; |
| 95 |
#ifdef JPH_DEBUG_RENDERER |
| 96 |
virtual void Draw(DebugRenderer *inRenderer) const override; |
| 97 |
#endif |
| 98 |
|
| 99 |
|
| 100 |
bool mEnableLeanController = true; |
| 101 |
bool mEnableLeanSteeringLimit = true; |
| 102 |
float mMaxLeanAngle; |
| 103 |
float mLeanSpringConstant; |
| 104 |
float mLeanSpringDamping; |
| 105 |
float mLeanSpringIntegrationCoefficient; |
| 106 |
float mLeanSpringIntegrationCoefficientDecay; |
| 107 |
float mLeanSmoothingFactor; |
| 108 |
|
| 109 |
|
| 110 |
Vec3 mTargetLean = Vec3::sZero(); |
| 111 |
|
| 112 |
|
| 113 |
float mLeanSpringIntegratedDeltaAngle = 0.0f; |
| 114 |
|
| 115 |
|
| 116 |
float mAppliedImpulse = 0.0f; |
| 117 |
}; |
| 118 |
|
| 119 |
JPH_NAMESPACE_END |