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
33 ETransmissionMode mMode = ETransmissionMode::Auto;
34 Array<float> mGearRatios { 2.66f, 1.78f, 1.3f, 1.0f, 0.74f };
35 Array<float> mReverseGearRatios { -2.90f };
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 bool AllowSleep() const { return mGearSwitchTimeLeft <= 0.0f && mClutchReleaseTimeLeft <= 0.0f && mGearSwitchLatencyTimeLeft <= 0.0f; }
74
76 void SaveState(StateRecorder &inStream) const;
77 void RestoreState(StateRecorder &inStream);
78
79private:
80 int mCurrentGear = 0;
81 float mClutchFriction = 1.0f;
82 float mGearSwitchTimeLeft = 0.0f;
83 float mClutchReleaseTimeLeft = 0.0f;
84 float mGearSwitchLatencyTimeLeft = 0.0f;
85};
86
std::uint8_t uint8
Definition: Core.h:440
#define JPH_EXPORT
Definition: Core.h:227
#define JPH_NAMESPACE_END
Definition: Core.h:367
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
#define JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(linkage, 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:48
Simple binary input stream.
Definition: StreamIn.h:13
Simple binary output stream.
Definition: StreamOut.h:13
Runtime data for transmission.
Definition: VehicleTransmission.h:46
bool AllowSleep() const
Only allow sleeping when the transmission is idle.
Definition: VehicleTransmission.h:73
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
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