PxVehicleUtilControl.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 #ifndef PX_VEHICLE_CONTROL_H
31 #define PX_VEHICLE_CONTROL_H
32 
35 #include "vehicle/PxVehicleSDK.h"
39 
40 
41 #if !PX_DOXYGEN
42 namespace physx
43 {
44 #endif
45 
46 #if PX_CHECKED
47  void testValidAnalogValue(const PxF32 actualValue, const PxF32 minVal, const PxF32 maxVal, const char* errorString);
48 #endif
49 
55 {
56 public:
57 
62 
67 };
69 
75 {
76 public:
77 
82 
87 };
89 
95 {
96 public:
97 
99  {
101  {
102  mRawDigitalInputs[i]=false;
103  mRawAnalogInputs[i]=0.0f;
104  }
105 
106  mGearUp = false;
107  mGearDown = false;
108  }
109 
111  {
112  }
113 
118  void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
119 
124  void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
125 
130  void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
131 
136  void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
137 
142  void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
143 
144 
149  bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
150 
155  bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
156 
162 
168 
174 
175 
180  void setAnalogAccel(const PxReal accel)
181  {
182 #if PX_CHECKED
183  testValidAnalogValue(accel, 0.0f, 1.0f, "Analog accel must be in range (0,1)");
184 #endif
185  mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accel;
186  }
187 
192  void setAnalogBrake(const PxReal brake)
193  {
194 #if PX_CHECKED
195  testValidAnalogValue(brake, 0.0f, 1.0f, "Analog brake must be in range (0,1)");
196 #endif
197  mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brake;
198  }
199 
204  void setAnalogHandbrake(const PxReal handbrake)
205  {
206 #if PX_CHECKED
207  testValidAnalogValue(handbrake, 0.0f, 1.0f, "Analog handbrake must be in range (0,1)");
208 #endif
209  mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrake;
210  }
211 
216  void setAnalogSteer(const PxReal steer)
217  {
218 #if PX_CHECKED
219  testValidAnalogValue(steer, -1.0f, 1.0f, "Analog steer must be in range (-1,1)");
220 #endif
222  }
223 
229 
235 
241 
246 
251  void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
252 
257  void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
258 
263  bool getGearUp() const {return mGearUp;}
264 
269  bool getGearDown() const {return mGearDown;}
270 
271 private:
272 
275 
276  bool mGearUp;
277  bool mGearDown;
278 };
279 
291  (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
292  const PxVehicleDrive4WRawInputData& rawInputData,
293  const PxReal timestep,
294  const bool isVehicleInAir,
295  PxVehicleDrive4W& focusVehicle);
296 
308  (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
309  const PxVehicleDrive4WRawInputData& rawInputData,
310  const PxReal timestep,
311  const bool isVehicleInAir,
312  PxVehicleDrive4W& focusVehicle);
313 
314 
320 {
321 public:
322 
325 };
326 
338  (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
339  const PxVehicleDriveNWRawInputData& rawInputData,
340  const PxReal timestep,
341  const bool isVehicleInAir,
342  PxVehicleDriveNW& focusVehicle);
343 
355  (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
356  const PxVehicleDriveNWRawInputData& rawInputData,
357  const PxReal timestep,
358  const bool isVehicleInAir,
359  PxVehicleDriveNW& focusVehicle);
360 
361 
367 {
368 public:
369 
371  : mMode(mode)
372  {
374  {
375  mRawAnalogInputs[i]=0.0f;
376  mRawDigitalInputs[i]=false;
377  }
378 
379  mGearUp=false;
380  mGearDown=false;
381  }
382 
384  {
385  }
386 
392  {
393  return mMode;
394  }
395 
400  void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
401 
407 
413 
419 
425 
430  bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
431 
437 
443 
449 
455 
456 
462  void setAnalogAccel(const PxF32 accel)
463  {
464 #if PX_CHECKED
465  testValidAnalogValue(accel, 0.0f, 1.0f, "Tank analog accel must be in range (-1,1)");
466 #endif
467  mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=accel;
468  }
469 
475  void setAnalogLeftThrust(const PxF32 leftThrust)
476  {
477 #if PX_CHECKED
479  {
480  testValidAnalogValue(leftThrust, -1.0f, 1.0f, "Tank left thrust must be in range (-1,1) in eSPECIAL mode.");
481  }
482  else
483  {
484  testValidAnalogValue(leftThrust, 0.0f, 1.0f, "Tank left thrust must be in range (0,1) in eSTANDARD mode.");
485  }
486 #endif
487  mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=leftThrust;
488  }
489 
495  void setAnalogRightThrust(const PxF32 rightThrust)
496  {
497 #if PX_CHECKED
499  {
500  testValidAnalogValue(rightThrust, -1.0f, 1.0f, "Tank right thrust must be in range (-1,1) in eSPECIAL mode.");
501  }
502  else
503  {
504  testValidAnalogValue(rightThrust, 0.0f, 1.0f, "Tank right thrust must be in range (0,1) in eSTANDARD mode.");
505  }
506 #endif
507  mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=rightThrust;
508  }
509 
515  void setAnalogLeftBrake(const PxF32 leftBrake)
516  {
517 #if PX_CHECKED
518  testValidAnalogValue(leftBrake, 0.0f, 1.0f, "Tank left brake must be in range (0,1).");
519 #endif
520  mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=leftBrake;
521  }
522 
528  void setAnalogRightBrake(const PxF32 rightBrake)
529  {
530 #if PX_CHECKED
531  testValidAnalogValue(rightBrake, 0.0f, 1.0f, "Tank right brake must be in range (0,1).");
532 #endif
533  mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake;
534  }
535 
541  {
542  return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
543  }
544 
550  {
552  }
553 
559  {
561  }
562 
568  {
570  }
571 
577  {
579  }
580 
585  void setGearUp(const bool gearUp) {mGearUp=gearUp;}
586 
591  void setGearDown(const bool gearDown) {mGearDown=gearDown;}
592 
597  bool getGearUp() const {return mGearUp;}
598 
603  bool getGearDown() const {return mGearDown;}
604 
605 private:
606 
608 
611 
612  bool mGearUp;
613  bool mGearDown;
614 };
615 
625 (const PxVehicleKeySmoothingData& keySmoothing,
626  const PxVehicleDriveTankRawInputData& rawInputData,
627  const PxReal timestep,
628  PxVehicleDriveTank& focusVehicle);
629 
630 
640 (const PxVehiclePadSmoothingData& padSmoothing,
641  const PxVehicleDriveTankRawInputData& rawInputData,
642  const PxReal timestep,
643  PxVehicleDriveTank& focusVehicle);
644 
645 
646 #if !PX_DOXYGEN
647 } // namespace physx
648 #endif
649 
651 #endif //PX_VEHICLE_CONTROL_H
Definition: GuContactBuffer.h:37
PxVehicleDriveNWRawInputData()
Definition: PxVehicleUtilControl.h:323
Definition: PxVehicleDrive4W.h:166
PxF32 getAnalogAccel() const
Return the analog accel value from the gamepad.
Definition: PxVehicleUtilControl.h:540
void setDigitalAccel(const bool accelKeyPressed)
Record if the accel button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:118
float PxF32
Definition: PxSimpleTypes.h:76
PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode)
Definition: PxVehicleUtilControl.h:370
void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs(const PxVehiclePadSmoothingData &padSmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W &focusVehicle)
Used to smooth and set analog vehicle control values from analog inputs (gamepad). Also used to set boolean gearup, geardown values.
void setAnalogLeftThrust(const PxF32 leftThrust)
Set the analog left thrust value from the gamepad.
Definition: PxVehicleUtilControl.h:475
PxVehicleDriveTankControlModel::Enum getDriveModel() const
Return the drive model (eDRIVE_MODEL_SPECIAL or eDRIVE_MODEL_STANDARD)
Definition: PxVehicleUtilControl.h:391
bool getGearUp() const
Return if the gear-up button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:597
bool getGearDown() const
Record if the geardown button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:269
void setDigitalBrake(const bool brakeKeyPressed)
Record if the brake button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:124
float PxReal
Definition: PxSimpleTypes.h:78
bool getGearUp() const
Return if the gearup button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:263
PxF32 getAnalogLeftBrake() const
Return the analog left brake value from the gamepad.
Definition: PxVehicleUtilControl.h:567
Data structure with instanced dynamics data and configuration data of a vehicle with up to PX_MAX_NB_...
Definition: PxVehicleDriveNW.h:134
Used to produce smooth vehicle driving control values from key inputs.
Definition: PxVehicleUtilControl.h:54
void setGearDown(const bool gearDown)
Record if the gear-down button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:591
bool getDigitalSteerLeft() const
Return if the left steer button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:167
bool mGearDown
Definition: PxVehicleUtilControl.h:613
bool getDigitalLeftBrake() const
Return if the left brake button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:448
bool getDigitalLeftThrust() const
Return if the left thrust button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:436
Definition: PxVehicleDriveTank.h:110
PxReal getAnalogBrake() const
Return the analog brake value from the gamepad.
Definition: PxVehicleUtilControl.h:234
PxReal getAnalogHandbrake() const
Return the analog handbrake value from the gamepad.
Definition: PxVehicleUtilControl.h:240
bool mGearDown
Definition: PxVehicleUtilControl.h:277
Enum
Definition: PxVehicleDriveTank.h:139
void setGearDown(const bool gearDownKeyPressed)
Record if the geardown button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:257
PxF32 getAnalogRightThrust() const
Return the analog right thrust value from the gamepad.
Definition: PxVehicleUtilControl.h:558
Definition: PxCoreUtilityTypes.h:100
bool getDigitalAccel() const
Return if the accel button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:430
Used to produce smooth analog vehicle control values from analog inputs.
Definition: PxVehicleUtilControl.h:74
void setDigitalHandbrake(const bool handbrakeKeyPressed)
Record if the handbrake button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:130
void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs(const PxVehiclePadSmoothingData &padSmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW &focusVehicle)
Used to smooth and set analog vehicle control values from analog inputs (gamepad). Also used to set boolean gearup, geardown values.
Definition: PxVehicleDriveTank.h:112
virtual ~PxVehicleDrive4WRawInputData()
Definition: PxVehicleUtilControl.h:110
bool getDigitalBrake() const
Return if the brake button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:155
void setDigitalRightBrake(const bool b)
Set if the right brake button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:424
Definition: PxVehicleDrive4W.h:167
Definition: PxVehicleDriveTank.h:109
void setAnalogHandbrake(const PxReal handbrake)
Set the analog handbrake value from the gamepad.
Definition: PxVehicleUtilControl.h:204
Definition: PxVehicleDrive.h:177
Used to produce smooth vehicle driving control values from analog and digital inputs.
Definition: PxVehicleUtilControl.h:94
bool getDigitalRightBrake() const
Return if the right brake button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:454
void setDigitalSteerRight(const bool steerRightKeyPressed)
Record if the right steer button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:142
void setDigitalSteerLeft(const bool steerLeftKeyPressed)
Record if the left steer button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:136
~PxVehicleDriveNWRawInputData()
Definition: PxVehicleUtilControl.h:324
void setAnalogAccel(const PxReal accel)
Set the analog accel value from the gamepad.
Definition: PxVehicleUtilControl.h:180
Definition: PxVehicleDrive4W.h:164
PxVehicleDrive4WRawInputData()
Definition: PxVehicleUtilControl.h:98
Used to produce smooth analog tank control values from analog and digital inputs. ...
Definition: PxVehicleUtilControl.h:366
Definition: PxVehicleDrive4W.h:165
void setDigitalLeftBrake(const bool b)
Set if the left brake button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:418
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:434
bool getDigitalHandbrake() const
Return if the handbrake button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:161
PxReal getAnalogAccel() const
Return the analog accel value from the gamepad.
Definition: PxVehicleUtilControl.h:228
void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs(const PxVehicleKeySmoothingData &keySmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W &focusVehicle)
Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital input...
Definition: PxVehicleDriveTank.h:113
Data structure with instanced dynamics data and configuration data of a vehicle with up to 4 driven w...
Definition: PxVehicleDrive4W.h:176
Definition: PxVehicleDriveTank.h:142
bool mGearUp
Definition: PxVehicleUtilControl.h:612
PxF32 getAnalogLeftThrust() const
Return the analog left thrust value from the gamepad.
Definition: PxVehicleUtilControl.h:549
bool getGearDown() const
Return if the gear-down button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:603
void setAnalogSteer(const PxReal steer)
Set the analog steer value from the gamepad.
Definition: PxVehicleUtilControl.h:216
void setGearUp(const bool gearUp)
Record if the gear-up button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:585
void setDigitalLeftThrust(const bool b)
Set if the left thrust button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:406
~PxVehicleDriveTankRawInputData()
Definition: PxVehicleUtilControl.h:383
bool getDigitalAccel() const
Return if the accel button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:149
void setAnalogBrake(const PxReal brake)
Set the analog brake value from the gamepad.
Definition: PxVehicleUtilControl.h:192
bool mGearUp
Definition: PxVehicleUtilControl.h:276
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...
void setAnalogRightThrust(const PxF32 rightThrust)
Set the analog right thrust value from the gamepad.
Definition: PxVehicleUtilControl.h:495
uint32_t PxU32
Definition: Px.h:48
void setDigitalAccel(const bool b)
Set if the accel button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:400
Definition: PxVehicleDrive4W.h:168
Data structure with instanced dynamics data and configuration data of a tank.
Definition: PxVehicleDriveTank.h:150
void setAnalogAccel(const PxF32 accel)
Set the analog accel value from the gamepad.
Definition: PxVehicleUtilControl.h:462
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: PxVehicleDriveTank.h:111
void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs(const PxVehicleKeySmoothingData &keySmoothing, const PxFixedSizeLookupTable< 8 > &steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData &rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW &focusVehicle)
Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital input...
bool getDigitalSteerRight() const
Return if the right steer button has been pressed on keyboard.
Definition: PxVehicleUtilControl.h:173
void setAnalogLeftBrake(const PxF32 leftBrake)
Set the analog left brake value from the gamepad.
Definition: PxVehicleUtilControl.h:515
bool getDigitalRightThrust() const
Return if the right thrust button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:442
void setDigitalRightThrust(const bool b)
Set if the right thrust button has been pressed on the keyboard.
Definition: PxVehicleUtilControl.h:412
PxVehicleDriveTankControlModel::Enum mMode
Definition: PxVehicleUtilControl.h:607
PxF32 getAnalogRightBrake() const
Return the analog right brake value from the gamepad.
Definition: PxVehicleUtilControl.h:576
void setGearUp(const bool gearUpKeyPressed)
Record if the gearup button has been pressed on keyboard or gamepad.
Definition: PxVehicleUtilControl.h:251
PxReal getAnalogSteer() const
Return the analog steer value from the gamepad.
Definition: PxVehicleUtilControl.h:245
void setAnalogRightBrake(const PxF32 rightBrake)
Set the analog right brake value from the gamepad.
Definition: PxVehicleUtilControl.h:528
Used to produce smooth vehicle driving control values from analog and digital inputs.
Definition: PxVehicleUtilControl.h:319