29#ifndef PX_VEHICLE_UTIL_CONTROL_H
30#define PX_VEHICLE_UTIL_CONTROL_H
32#include "vehicle/PxVehicleSDK.h"
33#include "vehicle/PxVehicleDrive4W.h"
34#include "vehicle/PxVehicleDriveNW.h"
35#include "vehicle/PxVehicleDriveTank.h"
44 void testValidAnalogValue(
const PxF32 actualValue,
const PxF32 minVal,
const PxF32 maxVal,
const char* errorString);
55 static PX_FORCE_INLINE float feedbackFilter(
float val,
float& memory,
float sharpness)
57 if(sharpness<0.0f) sharpness = 0.0f;
58 else if(sharpness>1.0f) sharpness = 1.0f;
59 return memory = val * sharpness + memory * (1.0f - sharpness);
63 const PxF32 vzAbs,
const PxF32 timestep)
const
65 const PxF32 targetMaxSteer = (isVehicleInAir ? 1.0f : steerVsForwardSpeedTable.getYVal(vzAbs));
67 return targetMaxSteer;
69 return feedbackFilter(targetMaxSteer, mFilteredMaxSteer, mSharpness*timestep);
73 mutable PxReal mFilteredMaxSteer;
85 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
90 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
103 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
108 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
122 for(PxU32 i=0;i<PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS;i++)
124 mRawDigitalInputs[i]=
false;
125 mRawAnalogInputs[i]=0.0f;
140 void setDigitalAccel(
const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
146 void setDigitalBrake(
const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
152 void setDigitalHandbrake(
const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
158 void setDigitalSteerLeft(
const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
164 void setDigitalSteerRight(
const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
171 bool getDigitalAccel()
const {
return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
177 bool getDigitalBrake()
const {
return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
183 bool getDigitalHandbrake()
const {
return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
189 bool getDigitalSteerLeft()
const {
return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT];}
195 bool getDigitalSteerRight()
const {
return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
205 testValidAnalogValue(accel, 0.0f, 1.0f,
"Analog accel must be in range (0,1)");
207 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accel;
217 testValidAnalogValue(brake, 0.0f, 1.0f,
"Analog brake must be in range (0,1)");
219 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brake;
229 testValidAnalogValue(handbrake, 0.0f, 1.0f,
"Analog handbrake must be in range (0,1)");
231 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrake;
241 testValidAnalogValue(steer, -1.0f, 1.0f,
"Analog steer must be in range (-1,1)");
243 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steer;
250 PxReal
getAnalogAccel()
const {
return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
256 PxReal
getAnalogBrake()
const {
return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
262 PxReal
getAnalogHandbrake()
const {
return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
267 PxReal
getAnalogSteer()
const {
return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
273 void setGearUp(
const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
279 void setGearDown(
const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
295 bool mRawDigitalInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
296 PxReal mRawAnalogInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
315 (
const PxVehicleKeySmoothingData& keySmoothing,
const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
316 const PxVehicleDrive4WRawInputData& rawInputData,
const PxReal timestep,
const bool isVehicleInAir,
317 PxVehicleDrive4W& focusVehicle,
const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(),
333 (
const PxVehiclePadSmoothingData& padSmoothing,
const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
334 const PxVehicleDrive4WRawInputData& rawInputData,
const PxReal timestep,
const bool isVehicleInAir,
335 PxVehicleDrive4W& focusVehicle,
const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(),
399 for(PxU32 i=0;i<PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS;i++)
401 mRawAnalogInputs[i]=0.0f;
402 mRawDigitalInputs[i]=
false;
426 void setDigitalAccel(
const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
432 void setDigitalLeftThrust(
const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=b;}
438 void setDigitalRightThrust(
const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=b;}
444 void setDigitalLeftBrake(
const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=b;}
450 void setDigitalRightBrake(
const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=b;}
456 bool getDigitalAccel()
const {
return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
462 bool getDigitalLeftThrust()
const {
return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];}
468 bool getDigitalRightThrust()
const {
return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];}
474 bool getDigitalLeftBrake()
const {
return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];}
480 bool getDigitalRightBrake()
const {
return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];}
491 testValidAnalogValue(accel, 0.0f, 1.0f,
"Tank analog accel must be in range (-1,1)");
493 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=accel;
504 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
506 testValidAnalogValue(leftThrust, -1.0f, 1.0f,
"Tank left thrust must be in range (-1,1) in eSPECIAL mode.");
510 testValidAnalogValue(leftThrust, 0.0f, 1.0f,
"Tank left thrust must be in range (0,1) in eSTANDARD mode.");
513 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=leftThrust;
524 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
526 testValidAnalogValue(rightThrust, -1.0f, 1.0f,
"Tank right thrust must be in range (-1,1) in eSPECIAL mode.");
530 testValidAnalogValue(rightThrust, 0.0f, 1.0f,
"Tank right thrust must be in range (0,1) in eSTANDARD mode.");
533 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=rightThrust;
544 testValidAnalogValue(leftBrake, 0.0f, 1.0f,
"Tank left brake must be in range (0,1).");
546 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=leftBrake;
557 testValidAnalogValue(rightBrake, 0.0f, 1.0f,
"Tank right brake must be in range (0,1).");
559 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake;
568 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
577 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];
586 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];
595 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];
604 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];
633 PxVehicleDriveTankControlModel::Enum mMode;
635 PxReal mRawAnalogInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
636 bool mRawDigitalInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
651(
const PxVehicleKeySmoothingData& keySmoothing,
652 const PxVehicleDriveTankRawInputData& rawInputData,
653 const PxReal timestep,
654 PxVehicleDriveTank& focusVehicle);
666(
const PxVehiclePadSmoothingData& padSmoothing,
667 const PxVehicleDriveTankRawInputData& rawInputData,
668 const PxReal timestep,
669 PxVehicleDriveTank& focusVehicle);
Definition PxCoreUtilityTypes.h:113
3 Element vector class.
Definition PxVec3.h:50
Data structure with instanced dynamics data and configuration data of a vehicle with up to PX_MAX_NB_...
Definition PxVehicleDriveNW.h:131
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_DEPRECATED void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs(const PxVehicleKeySmoothingData &keySmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W &focusVehicle, const PxVehicleSteerFilter &steerFilter=PxVehicleSteerFilter(), const PxVec3 &forwardAxis=PxVehicleGetDefaultContext().forwardAxis)
Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital input...
Definition VehicleUtilControl.cpp:245
PX_DEPRECATED void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs(const PxVehicleKeySmoothingData &keySmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW &focusVehicle, const PxVehicleSteerFilter &steerFilter=PxVehicleSteerFilter(), const PxVec3 &forwardAxis=PxVehicleGetDefaultContext().forwardAxis)
Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital input...
Definition VehicleUtilControl.cpp:267
PX_DEPRECATED void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs(const PxVehiclePadSmoothingData &padSmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W &focusVehicle, const PxVehicleSteerFilter &steerFilter=PxVehicleSteerFilter(), const PxVec3 &forwardAxis=PxVehicleGetDefaultContext().forwardAxis)
Used to smooth and set analog vehicle control values from analog inputs (gamepad)....
Definition VehicleUtilControl.cpp:255
PX_DEPRECATED void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs(const PxVehicleKeySmoothingData &keySmoothing, const PxVehicleDriveTankRawInputData &rawInputData, const PxReal timestep, PxVehicleDriveTank &focusVehicle)
Used to smooth and set analog tank control values from digital inputs (keyboard). Also used to set bo...
Definition VehicleUtilControl.cpp:402
PX_DEPRECATED const PxVehicleContext & PxVehicleGetDefaultContext()
Get the default vehicle context.
Definition PxVehicleUpdate.cpp:120
PX_DEPRECATED void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs(const PxVehiclePadSmoothingData &padSmoothing, const PxVehicleDriveTankRawInputData &rawInputData, const PxReal timestep, PxVehicleDriveTank &focusVehicle)
Used to smooth and set analog tank control values from analog inputs (gamepad). Also used to set bool...
Definition VehicleUtilControl.cpp:289
PX_DEPRECATED void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs(const PxVehiclePadSmoothingData &padSmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW &focusVehicle, const PxVehicleSteerFilter &steerFilter=PxVehicleSteerFilter(), const PxVec3 &forwardAxis=PxVehicleGetDefaultContext().forwardAxis)
Used to smooth and set analog vehicle control values from analog inputs (gamepad)....
Definition VehicleUtilControl.cpp:277
Used to produce smooth vehicle driving control values from key inputs.
Definition PxVehicleUtilControl.h:81
Used to produce smooth analog vehicle control values from analog inputs.
Definition PxVehicleUtilControl.h:99
Used to produce smooth steering values in the presence of discontinuities when a vehicle e....
Definition PxVehicleUtilControl.h:52