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{
15public:
17
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
24 float mMaxLeanAngle = DegreesToRadians(45.0f);
25
27 float mLeanSpringConstant = 5000.0f;
28
30 float mLeanSpringDamping = 1000.0f;
31
33 float mLeanSpringIntegrationCoefficient = 0.0f;
34
36 float mLeanSpringIntegrationCoefficientDecay = 4.0f;
37
40 float mLeanSmoothingFactor = 0.8f;
41};
42
45{
46public:
48
51
53 float GetWheelBase() const;
54
56 void EnableLeanController(bool inEnable) { mEnableLeanController = inEnable; }
57
59 bool IsLeanControllerEnabled() const { return mEnableLeanController; }
60
61protected:
62 // See: VehicleController
63 virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override;
64 virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) override;
65 virtual void SaveState(StateRecorder& inStream) const override;
66 virtual void RestoreState(StateRecorder& inStream) override;
67#ifdef JPH_DEBUG_RENDERER
68 virtual void Draw(DebugRenderer *inRenderer) const override;
69#endif // JPH_DEBUG_RENDERER
70
71 // Configuration properties
72 bool mEnableLeanController = true;
79
80 // Run-time calculated target lean vector
81 Vec3 mTargetLean = Vec3::sZero();
82
83 // Integrated error for the lean spring
84 float mLeanSpringIntegratedDeltaAngle = 0.0f;
85
86 // Run-time total angular impulse applied to turn the cycle towards the target lean angle
87 float mAppliedImpulse = 0.0f;
88};
89
#define JPH_EXPORT
Definition: Core.h:214
#define JPH_NAMESPACE_END
Definition: Core.h:354
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:348
constexpr float DegreesToRadians(float inV)
Convert a value from degrees to radians.
Definition: Math.h:13
#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
Simple triangle renderer for debugging purposes.
Definition: DebugRenderer.h:30
Runtime controller class.
Definition: MotorcycleController.h:45
float mLeanSpringIntegrationCoefficient
Definition: MotorcycleController.h:76
bool IsLeanControllerEnabled() const
Check if the lean spring is enabled.
Definition: MotorcycleController.h:59
float mMaxLeanAngle
Definition: MotorcycleController.h:73
float mLeanSpringConstant
Definition: MotorcycleController.h:74
float mLeanSmoothingFactor
Definition: MotorcycleController.h:78
float mLeanSpringIntegrationCoefficientDecay
Definition: MotorcycleController.h:77
float mLeanSpringDamping
Definition: MotorcycleController.h:75
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
Definition: MotorcycleController.h:14
Definition: PhysicsSystem.h:28
Definition: StateRecorder.h:48
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
Definition: Vec3.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
Definition: VehicleConstraint.h:66
Runtime data for interface that controls acceleration / decelleration of the vehicle.
Definition: VehicleController.h:41
Runtime controller class.
Definition: WheeledVehicleController.h:90
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:156
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override
Create an instance of the vehicle controller class.
Definition: WheeledVehicleController.cpp:137
virtual void SaveBinaryState(StreamOut &inStream) const override
Saves the contents of the controller settings in binary form to inStream.
Definition: WheeledVehicleController.cpp:142