Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
TrackedVehicleController.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
12
14
15class PhysicsSystem;
16
19{
20public:
22
23 // See: WheelSettings
24 virtual void SaveBinaryState(StreamOut &inStream) const override;
25 virtual void RestoreBinaryState(StreamIn &inStream) override;
26
27 float mLongitudinalFriction = 4.0f;
28 float mLateralFriction = 2.0f;
29};
30
32class JPH_EXPORT WheelTV : public Wheel
33{
34public:
36
38 explicit WheelTV(const WheelSettingsTV &inWheel);
39
41 const WheelSettingsTV * GetSettings() const { return static_cast<const WheelSettingsTV *>(mSettings.GetPtr()); }
42
44 void CalculateAngularVelocity(const VehicleConstraint &inConstraint);
45
47 void Update(uint inWheelIndex, float inDeltaTime, const VehicleConstraint &inConstraint);
48
49 int mTrackIndex = -1;
50 float mCombinedLongitudinalFriction = 0.0f;
51 float mCombinedLateralFriction = 0.0f;
52 float mBrakeImpulse = 0.0f;
53};
54
60{
61public:
63
64 // Constructor
66
67 // See: VehicleControllerSettings
68 virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override;
69 virtual void SaveBinaryState(StreamOut &inStream) const override;
70 virtual void RestoreBinaryState(StreamIn &inStream) override;
71
74 VehicleTrackSettings mTracks[(int)ETrackSide::Num];
75};
76
79{
80public:
82
85
91 void SetDriverInput(float inForward, float inLeftRatio, float inRightRatio, float inBrake) { JPH_ASSERT(inLeftRatio != 0.0f && inRightRatio != 0.0f); mForwardInput = inForward; mLeftRatio = inLeftRatio; mRightRatio = inRightRatio; mBrakeInput = inBrake; }
92
94 void SetForwardInput(float inForward) { mForwardInput = inForward; }
95 float GetForwardInput() const { return mForwardInput; }
96
98 void SetLeftRatio(float inLeftRatio) { JPH_ASSERT(inLeftRatio != 0.0f); mLeftRatio = inLeftRatio; }
99 float GetLeftRatio() const { return mLeftRatio; }
100
102 void SetRightRatio(float inRightRatio) { JPH_ASSERT(inRightRatio != 0.0f); mRightRatio = inRightRatio; }
103 float GetRightRatio() const { return mRightRatio; }
104
106 void SetBrakeInput(float inBrake) { mBrakeInput = inBrake; }
107 float GetBrakeInput() const { return mBrakeInput; }
108
110 const VehicleEngine & GetEngine() const { return mEngine; }
111
113 VehicleEngine & GetEngine() { return mEngine; }
114
116 const VehicleTransmission & GetTransmission() const { return mTransmission; }
117
119 VehicleTransmission & GetTransmission() { return mTransmission; }
120
122 const VehicleTracks & GetTracks() const { return mTracks; }
123
125 VehicleTracks & GetTracks() { return mTracks; }
126
127#ifdef JPH_DEBUG_RENDERER
129 void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; }
130#endif // JPH_DEBUG_RENDERER
131
132protected:
134 void SyncLeftRightTracks();
135
136 // See: VehicleController
137 virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const override { JPH_ASSERT(IsKindOf(&inWheel, JPH_RTTI(WheelSettingsTV))); return new WheelTV(static_cast<const WheelSettingsTV &>(inWheel)); }
138 virtual bool AllowSleep() const override;
139 virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override;
140 virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override;
141 virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) override;
142 virtual void SaveState(StateRecorder &inStream) const override;
143 virtual void RestoreState(StateRecorder &inStream) override;
144#ifdef JPH_DEBUG_RENDERER
145 virtual void Draw(DebugRenderer *inRenderer) const override;
146#endif // JPH_DEBUG_RENDERER
147
148 // Control information
149 float mForwardInput = 0.0f;
150 float mLeftRatio = 1.0f;
151 float mRightRatio = 1.0f;
152 float mBrakeInput = 0.0f;
153
154 // Simulation information
158
159#ifdef JPH_DEBUG_RENDERER
160 // Debug settings
161 Vec3 mRPMMeterPosition { 0, 1, 0 };
162 float mRPMMeterSize = 0.5f;
163#endif // JPH_DEBUG_RENDERER
164};
165
#define JPH_EXPORT
Definition: Core.h:227
unsigned int uint
Definition: Core.h:439
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
bool IsKindOf(const Type *inObject, const RTTI *inRTTI)
Check if inObject is or is derived from DstType.
Definition: RTTI.h:365
#define JPH_RTTI(class_name)
Definition: RTTI.h:315
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition: SerializableObject.h:100
VehicleTrack[(int) ETrackSide::Num] VehicleTracks
Definition: VehicleTrack.h:54
Definition: DebugRenderer.h:47
Definition: PhysicsSystem.h:29
Definition: StateRecorder.h:48
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
Runtime controller class for vehicle with tank tracks.
Definition: TrackedVehicleController.h:79
VehicleEngine mEngine
Engine state of the vehicle.
Definition: TrackedVehicleController.h:155
VehicleTracks mTracks
Tracks of the vehicle.
Definition: TrackedVehicleController.h:157
const VehicleTransmission & GetTransmission() const
Get current transmission state.
Definition: TrackedVehicleController.h:116
const VehicleTracks & GetTracks() const
Get the tracks this vehicle has.
Definition: TrackedVehicleController.h:122
float GetLeftRatio() const
Definition: TrackedVehicleController.h:99
void SetRightRatio(float inRightRatio)
Value between -1 and 1 indicating an extra multiplier to the rotation rate of the right track (used f...
Definition: TrackedVehicleController.h:102
float GetBrakeInput() const
Definition: TrackedVehicleController.h:107
float GetRightRatio() const
Definition: TrackedVehicleController.h:103
VehicleTransmission mTransmission
Transmission state of the vehicle.
Definition: TrackedVehicleController.h:156
virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const override
Definition: TrackedVehicleController.h:137
void SetRPMMeter(Vec3Arg inPosition, float inSize)
Debug drawing of RPM meter.
Definition: TrackedVehicleController.h:129
VehicleTracks & GetTracks()
Get the tracks this vehicle has (writable interface, allows you to make changes to the configuration ...
Definition: TrackedVehicleController.h:125
void SetLeftRatio(float inLeftRatio)
Value between -1 and 1 indicating an extra multiplier to the rotation rate of the left track (used fo...
Definition: TrackedVehicleController.h:98
const VehicleEngine & GetEngine() const
Get current engine state.
Definition: TrackedVehicleController.h:110
float GetForwardInput() const
Definition: TrackedVehicleController.h:95
VehicleEngine & GetEngine()
Get current engine state (writable interface, allows you to make changes to the configuration which w...
Definition: TrackedVehicleController.h:113
void SetBrakeInput(float inBrake)
Value between 0 and 1 indicating how strong the brake pedal is pressed.
Definition: TrackedVehicleController.h:106
void SetDriverInput(float inForward, float inLeftRatio, float inRightRatio, float inBrake)
Definition: TrackedVehicleController.h:91
void SetForwardInput(float inForward)
Value between -1 and 1 for auto transmission and value between 0 and 1 indicating desired driving dir...
Definition: TrackedVehicleController.h:94
VehicleTransmission & GetTransmission()
Get current transmission state (writable interface, allows you to make changes to the configuration w...
Definition: TrackedVehicleController.h:119
Definition: TrackedVehicleController.h:60
VehicleEngineSettings mEngine
The properties of the engine.
Definition: TrackedVehicleController.h:72
VehicleTransmissionSettings mTransmission
The properties of the transmission (aka gear box)
Definition: TrackedVehicleController.h:73
Definition: Vec3.h:16
Definition: VehicleConstraint.h:66
Runtime data for interface that controls acceleration / deceleration of the vehicle.
Definition: VehicleController.h:41
Basic settings object for interface that controls acceleration / deceleration of the vehicle.
Definition: VehicleController.h:25
Runtime data for engine.
Definition: VehicleEngine.h:44
Generic properties for a vehicle engine.
Definition: VehicleEngine.h:21
Generic properties for tank tracks.
Definition: VehicleTrack.h:25
Runtime data for transmission.
Definition: VehicleTransmission.h:46
Configuration for the transmission of a vehicle (gear box)
Definition: VehicleTransmission.h:23
Base class for runtime data for a wheel, each VehicleController can implement a derived class of this...
Definition: Wheel.h:46
Base class for wheel settings, each VehicleController can implement a derived class of this.
Definition: Wheel.h:19
virtual void SaveBinaryState(StreamOut &inStream) const
Saves the contents in binary form to inStream.
Definition: Wheel.cpp:32
virtual void RestoreBinaryState(StreamIn &inStream)
Restores the contents in binary form to inStream.
Definition: Wheel.cpp:49
WheelSettings object specifically for TrackedVehicleController.
Definition: TrackedVehicleController.h:19
Wheel object specifically for TrackedVehicleController.
Definition: TrackedVehicleController.h:33
const WheelSettingsTV * GetSettings() const
Override GetSettings and cast to the correct class.
Definition: TrackedVehicleController.h:41