Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
VehicleTransmission.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
11
13
16{
17 Auto,
18 Manual,
19};
20
23{
24public:
26
27
28 void SaveBinaryState(StreamOut &inStream) const;
29
31 void RestoreBinaryState(StreamIn &inStream);
32
34 Array<float> mGearRatios { 2.66f, 1.78f, 1.3f, 1.0f, 0.74f };
36 float mSwitchTime = 0.5f;
37 float mClutchReleaseTime = 0.3f;
38 float mSwitchLatency = 0.5f;
39 float mShiftUpRPM = 4000.0f;
40 float mShiftDownRPM = 2000.0f;
41 float mClutchStrength = 10.0f;
42};
43
46{
47public:
51 void Set(int inCurrentGear, float inClutchFriction) { mCurrentGear = inCurrentGear; mClutchFriction = inClutchFriction; }
52
58 void Update(float inDeltaTime, float inCurrentRPM, float inForwardInput, bool inCanShiftUp);
59
61 int GetCurrentGear() const { return mCurrentGear; }
62
64 float GetClutchFriction() const { return mClutchFriction; }
65
67 bool IsSwitchingGear() const { return mGearSwitchTimeLeft > 0.0f; }
68
70 float GetCurrentRatio() const;
71
73 void SaveState(StateRecorder &inStream) const;
74 void RestoreState(StateRecorder &inStream);
75
76private:
77 int mCurrentGear = 0;
78 float mClutchFriction = 1.0f;
79 float mGearSwitchTimeLeft = 0.0f;
80 float mClutchReleaseTimeLeft = 0.0f;
81 float mGearSwitchLatencyTimeLeft = 0.0f;
82};
83
#define JPH_NAMESPACE_END
Definition Core.h:240
uint8_t uint8
Definition Core.h:310
#define JPH_NAMESPACE_BEGIN
Definition Core.h:234
std::vector< T, STLAllocator< T > > Array
Definition STLAllocator.h:81
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(class_name)
Definition SerializableObject.h:71
ETransmissionMode
How gears are shifted.
Definition VehicleTransmission.h:16
@ Auto
Automatically shift gear up and down.
@ Manual
Manual gear shift (call SetTransmissionInput)
Definition StateRecorder.h:15
Simple binary input stream.
Definition StreamIn.h:11
Simple binary output stream.
Definition StreamOut.h:11
Runtime data for transmission.
Definition VehicleTransmission.h:46
void RestoreState(StateRecorder &inStream)
Definition VehicleTransmission.cpp:150
int GetCurrentGear() const
Current gear, -1 = reverse, 0 = neutral, 1 = 1st gear etc.
Definition VehicleTransmission.h:61
float GetClutchFriction() const
Value between 0 and 1 indicating how much friction the clutch gives (0 = no friction,...
Definition VehicleTransmission.h:64
void Set(int inCurrentGear, float inClutchFriction)
Definition VehicleTransmission.h:51
void SaveState(StateRecorder &inStream) const
Saving state for replay.
Definition VehicleTransmission.cpp:141
float GetCurrentRatio() const
Return the transmission ratio based on the current gear (ratio between engine and differential)
Definition VehicleTransmission.cpp:131
void Update(float inDeltaTime, float inCurrentRPM, float inForwardInput, bool inCanShiftUp)
Definition VehicleTransmission.cpp:51
bool IsSwitchingGear() const
If the auto box is currently switching gears.
Definition VehicleTransmission.h:67
Configuration for the transmission of a vehicle (gear box)
Definition VehicleTransmission.h:23
float mClutchReleaseTime
How long it takes to release the clutch (go to full friction), only used in auto mode.
Definition VehicleTransmission.h:37
void RestoreBinaryState(StreamIn &inStream)
Restores the contents in binary form to inStream.
Definition VehicleTransmission.cpp:38
Array< float > mGearRatios
Ratio in rotation rate between engine and gear box, first element is 1st gear, 2nd element 2nd gear e...
Definition VehicleTransmission.h:34
ETransmissionMode mMode
How to switch gears.
Definition VehicleTransmission.h:33
float mClutchStrength
Strength of the clutch when fully engaged. Total torque a clutch applies is Torque = ClutchStrength *...
Definition VehicleTransmission.h:41
float mSwitchLatency
How long to wait after releasing the clutch before another switch is attempted (s),...
Definition VehicleTransmission.h:38
float mShiftUpRPM
If RPM of engine is bigger then this we will shift a gear up, only used in auto mode.
Definition VehicleTransmission.h:39
float mShiftDownRPM
If RPM of engine is smaller then this we will shift a gear down, only used in auto mode.
Definition VehicleTransmission.h:40
Array< float > mReverseGearRatios
Ratio in rotation rate between engine and gear box when driving in reverse.
Definition VehicleTransmission.h:35
void SaveBinaryState(StreamOut &inStream) const
Saves the contents in binary form to inStream.
Definition VehicleTransmission.cpp:25
float mSwitchTime
How long it takes to switch gears (s), only used in auto mode.
Definition VehicleTransmission.h:36