MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / SetDriveControl

Method SetDriveControl

Source/Engine/Physics/Actors/WheeledVehicle.cpp:47–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47void WheeledVehicle::SetDriveControl(DriveControlSettings value)
48{
49 value.RiseRateAcceleration = Math::Max(value.RiseRateAcceleration, 0.01f);
50 value.RiseRateBrake = Math::Max(value.RiseRateBrake, 0.01f);
51 value.RiseRateHandBrake = Math::Max(value.RiseRateHandBrake, 0.01f);
52 value.RiseRateSteer = Math::Max(value.RiseRateSteer, 0.01f);
53
54 value.FallRateAcceleration = Math::Max(value.FallRateAcceleration, 0.01f);
55 value.FallRateBrake = Math::Max(value.FallRateBrake, 0.01f);
56 value.FallRateHandBrake = Math::Max(value.FallRateHandBrake, 0.01f);
57 value.FallRateSteer = Math::Max(value.FallRateSteer, 0.01f);
58
59 // Don't let have an invalid steer vs speed list.
60 if (value.SteerVsSpeed.Count() < 1)
61 value.SteerVsSpeed.Add(WheeledVehicle::SteerControl());
62 else // PhysX backend requires the max of 4 values only
63 while (value.SteerVsSpeed.Count() > 4)
64 value.SteerVsSpeed.RemoveLast();
65
66 // Maintain all values clamped to have an ordered speed list
67 const int32 steerVsSpeedCount = value.SteerVsSpeed.Count();
68 for (int32 i = 0; i < steerVsSpeedCount; i++)
69 {
70 // Apply only on changed value
71 if (i > _driveControl.SteerVsSpeed.Count() - 1 ||
72 Math::NotNearEqual(_driveControl.SteerVsSpeed[i].Speed, value.SteerVsSpeed[i].Speed) ||
73 Math::NotNearEqual(_driveControl.SteerVsSpeed[i].Steer, value.SteerVsSpeed[i].Steer))
74 {
75 SteerControl& steerVsSpeed = value.SteerVsSpeed[i];
76 steerVsSpeed.Steer = Math::Saturate(steerVsSpeed.Steer);
77 steerVsSpeed.Speed = Math::Max(steerVsSpeed.Speed, 10.0f);
78
79 // Clamp speeds to have an ordered list
80 if (i >= 1)
81 {
82 const SteerControl& lastSteerVsSpeed = value.SteerVsSpeed[i - 1];
83 const SteerControl& nextSteerVsSpeed = value.SteerVsSpeed[Math::Clamp(i + 1, 0, steerVsSpeedCount - 1)];
84 const float minSpeed = lastSteerVsSpeed.Speed;
85 const float maxSpeed = nextSteerVsSpeed.Speed;
86
87 if (i + 1 < steerVsSpeedCount - 1)
88 steerVsSpeed.Speed = Math::Clamp(steerVsSpeed.Speed, minSpeed, maxSpeed);
89 else
90 steerVsSpeed.Speed = Math::Max(steerVsSpeed.Speed, minSpeed);
91 }
92 else if (steerVsSpeedCount > 1)
93 {
94 const SteerControl& nextSteerVsSpeed = value.SteerVsSpeed[i + 1];
95 steerVsSpeed.Speed = Math::Min(steerVsSpeed.Speed, nextSteerVsSpeed.Speed);
96 }
97 }
98 }
99
100 _driveControl = value;
101}
102
103void WheeledVehicle::SetWheels(const Array<Wheel>& value)
104{

Callers

nothing calls this directly

Calls 9

SteerControlClass · 0.85
SaturateFunction · 0.85
ClampFunction · 0.85
RemoveLastMethod · 0.80
MaxFunction · 0.50
NotNearEqualFunction · 0.50
MinFunction · 0.50
CountMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected