Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MotorcycleController.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
14{
16
17public:
18 // See: VehicleControllerSettings
19 virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override;
20 virtual void SaveBinaryState(StreamOut &inStream) const override;
21 virtual void RestoreBinaryState(StreamIn &inStream) override;
22
25
27 float mLeanSpringConstant = 5000.0f;
28
30 float mLeanSpringDamping = 1000.0f;
31
34
37
41};
42
45{
46public:
48
51
53 float GetWheelBase() const;
54
56 void EnableLeanController(bool inEnable) { mEnableLeanController = inEnable; }
57
60
62 void EnableLeanSteeringLimit(bool inEnable) { mEnableLeanSteeringLimit = inEnable; }
64
66 void SetLeanSpringConstant(float inConstant) { mLeanSpringConstant = inConstant; }
68
70 void SetLeanSpringDamping(float inDamping) { mLeanSpringDamping = inDamping; }
71 float GetLeanSpringDamping() const { return mLeanSpringDamping; }
72
74 void SetLeanSpringIntegrationCoefficient(float inCoefficient) { mLeanSpringIntegrationCoefficient = inCoefficient; }
76
80
83 void SetLeanSmoothingFactor(float inFactor) { mLeanSmoothingFactor = inFactor; }
85
86 // See: VehicleController
87 virtual Ref<VehicleControllerSettings> GetSettings() const override;
88
89protected:
90 // See: VehicleController
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 // JPH_DEBUG_RENDERER
98
99 // Configuration properties
108
109 // Run-time calculated target lean vector
111
112 // Integrated error for the lean spring
114
115 // Run-time total angular impulse applied to turn the cycle towards the target lean angle
116 float mAppliedImpulse = 0.0f;
117};
118
#define JPH_EXPORT
Definition Core.h:275
#define JPH_NAMESPACE_END
Definition Core.h:425
#define JPH_NAMESPACE_BEGIN
Definition Core.h:419
JPH_INLINE constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition Math.h:16
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:109
Definition DebugRenderer.h:47
float mLeanSpringIntegratedDeltaAngle
Definition MotorcycleController.h:113
float mLeanSpringIntegrationCoefficient
Definition MotorcycleController.h:105
void SetLeanSmoothingFactor(float inFactor)
Definition MotorcycleController.h:83
bool mEnableLeanController
Definition MotorcycleController.h:100
bool IsLeanControllerEnabled() const
Check if the lean spring is enabled.
Definition MotorcycleController.h:59
float GetLeanSpringIntegrationCoefficientDecay() const
Definition MotorcycleController.h:79
float mMaxLeanAngle
Definition MotorcycleController.h:102
float mLeanSpringConstant
Definition MotorcycleController.h:103
void EnableLeanSteeringLimit(bool inEnable)
Enable or disable the lean steering limit. When enabled (default) the steering angle is limited based...
Definition MotorcycleController.h:62
float mLeanSmoothingFactor
Definition MotorcycleController.h:107
float mLeanSpringIntegrationCoefficientDecay
Definition MotorcycleController.h:106
float GetLeanSpringConstant() const
Definition MotorcycleController.h:67
float mLeanSpringDamping
Definition MotorcycleController.h:104
Vec3 mTargetLean
Definition MotorcycleController.h:110
float GetLeanSmoothingFactor() const
Definition MotorcycleController.h:84
void SetLeanSpringConstant(float inConstant)
Spring constant for the lean spring.
Definition MotorcycleController.h:66
void SetLeanSpringDamping(float inDamping)
Spring damping constant for the lean spring.
Definition MotorcycleController.h:70
float GetWheelBase() const
Get the distance between the front and back wheels.
Definition MotorcycleController.cpp:70
bool IsLeanSteeringLimitEnabled() const
Definition MotorcycleController.h:63
void EnableLeanController(bool inEnable)
Enable or disable the lean spring. This allows you to temporarily disable the lean spring to allow th...
Definition MotorcycleController.h:56
bool mEnableLeanSteeringLimit
Definition MotorcycleController.h:101
float GetLeanSpringIntegrationCoefficient() const
Definition MotorcycleController.h:75
float mAppliedImpulse
Definition MotorcycleController.h:116
void SetLeanSpringIntegrationCoefficientDecay(float inDecay)
How much to decay the angle integral when the wheels are not touching the floor: new_value = e^(-deca...
Definition MotorcycleController.h:78
float GetLeanSpringDamping() const
Definition MotorcycleController.h:71
JPH_OVERRIDE_NEW_DELETE MotorcycleController(const MotorcycleControllerSettings &inSettings, VehicleConstraint &inConstraint)
Constructor.
Definition MotorcycleController.cpp:59
void SetLeanSpringIntegrationCoefficient(float inCoefficient)
The lean spring applies an additional force equal to this coefficient * Integral(delta angle,...
Definition MotorcycleController.h:74
Definition MotorcycleController.h:14
float mMaxLeanAngle
How far we're willing to make the bike lean over in turns (in radians).
Definition MotorcycleController.h:24
float mLeanSpringDamping
Spring damping constant for the lean spring.
Definition MotorcycleController.h:30
float mLeanSpringIntegrationCoefficient
The lean spring applies an additional force equal to this coefficient * Integral(delta angle,...
Definition MotorcycleController.h:33
float mLeanSpringConstant
Spring constant for the lean spring.
Definition MotorcycleController.h:27
float mLeanSpringIntegrationCoefficientDecay
How much to decay the angle integral when the wheels are not touching the floor: new_value = e^(-deca...
Definition MotorcycleController.h:36
float mLeanSmoothingFactor
Definition MotorcycleController.h:40
Definition PhysicsSystem.h:30
Definition Reference.h:107
Definition StateRecorder.h:110
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
Definition Vec3.h:17
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:103
Definition VehicleConstraint.h:66
Runtime data for interface that controls acceleration / deceleration of the vehicle.
Definition VehicleController.h:41
friend class VehicleConstraint
Definition VehicleController.h:58
JPH_OVERRIDE_NEW_DELETE WheeledVehicleController(const WheeledVehicleControllerSettings &inSettings, VehicleConstraint &inConstraint)
Constructor.
Definition WheeledVehicleController.cpp:178
Definition WheeledVehicleController.h:73
virtual void RestoreBinaryState(StreamIn &inStream) override
Restore the contents of the controller settings in binary form from inStream.
Definition WheeledVehicleController.cpp:163
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override
Create an instance of the vehicle controller class.
Definition WheeledVehicleController.cpp:144
virtual void SaveBinaryState(StreamOut &inStream) const override
Saves the contents of the controller settings in binary form to inStream.
Definition WheeledVehicleController.cpp:149