1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13#ifndef PX_VEHICLE_CONTROL_H
14#define PX_VEHICLE_CONTROL_H
15/** \addtogroup vehicle
16 @{
17*/
18#include "vehicle/PxVehicleSDK.h"
19#include "vehicle/PxVehicleDrive4W.h"
20#include "vehicle/PxVehicleDriveNW.h"
21#include "vehicle/PxVehicleDriveTank.h"
22
23
24#ifndef PX_DOXYGEN
25namespace physx
26{
27#endif
28
29#ifdef PX_CHECKED
30 void testValidAnalogValue(const PxF32 actualValue, const PxF32 minVal, const PxF32 maxVal, const char* errorString);
31#endif
32
33/**
34\brief Used to produce smooth vehicle driving control values from key inputs.
35@see PxVehicle4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicle4WSmoothAnalogRawInputsAndSetAnalogInputs
36*/
37struct PxVehicleKeySmoothingData
38{
39public:
40
41 /**
42 \brief Rise rate of each analog value if digital value is 1
43 */
44 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
45
46 /**
47 \brief Fall rate of each analog value if digital value is 0
48 */
49 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
50};
51PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleKeySmoothingData)& 0x0f));
52
53/**
54\brief Used to produce smooth analog vehicle control values from analog inputs.
55@see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
56*/
57struct PxVehiclePadSmoothingData
58{
59public:
60
61 /**
62 \brief Rise rate of each analog value from previous value towards target if target>previous
63 */
64 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
65
66 /**
67 \brief Rise rate of each analog value from previous value towards target if target<previous
68 */
69 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
70};
71PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehiclePadSmoothingData)& 0x0f));
72
73/**
74\brief Used to produce smooth vehicle driving control values from analog and digital inputs.
75@see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
76*/
77class PxVehicleDrive4WRawInputData
78{
79public:
80
81 PxVehicleDrive4WRawInputData()
82 {
83 for(PxU32 i=0;i<PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS;i++)
84 {
85 mRawDigitalInputs[i]=false;
86 mRawAnalogInputs[i]=0.0f;
87 }
88
89 mGearUp = false;
90 mGearDown = false;
91 }
92
93 virtual ~PxVehicleDrive4WRawInputData()
94 {
95 }
96
97 /**
98 \brief Record if the accel button has been pressed on keyboard.
99 \param[in] accelKeyPressed is true if the accelerator key has been pressed and false otherwise.
100 */
101 void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
102
103 /**
104 \brief Record if the brake button has been pressed on keyboard.
105 \param[in] brakeKeyPressed is true if the brake key has been pressed and false otherwise.
106 */
107 void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
108
109 /**
110 \brief Record if the handbrake button has been pressed on keyboard.
111 \param[in] handbrakeKeyPressed is true if the handbrake key has been pressed and false otherwise.
112 */
113 void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
114
115 /**
116 \brief Record if the left steer button has been pressed on keyboard.
117 \param[in] steerLeftKeyPressed is true if the steer-left key has been pressed and false otherwise.
118 */
119 void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
120
121 /**
122 \brief Record if the right steer button has been pressed on keyboard.
123 \param[in] steerRightKeyPressed is true if the steer-right key has been pressed and false otherwise.
124 */
125 void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
126
127
128 /**
129 \brief Return if the accel button has been pressed on keyboard.
130 \return True if the accel button has been pressed, false otherwise.
131 */
132 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
133
134 /**
135 \brief Return if the brake button has been pressed on keyboard.
136 \return True if the brake button has been pressed, false otherwise.
137 */
138 bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
139
140 /**
141 \brief Return if the handbrake button has been pressed on keyboard.
142 \return True if the handbrake button has been pressed, false otherwise.
143 */
144 bool getDigitalHandbrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
145
146 /**
147 \brief Return if the left steer button has been pressed on keyboard.
148 \return True if the steer-left button has been pressed, false otherwise.
149 */
150 bool getDigitalSteerLeft() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT];}
151
152 /**
153 \brief Return if the right steer button has been pressed on keyboard.
154 \return True if the steer-right button has been pressed, false otherwise.
155 */
156 bool getDigitalSteerRight() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
157
158
159 /**
160 \brief Set the analog accel value from the gamepad
161 \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.
162 */
163 void setAnalogAccel(const PxReal accel)
164 {
165#ifdef PX_CHECKED
166 testValidAnalogValue(accel, 0.0f, 1.0f, "Analog accel must be in range (0,1)");
167#endif
168 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accel;
169 }
170
171 /**
172 \brief Set the analog brake value from the gamepad
173 \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.
174 */
175 void setAnalogBrake(const PxReal brake)
176 {
177#ifdef PX_CHECKED
178 testValidAnalogValue(brake, 0.0f, 1.0f, "Analog brake must be in range (0,1)");
179#endif
180 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brake;
181 }
182
183 /**
184 \brief Set the analog handbrake value from the gamepad
185 \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.
186 */
187 void setAnalogHandbrake(const PxReal handbrake)
188 {
189#ifdef PX_CHECKED
190 testValidAnalogValue(handbrake, 0.0f, 1.0f, "Analog handbrake must be in range (0,1)");
191#endif
192 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrake;
193 }
194
195 /**
196 \brief Set the analog steer value from the gamepad
197 \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.
198 */
199 void setAnalogSteer(const PxReal steer)
200 {
201#ifdef PX_CHECKED
202 testValidAnalogValue(steer, -1.0f, 1.0f, "Analog steer must be in range (-1,1)");
203#endif
204 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steer;
205 }
206
207 /**
208 \brief Return the analog accel value from the gamepad
209 \return The analog accel value.
210 */
211 PxReal getAnalogAccel() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
212
213 /**
214 \brief Return the analog brake value from the gamepad
215 \return The analog brake value.
216 */
217 PxReal getAnalogBrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
218
219 /**
220 \brief Return the analog handbrake value from the gamepad
221 \return The analog handbrake value.
222 */
223 PxReal getAnalogHandbrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
224
225 /**
226 \brief Return the analog steer value from the gamepad
227 */
228 PxReal getAnalogSteer() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
229
230 /**
231 \brief Record if the gearup button has been pressed on keyboard or gamepad
232 \param[in] gearUpKeyPressed is true if the gear-up button has been pressed, false otherwise.
233 */
234 void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
235
236 /**
237 \brief Record if the geardown button has been pressed on keyboard or gamepad
238 \param[in] gearDownKeyPressed is true if the gear-down button has been pressed, false otherwise.
239 */
240 void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
241
242 /**
243 \brief Return if the gearup button has been pressed on keyboard or gamepad
244 \return The value of the gear-up button.
245 */
246 bool getGearUp() const {return mGearUp;}
247
248 /**
249 \brief Record if the geardown button has been pressed on keyboard or gamepad
250 \return The value of the gear-down button.
251 */
252 bool getGearDown() const {return mGearDown;}
253
254private:
255
256 bool mRawDigitalInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
257 PxReal mRawAnalogInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
258
259 bool mGearUp;
260 bool mGearDown;
261};
262
263/**
264\brief Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital inputs (keyboard).
265 Also used to set boolean gearup, geardown values.
266 \param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
267 \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
268 \param[in] rawInputData is the state of all digital inputs that control the vehicle.
269 \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
270 \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.
271 \param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
272 */
273void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
274 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
275 const PxVehicleDrive4WRawInputData& rawInputData,
276 const PxReal timestep,
277 const bool isVehicleInAir,
278 PxVehicleDrive4W& focusVehicle);
279
280/**
281\brief Used to smooth and set analog vehicle control values from analog inputs (gamepad).
282Also used to set boolean gearup, geardown values.
283\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.
284\param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
285\param[in] rawInputData is the state of all gamepad analog inputs that will be used 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 control values arising from the gamepad inputs.
289*/
290void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
291 (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
292 const PxVehicleDrive4WRawInputData& rawInputData,
293 const PxReal timestep,
294 const bool isVehicleInAir,
295 PxVehicleDrive4W& focusVehicle);
296
297
298/**
299\brief Used to produce smooth vehicle driving control values from analog and digital inputs.
300@see PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs
301*/
302class PxVehicleDriveNWRawInputData : public PxVehicleDrive4WRawInputData
303{
304public:
305
306 PxVehicleDriveNWRawInputData() : PxVehicleDrive4WRawInputData(){}
307 ~PxVehicleDriveNWRawInputData(){}
308};
309
310/**
311\brief Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital inputs (keyboard).
312 Also used to set boolean gearup, geardown values.
313 \param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
314 \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
315 \param[in] rawInputData is the state of all digital inputs that control the vehicle.
316 \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
317 \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.
318 \param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
319*/
320void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs
321 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
322 const PxVehicleDriveNWRawInputData& rawInputData,
323 const PxReal timestep,
324 const bool isVehicleInAir,
325 PxVehicleDriveNW& focusVehicle);
326
327/**
328\brief Used to smooth and set analog vehicle control values from analog inputs (gamepad).
329Also used to set boolean gearup, geardown values.
330\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.
331\param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed.
332\param[in] rawInputData is the state of all gamepad analog inputs that will be used 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 control values arising from the gamepad inputs.
336*/
337void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs
338 (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
339 const PxVehicleDriveNWRawInputData& rawInputData,
340 const PxReal timestep,
341 const bool isVehicleInAir,
342 PxVehicleDriveNW& focusVehicle);
343
344
345/**
346\brief Used to produce smooth analog tank control values from analog and digital inputs.
347@see PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
348*/
349class PxVehicleDriveTankRawInputData
350{
351public:
352
353 PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode)
354 : mMode(mode)
355 {
356 for(PxU32 i=0;i<PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS;i++)
357 {
358 mRawAnalogInputs[i]=0.0f;
359 mRawDigitalInputs[i]=false;
360 }
361
362 mGearUp=false;
363 mGearDown=false;
364 }
365
366 ~PxVehicleDriveTankRawInputData()
367 {
368 }
369
370 /**
371 \brief Return the drive model (eDRIVE_MODEL_SPECIAL or eDRIVE_MODEL_STANDARD)
372 \return The chosen tank drive model.
373 */
374 PxVehicleDriveTankControlModel::Enum getDriveModel() const
375 {
376 return mMode;
377 }
378
379 /**
380 \brief Set if the accel button has been pressed on the keyboard
381 \param[in] b is true if the digital accel button has been pressed, false otherwise.
382 */
383 void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
384
385 /**
386 \brief Set if the left thrust button has been pressed on the keyboard
387 \param[in] b is true if the digital left thrust button has been pressed, false otherwise.
388 */
389 void setDigitalLeftThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=b;}
390
391 /**
392 \brief Set if the right thrust button has been pressed on the keyboard
393 \param[in] b is true if the digital right thrust button has been pressed, false otherwise.
394 */
395 void setDigitalRightThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=b;}
396
397 /**
398 \brief Set if the left brake button has been pressed on the keyboard
399 \param[in] b is true if the digital left brake button has been pressed, false otherwise.
400 */
401 void setDigitalLeftBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=b;}
402
403 /**
404 \brief Set if the right brake button has been pressed on the keyboard
405 \param[in] b is true if the digital right brake button has been pressed, false otherwise.
406 */
407 void setDigitalRightBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=b;}
408
409 /**
410 \brief Return if the accel button has been pressed on the keyboard
411 \return True if the accel button has been pressed, false otherwise.
412 */
413 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
414
415 /**
416 \brief Return if the left thrust button has been pressed on the keyboard
417 \return True if the left thrust button has been pressed, false otherwise.
418 */
419 bool getDigitalLeftThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];}
420
421 /**
422 \brief Return if the right thrust button has been pressed on the keyboard
423 \return True if the right thrust button has been pressed, false otherwise.
424 */
425 bool getDigitalRightThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];}
426
427 /**
428 \brief Return if the left brake button has been pressed on the keyboard
429 \return True if the left brake button has been pressed, false otherwise.
430 */
431 bool getDigitalLeftBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];}
432
433 /**
434 \brief Return if the right brake button has been pressed on the keyboard
435 \return True if the right brake button has been pressed, false otherwise.
436 */
437 bool getDigitalRightBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];}
438
439
440 /**
441 \brief Set the analog accel value from the gamepad
442 \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.
443 In range (0,1).
444 */
445 void setAnalogAccel(const PxF32 accel)
446 {
447#ifdef PX_CHECKED
448 testValidAnalogValue(accel, 0.0f, 1.0f, "Tank analog accel must be in range (-1,1)");
449#endif
450 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=accel;
451 }
452
453 /**
454 \brief Set the analog left thrust value from the gamepad
455 \param[in] leftThrust represents the state of the left stick.
456 \note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
457 */
458 void setAnalogLeftThrust(const PxF32 leftThrust)
459 {
460#ifdef PX_CHECKED
461 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
462 {
463 testValidAnalogValue(leftThrust, -1.0f, 1.0f, "Tank left thrust must be in range (-1,1) in eSPECIAL mode.");
464 }
465 else
466 {
467 testValidAnalogValue(leftThrust, 0.0f, 1.0f, "Tank left thrust must be in range (0,1) in eSTANDARD mode.");
468 }
469#endif
470 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=leftThrust;
471 }
472
473 /**
474 \brief Set the analog right thrust value from the gamepad
475 \param[in] rightThrust represents the state of the right stick.
476 \note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
477 */
478 void setAnalogRightThrust(const PxF32 rightThrust)
479 {
480#ifdef PX_CHECKED
481 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
482 {
483 testValidAnalogValue(rightThrust, -1.0f, 1.0f, "Tank right thrust must be in range (-1,1) in eSPECIAL mode.");
484 }
485 else
486 {
487 testValidAnalogValue(rightThrust, 0.0f, 1.0f, "Tank right thrust must be in range (0,1) in eSTANDARD mode.");
488 }
489#endif
490 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=rightThrust;
491 }
492
493 /**
494 \brief Set the analog left brake value from the gamepad
495 \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.
496 \note In range (0,1).
497 */
498 void setAnalogLeftBrake(const PxF32 leftBrake)
499 {
500#ifdef PX_CHECKED
501 testValidAnalogValue(leftBrake, 0.0f, 1.0f, "Tank left brake must be in range (0,1).");
502#endif
503 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=leftBrake;
504 }
505
506 /**
507 \brief Set the analog right brake value from the gamepad
508 \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.
509 \note In range (0,1).
510 */
511 void setAnalogRightBrake(const PxF32 rightBrake)
512 {
513#ifdef PX_CHECKED
514 testValidAnalogValue(rightBrake, 0.0f, 1.0f, "Tank right brake must be in range (0,1).");
515#endif
516 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake;
517 }
518
519 /**
520 \brief Return the analog accel value from the gamepad
521 \return The analog accel value.
522 */
523 PxF32 getAnalogAccel() const
524 {
525 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
526 }
527
528 /**
529 \brief Return the analog left thrust value from the gamepad
530 \return The analog left thrust value.
531 */
532 PxF32 getAnalogLeftThrust() const
533 {
534 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];
535 }
536
537 /**
538 \brief Return the analog right thrust value from the gamepad
539 \return The analog right thrust value.
540 */
541 PxF32 getAnalogRightThrust() const
542 {
543 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];
544 }
545
546 /**
547 \brief Return the analog left brake value from the gamepad
548 \return The analog left brake value.
549 */
550 PxF32 getAnalogLeftBrake() const
551 {
552 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];
553 }
554
555 /**
556 \brief Return the analog right brake value from the gamepad
557 \return The analog right brake value.
558 */
559 PxF32 getAnalogRightBrake() const
560 {
561 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];
562 }
563
564 /**
565 \brief Record if the gear-up button has been pressed on keyboard or gamepad
566 \param[in] gearUp is true if the gear-up button has been pressed, false otherwise.
567 */
568 void setGearUp(const bool gearUp) {mGearUp=gearUp;}
569
570 /**
571 \brief Record if the gear-down button has been pressed on keyboard or gamepad
572 \param[in] gearDown is true if the gear-down button has been pressed, false otherwise.
573 */
574 void setGearDown(const bool gearDown) {mGearDown=gearDown;}
575
576 /**
577 \brief Return if the gear-up button has been pressed on keyboard or gamepad
578 \return True if the gear-up button has been pressed, false otherwise.
579 */
580 bool getGearUp() const {return mGearUp;}
581
582 /**
583 \brief Return if the gear-down button has been pressed on keyboard or gamepad
584 \return True if the gear-down button has been pressed, false otherwise.
585 */
586 bool getGearDown() const {return mGearDown;}
587
588private:
589
590 PxVehicleDriveTankControlModel::Enum mMode;
591
592 PxReal mRawAnalogInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
593 bool mRawDigitalInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
594
595 bool mGearUp;
596 bool mGearDown;
597};
598
599/**
600\brief Used to smooth and set analog tank control values from digital inputs (keyboard).
601Also used to set boolean gearup, geardown values.
602\param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off.
603\param[in] rawInputData is the state of all digital inputs that control the vehicle.
604\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
605\param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
606*/
607void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs
608(const PxVehicleKeySmoothingData& keySmoothing,
609 const PxVehicleDriveTankRawInputData& rawInputData,
610 const PxReal timestep,
611 PxVehicleDriveTank& focusVehicle);
612
613
614/**
615\brief Used to smooth and set analog tank control values from analog inputs (gamepad).
616Also used to set boolean gearup, geardown values.
617\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.
618\param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle.
619\param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
620\param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs.
621*/
622void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
623(const PxVehiclePadSmoothingData& padSmoothing,
624 const PxVehicleDriveTankRawInputData& rawInputData,
625 const PxReal timestep,
626 PxVehicleDriveTank& focusVehicle);
627
628
629#ifndef PX_DOXYGEN
630} // namespace physx
631#endif
632
633/** @} */
634#endif //PX_VEHICLE_CONTROL_H
635