| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Vehicle/VehicleConstraint.h> |
| 8 |
#include <Jolt/Physics/Vehicle/VehicleController.h> |
| 9 |
#include <Jolt/Physics/Vehicle/VehicleEngine.h> |
| 10 |
#include <Jolt/Physics/Vehicle/VehicleTransmission.h> |
| 11 |
#include <Jolt/Physics/Vehicle/VehicleTrack.h> |
| 12 |
|
| 13 |
JPH_NAMESPACE_BEGIN |
| 14 |
|
| 15 |
class PhysicsSystem; |
| 16 |
|
| 17 |
|
| 18 |
class JPH_EXPORT WheelSettingsTV : public WheelSettings |
| 19 |
{ |
| 20 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, WheelSettingsTV) |
| 21 |
|
| 22 |
public: |
| 23 |
|
| 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 |
|
| 31 |
|
| 32 |
class JPH_EXPORT WheelTV : public Wheel |
| 33 |
{ |
| 34 |
public: |
| 35 |
JPH_OVERRIDE_NEW_DELETE |
| 36 |
|
| 37 |
|
| 38 |
explicit WheelTV(const WheelSettingsTV &inWheel); |
| 39 |
|
| 40 |
|
| 41 |
const WheelSettingsTV * GetSettings() const { return StaticCast<WheelSettingsTV>(mSettings); } |
| 42 |
|
| 43 |
|
| 44 |
void CalculateAngularVelocity(const VehicleConstraint &inConstraint); |
| 45 |
|
| 46 |
|
| 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 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class JPH_EXPORT TrackedVehicleControllerSettings : public VehicleControllerSettings |
| 60 |
{ |
| 61 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TrackedVehicleControllerSettings) |
| 62 |
|
| 63 |
public: |
| 64 |
|
| 65 |
TrackedVehicleControllerSettings(); |
| 66 |
|
| 67 |
|
| 68 |
virtual VehicleController * ConstructController(VehicleConstraint &inConstraint) const override; |
| 69 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 70 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 71 |
|
| 72 |
VehicleEngineSettings mEngine; |
| 73 |
VehicleTransmissionSettings mTransmission; |
| 74 |
VehicleTrackSettings mTracks[(int)ETrackSide::Num]; |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
class JPH_EXPORT TrackedVehicleController : public VehicleController |
| 79 |
{ |
| 80 |
public: |
| 81 |
JPH_OVERRIDE_NEW_DELETE |
| 82 |
|
| 83 |
|
| 84 |
TrackedVehicleController(const TrackedVehicleControllerSettings &inSettings, VehicleConstraint &inConstraint); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 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 |
|
| 93 |
|
| 94 |
void SetForwardInput(float inForward) { mForwardInput = inForward; } |
| 95 |
float GetForwardInput() const { return mForwardInput; } |
| 96 |
|
| 97 |
|
| 98 |
void SetLeftRatio(float inLeftRatio) { JPH_ASSERT(inLeftRatio != 0.0f); mLeftRatio = inLeftRatio; } |
| 99 |
float GetLeftRatio() const { return mLeftRatio; } |
| 100 |
|
| 101 |
|
| 102 |
void SetRightRatio(float inRightRatio) { JPH_ASSERT(inRightRatio != 0.0f); mRightRatio = inRightRatio; } |
| 103 |
float GetRightRatio() const { return mRightRatio; } |
| 104 |
|
| 105 |
|
| 106 |
void SetBrakeInput(float inBrake) { mBrakeInput = inBrake; } |
| 107 |
float GetBrakeInput() const { return mBrakeInput; } |
| 108 |
|
| 109 |
|
| 110 |
const VehicleEngine & GetEngine() const { return mEngine; } |
| 111 |
|
| 112 |
|
| 113 |
VehicleEngine & GetEngine() { return mEngine; } |
| 114 |
|
| 115 |
|
| 116 |
const VehicleTransmission & GetTransmission() const { return mTransmission; } |
| 117 |
|
| 118 |
|
| 119 |
VehicleTransmission & GetTransmission() { return mTransmission; } |
| 120 |
|
| 121 |
|
| 122 |
const VehicleTracks & GetTracks() const { return mTracks; } |
| 123 |
|
| 124 |
|
| 125 |
VehicleTracks & GetTracks() { return mTracks; } |
| 126 |
|
| 127 |
#ifdef JPH_DEBUG_RENDERER |
| 128 |
|
| 129 |
void SetRPMMeter(Vec3Arg inPosition, float inSize) { mRPMMeterPosition = inPosition; mRPMMeterSize = inSize; } |
| 130 |
#endif |
| 131 |
|
| 132 |
|
| 133 |
virtual Ref<VehicleControllerSettings> GetSettings() const override; |
| 134 |
|
| 135 |
protected: |
| 136 |
|
| 137 |
void SyncLeftRightTracks(); |
| 138 |
|
| 139 |
|
| 140 |
virtual Wheel * ConstructWheel(const WheelSettings &inWheel) const override { JPH_ASSERT(IsKindOf(&inWheel, JPH_RTTI(WheelSettingsTV))); return new WheelTV(static_cast<const WheelSettingsTV &>(inWheel)); } |
| 141 |
virtual bool AllowSleep() const override; |
| 142 |
virtual void PreCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override; |
| 143 |
virtual void PostCollide(float inDeltaTime, PhysicsSystem &inPhysicsSystem) override; |
| 144 |
virtual bool SolveLongitudinalAndLateralConstraints(float inDeltaTime) override; |
| 145 |
virtual void SaveState(StateRecorder &inStream) const override; |
| 146 |
virtual void RestoreState(StateRecorder &inStream) override; |
| 147 |
#ifdef JPH_DEBUG_RENDERER |
| 148 |
virtual void Draw(DebugRenderer *inRenderer) const override; |
| 149 |
#endif |
| 150 |
|
| 151 |
|
| 152 |
float mForwardInput = 0.0f; |
| 153 |
float mLeftRatio = 1.0f; |
| 154 |
float mRightRatio = 1.0f; |
| 155 |
float mBrakeInput = 0.0f; |
| 156 |
|
| 157 |
|
| 158 |
VehicleEngine mEngine; |
| 159 |
VehicleTransmission mTransmission; |
| 160 |
VehicleTracks mTracks; |
| 161 |
|
| 162 |
#ifdef JPH_DEBUG_RENDERER |
| 163 |
|
| 164 |
Vec3 mRPMMeterPosition { 0, 1, 0 }; |
| 165 |
float mRPMMeterSize = 0.5f; |
| 166 |
#endif |
| 167 |
}; |
| 168 |
|
| 169 |
JPH_NAMESPACE_END |