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/** \addtogroup vehicle
33 @{
34*/
35#include "vehicle/PxVehicleSDK.h"
36#include "vehicle/PxVehicleDrive4W.h"
37#include "vehicle/PxVehicleDriveNW.h"
38#include "vehicle/PxVehicleDriveTank.h"
39
40
41#if !PX_DOXYGEN
42namespace 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
50/**
51\brief Used to produce smooth vehicle driving control values from key inputs.
52@see PxVehicle4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicle4WSmoothAnalogRawInputsAndSetAnalogInputs
53*/
54struct PxVehicleKeySmoothingData
55{
56public:
57
58 /**
59 \brief Rise rate of each analog value if digital value is 1
60 */
61 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
62
63 /**
64 \brief Fall rate of each analog value if digital value is 0
65 */
66 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
67};
68PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleKeySmoothingData)& 0x0f));
69
70/**
71\brief Used to produce smooth analog vehicle control values from analog inputs.
72@see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
73*/
74struct PxVehiclePadSmoothingData
75{
76public:
77
78 /**
79 \brief Rise rate of each analog value from previous value towards target if target>previous
80 */
81 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
82
83 /**
84 \brief Rise rate of each analog value from previous value towards target if target<previous
85 */
86 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
87};
88PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehiclePadSmoothingData)& 0x0f));
89
90/**
91\brief Used to produce smooth vehicle driving control values from analog and digital inputs.
92@see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
93*/
94class PxVehicleDrive4WRawInputData
95{
96public:
97
98 PxVehicleDrive4WRawInputData()
99 {
100 for(PxU32 i=0;i<PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS;i++)
101 {
102 mRawDigitalInputs[i]=false;
103 mRawAnalogInputs[i]=0.0f;
104 }
105
106 mGearUp = false;
107 mGearDown = false;
108 }
109
110 virtual ~PxVehicleDrive4WRawInputData()
111 {
112 }
113
114 /**
115 \brief Record if the accel button has been pressed on keyboard.
116 \param[in] accelKeyPressed is true if the accelerator key has been pressed and false otherwise.
117 */
118 void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
119
120 /**
121 \brief Record if the brake button has been pressed on keyboard.
122 \param[in] brakeKeyPressed is true if the brake key has been pressed and false otherwise.
123 */
124 void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
125
126 /**
127 \brief Record if the handbrake button has been pressed on keyboard.
128 \param[in] handbrakeKeyPressed is true if the handbrake key has been pressed and false otherwise.
129 */
130 void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
131
132 /**
133 \brief Record if the left steer button has been pressed on keyboard.
134 \param[in] steerLeftKeyPressed is true if the steer-left key has been pressed and false otherwise.
135 */
136 void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
137
138 /**
139 \brief Record if the right steer button has been pressed on keyboard.
140 \param[in] steerRightKeyPressed is true if the steer-right key has been pressed and false otherwise.
141 */
142 void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
143
144
145 /**
146 \brief Return if the accel button has been pressed on keyboard.
147 \return True if the accel button has been pressed, false otherwise.
148 */
149 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
150
151 /**
152 \brief Return if the brake button has been pressed on keyboard.
153 \return True if the brake button has been pressed, false otherwise.
154 */
155 bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
156
157 /**
158 \brief Return if the handbrake button has been pressed on keyboard.
159 \return True if the handbrake button has been pressed, false otherwise.
160 */
161 bool getDigitalHandbrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
162
163 /**
164 \brief Return if the left steer button has been pressed on keyboard.
165 \return True if the steer-left button has been pressed, false otherwise.
166 */
167 bool getDigitalSteerLeft() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT];}
168
169 /**
170 \brief Return if the right steer button has been pressed on keyboard.
171 \return True if the steer-right button has been pressed, false otherwise.
172 */
173 bool getDigitalSteerRight() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
174
175
176 /**
177 \brief Set the analog accel value from the gamepad
178 \param[in] accel is the analog accelerator pedal value in range(0,1) where 1 represents the pedal fully pressed and 0 represents the pedal in its rest state.
179 */
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
188 /**
189 \brief Set the analog brake value from the gamepad
190 \param[in] brake is the analog brake pedal value in range(0,1) where 1 represents the pedal fully pressed and 0 represents the pedal in its rest state.
191 */
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
200 /**
201 \brief Set the analog handbrake value from the gamepad
202 \param[in] handbrake is the analog handbrake value in range(0,1) where 1 represents the handbrake fully engaged and 0 represents the handbrake in its rest state.
203 */
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
212 /**
213 \brief Set the analog steer value from the gamepad
214 \param[in] steer is the analog steer value in range(-1,1) where -1 represents the steering wheel at left lock and +1 represents the steering wheel at right lock.
215 */
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
221 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steer;
222 }
223
224 /**
225 \brief Return the analog accel value from the gamepad
226 \return The analog accel value.
227 */
228 PxReal getAnalogAccel() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
229
230 /**
231 \brief Return the analog brake value from the gamepad
232 \return The analog brake value.
233 */
234 PxReal getAnalogBrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
235
236 /**
237 \brief Return the analog handbrake value from the gamepad
238 \return The analog handbrake value.
239 */
240 PxReal getAnalogHandbrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
241
242 /**
243 \brief Return the analog steer value from the gamepad
244 */
245 PxReal getAnalogSteer() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
246
247 /**
248 \brief Record if the gearup button has been pressed on keyboard or gamepad
249 \param[in] gearUpKeyPressed is true if the gear-up button has been pressed, false otherwise.
250 */
251 void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
252
253 /**
254 \brief Record if the geardown button has been pressed on keyboard or gamepad
255 \param[in] gearDownKeyPressed is true if the gear-down button has been pressed, false otherwise.
256 */
257 void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
258
259 /**
260 \brief Return if the gearup button has been pressed on keyboard or gamepad
261 \return The value of the gear-up button.
262 */
263 bool getGearUp() const {return mGearUp;}
264
265 /**
266 \brief Record if the geardown button has been pressed on keyboard or gamepad
267 \return The value of the gear-down button.
268 */
269 bool getGearDown() const {return mGearDown;}
270
271private:
272
273 bool mRawDigitalInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
274 PxReal mRawAnalogInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
275
276 bool mGearUp;
277 bool mGearDown;
278};
279
280/**
281\brief Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital inputs (keyboard).
282 Also used to set boolean gearup, geardown values.
283 \param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
284 \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
285 \param[in] rawInputData is the state of all digital inputs that control the vehicle.
286 \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
287 \param[in] isVehicleInAir describes if the vehicle is in the air or on the ground and is used to decide whether or not to apply steerVsForwardSpeedTable.
288 \param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
289 */
290void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
291 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
292 const PxVehicleDrive4WRawInputData& rawInputData,
293 const PxReal timestep,
294 const bool isVehicleInAir,
295 PxVehicleDrive4W& focusVehicle);
296
297/**
298\brief Used to smooth and set analog vehicle control values from analog inputs (gamepad).
299Also used to set boolean gearup, geardown values.
300\param[in] padSmoothing describes how quickly the control values applied to the vehicle blend from the current vehicle values towards the raw analog values from the gamepad.
301\param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
302\param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle.
303\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
304\param[in] isVehicleInAir describes if the vehicle is in the air or on the ground and is used to decide whether or not to apply steerVsForwardSpeedTable.
305\param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs.
306*/
307void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
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
315/**
316\brief Used to produce smooth vehicle driving control values from analog and digital inputs.
317@see PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs
318*/
319class PxVehicleDriveNWRawInputData : public PxVehicleDrive4WRawInputData
320{
321public:
322
323 PxVehicleDriveNWRawInputData() : PxVehicleDrive4WRawInputData(){}
324 ~PxVehicleDriveNWRawInputData(){}
325};
326
327/**
328\brief Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital inputs (keyboard).
329 Also used to set boolean gearup, geardown values.
330 \param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
331 \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
332 \param[in] rawInputData is the state of all digital inputs that control the vehicle.
333 \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
334 \param[in] isVehicleInAir describes if the vehicle is in the air or on the ground and is used to decide whether or not to apply steerVsForwardSpeedTable.
335 \param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
336*/
337void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs
338 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
339 const PxVehicleDriveNWRawInputData& rawInputData,
340 const PxReal timestep,
341 const bool isVehicleInAir,
342 PxVehicleDriveNW& focusVehicle);
343
344/**
345\brief Used to smooth and set analog vehicle control values from analog inputs (gamepad).
346Also used to set boolean gearup, geardown values.
347\param[in] padSmoothing describes how quickly the control values applied to the vehicle blend from the current vehicle values towards the raw analog values from the gamepad.
348\param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
349\param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle.
350\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
351\param[in] isVehicleInAir describes if the vehicle is in the air or on the ground and is used to decide whether or not to apply steerVsForwardSpeedTable.
352\param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs.
353*/
354void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs
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
362/**
363\brief Used to produce smooth analog tank control values from analog and digital inputs.
364@see PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
365*/
366class PxVehicleDriveTankRawInputData
367{
368public:
369
370 PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode)
371 : mMode(mode)
372 {
373 for(PxU32 i=0;i<PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS;i++)
374 {
375 mRawAnalogInputs[i]=0.0f;
376 mRawDigitalInputs[i]=false;
377 }
378
379 mGearUp=false;
380 mGearDown=false;
381 }
382
383 ~PxVehicleDriveTankRawInputData()
384 {
385 }
386
387 /**
388 \brief Return the drive model (eDRIVE_MODEL_SPECIAL or eDRIVE_MODEL_STANDARD)
389 \return The chosen tank drive model.
390 */
391 PxVehicleDriveTankControlModel::Enum getDriveModel() const
392 {
393 return mMode;
394 }
395
396 /**
397 \brief Set if the accel button has been pressed on the keyboard
398 \param[in] b is true if the digital accel button has been pressed, false otherwise.
399 */
400 void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
401
402 /**
403 \brief Set if the left thrust button has been pressed on the keyboard
404 \param[in] b is true if the digital left thrust button has been pressed, false otherwise.
405 */
406 void setDigitalLeftThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=b;}
407
408 /**
409 \brief Set if the right thrust button has been pressed on the keyboard
410 \param[in] b is true if the digital right thrust button has been pressed, false otherwise.
411 */
412 void setDigitalRightThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=b;}
413
414 /**
415 \brief Set if the left brake button has been pressed on the keyboard
416 \param[in] b is true if the digital left brake button has been pressed, false otherwise.
417 */
418 void setDigitalLeftBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=b;}
419
420 /**
421 \brief Set if the right brake button has been pressed on the keyboard
422 \param[in] b is true if the digital right brake button has been pressed, false otherwise.
423 */
424 void setDigitalRightBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=b;}
425
426 /**
427 \brief Return if the accel button has been pressed on the keyboard
428 \return True if the accel button has been pressed, false otherwise.
429 */
430 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
431
432 /**
433 \brief Return if the left thrust button has been pressed on the keyboard
434 \return True if the left thrust button has been pressed, false otherwise.
435 */
436 bool getDigitalLeftThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];}
437
438 /**
439 \brief Return if the right thrust button has been pressed on the keyboard
440 \return True if the right thrust button has been pressed, false otherwise.
441 */
442 bool getDigitalRightThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];}
443
444 /**
445 \brief Return if the left brake button has been pressed on the keyboard
446 \return True if the left brake button has been pressed, false otherwise.
447 */
448 bool getDigitalLeftBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];}
449
450 /**
451 \brief Return if the right brake button has been pressed on the keyboard
452 \return True if the right brake button has been pressed, false otherwise.
453 */
454 bool getDigitalRightBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];}
455
456
457 /**
458 \brief Set the analog accel value from the gamepad
459 \param[in] accel is a value in range (0,1) where 1 represents the accelerator pedal fully pressed and 0 represents the pedal in its rest state.
460 In range (0,1).
461 */
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
470 /**
471 \brief Set the analog left thrust value from the gamepad
472 \param[in] leftThrust represents the state of the left stick.
473 \note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
474 */
475 void setAnalogLeftThrust(const PxF32 leftThrust)
476 {
477#if PX_CHECKED
478 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
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
490 /**
491 \brief Set the analog right thrust value from the gamepad
492 \param[in] rightThrust represents the state of the right stick.
493 \note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
494 */
495 void setAnalogRightThrust(const PxF32 rightThrust)
496 {
497#if PX_CHECKED
498 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
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
510 /**
511 \brief Set the analog left brake value from the gamepad
512 \param[in] leftBrake is a value in range (0,1) where 1 represents the left brake pedal fully pressed and 0 represents the left brake pedal in its rest state.
513 \note In range (0,1).
514 */
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
523 /**
524 \brief Set the analog right brake value from the gamepad
525 \param[in] rightBrake is a value in range (0,1) where 1 represents the right brake pedal fully pressed and 0 represents the right brake pedal in its rest state.
526 \note In range (0,1).
527 */
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
536 /**
537 \brief Return the analog accel value from the gamepad
538 \return The analog accel value.
539 */
540 PxF32 getAnalogAccel() const
541 {
542 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
543 }
544
545 /**
546 \brief Return the analog left thrust value from the gamepad
547 \return The analog left thrust value.
548 */
549 PxF32 getAnalogLeftThrust() const
550 {
551 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];
552 }
553
554 /**
555 \brief Return the analog right thrust value from the gamepad
556 \return The analog right thrust value.
557 */
558 PxF32 getAnalogRightThrust() const
559 {
560 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];
561 }
562
563 /**
564 \brief Return the analog left brake value from the gamepad
565 \return The analog left brake value.
566 */
567 PxF32 getAnalogLeftBrake() const
568 {
569 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];
570 }
571
572 /**
573 \brief Return the analog right brake value from the gamepad
574 \return The analog right brake value.
575 */
576 PxF32 getAnalogRightBrake() const
577 {
578 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];
579 }
580
581 /**
582 \brief Record if the gear-up button has been pressed on keyboard or gamepad
583 \param[in] gearUp is true if the gear-up button has been pressed, false otherwise.
584 */
585 void setGearUp(const bool gearUp) {mGearUp=gearUp;}
586
587 /**
588 \brief Record if the gear-down button has been pressed on keyboard or gamepad
589 \param[in] gearDown is true if the gear-down button has been pressed, false otherwise.
590 */
591 void setGearDown(const bool gearDown) {mGearDown=gearDown;}
592
593 /**
594 \brief Return if the gear-up button has been pressed on keyboard or gamepad
595 \return True if the gear-up button has been pressed, false otherwise.
596 */
597 bool getGearUp() const {return mGearUp;}
598
599 /**
600 \brief Return if the gear-down button has been pressed on keyboard or gamepad
601 \return True if the gear-down button has been pressed, false otherwise.
602 */
603 bool getGearDown() const {return mGearDown;}
604
605private:
606
607 PxVehicleDriveTankControlModel::Enum mMode;
608
609 PxReal mRawAnalogInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
610 bool mRawDigitalInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
611
612 bool mGearUp;
613 bool mGearDown;
614};
615
616/**
617\brief Used to smooth and set analog tank control values from digital inputs (keyboard).
618Also used to set boolean gearup, geardown values.
619\param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
620\param[in] rawInputData is the state of all digital inputs that control the vehicle.
621\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
622\param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
623*/
624void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs
625(const PxVehicleKeySmoothingData& keySmoothing,
626 const PxVehicleDriveTankRawInputData& rawInputData,
627 const PxReal timestep,
628 PxVehicleDriveTank& focusVehicle);
629
630
631/**
632\brief Used to smooth and set analog tank control values from analog inputs (gamepad).
633Also used to set boolean gearup, geardown values.
634\param[in] padSmoothing describes how quickly the control values applied to the vehicle blend from the current vehicle values towards the raw analog values from the gamepad.
635\param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle.
636\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
637\param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs.
638*/
639void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
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
650/** @} */
651#endif //PX_VEHICLE_CONTROL_H
652

source code of qtquick3dphysics/src/3rdparty/PhysX/include/vehicle/PxVehicleUtilControl.h