-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathvjolt_controller_vehicle.h
93 lines (67 loc) · 3.08 KB
/
vjolt_controller_vehicle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include "vjolt_object.h" // IJoltObjectDestroyedListener
#include "vjolt_environment.h" // IJoltPhysicsController
struct JoltPhysicsWheel
{
JoltPhysicsObject* pObject = nullptr;
bool InWater = false;
float Depth = 0.0f;
};
struct JoltPhysicsInternalVehicleState
{
bool EngineDisabled = false;
float BoostDelay = 0.0f;
float BoosterRemainingTime = 0.0f;
float LargestWheelRadius = 0.0f;
};
class JoltPhysicsVehicleController final : public IPhysicsVehicleController, public IJoltObjectDestroyedListener, public IJoltPhysicsController
{
public:
static constexpr int MaxWheels = VEHICLE_MAX_WHEEL_COUNT;
JoltPhysicsVehicleController( JoltPhysicsEnvironment *pEnvironment, JPH::PhysicsSystem *pPhysicsSystem, JoltPhysicsObject *pVehicleBodyObject, const vehicleparams_t ¶ms, unsigned int nVehicleType, IPhysicsGameTrace *pGameTrace );
~JoltPhysicsVehicleController() override;
void Update( float dt, vehicle_controlparams_t &controls ) override;
const vehicle_operatingparams_t & GetOperatingParams() override;
const vehicleparams_t & GetVehicleParams() override;
vehicleparams_t & GetVehicleParamsForChange() override;
float UpdateBooster( float dt ) override;
int GetWheelCount( void ) override;
IPhysicsObject * GetWheel( int index ) override;
bool GetWheelContactPoint( int index, Vector *pContactPoint, int *pSurfaceProps ) override;
void SetSpringLength( int wheelIndex, float length ) override;
void SetWheelFriction( int wheelIndex, float friction ) override;
void OnVehicleEnter( void ) override;
void OnVehicleExit( void ) override;
void SetEngineDisabled( bool bDisable ) override;
bool IsEngineDisabled( void ) override;
void GetCarSystemDebugData( vehicle_debugcarsystem_t &debugCarSystem ) override;
void VehicleDataReload() override;
public:
// IJoltObjectDestroyedListener
void OnJoltPhysicsObjectDestroyed( JoltPhysicsObject *pObject ) override;
float GetSpeed();
// IJoltPhysicsController
void OnPreSimulate( float flDeltaTime ) override;
void OnPostSimulate( float flDeltaTime ) override;
private:
void HandleBoostKey();
void HandleBoostDecay();
void CreateWheel( JPH::VehicleConstraintSettings &vehicleSettings, matrix3x4_t &bodyMatrix, int axleIdx, int wheelIdx );
void CreateWheels( JPH::VehicleConstraintSettings& vehicleSettings );
JPH::WheeledVehicleControllerSettings *CreateVehicleController();
JPH::WheeledVehicleController *GetWheeledVehicleController();
matrix3x4_t GetBodyMatrix() const;
void DetachObject();
JoltPhysicsEnvironment *m_pEnvironment = nullptr;
JPH::PhysicsSystem *m_pPhysicsSystem = nullptr;
JoltPhysicsObject *m_pCarBodyObject = nullptr;
vehicleparams_t m_VehicleParams = {};
unsigned int m_VehicleType = 0u;
vehicle_operatingparams_t m_OperatingParams = {};
vehicle_controlparams_t m_ControlParams = {};
std::vector< JoltPhysicsWheel > m_Wheels;
float m_TotalWheelMass = 0.0f;
JoltPhysicsInternalVehicleState m_InternalState;
JPH::Ref< JPH::VehicleConstraint > m_VehicleConstraint;
JPH::Ref< JPH::VehicleCollisionTester > m_Tester;
};