00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef PX_VEHICLE_CONTROL_H
00031 #define PX_VEHICLE_CONTROL_H
00032
00035 #include "vehicle/PxVehicleSDK.h"
00036 #include "vehicle/PxVehicleDrive4W.h"
00037 #include "vehicle/PxVehicleDriveNW.h"
00038 #include "vehicle/PxVehicleDriveTank.h"
00039
00040
00041 #if !PX_DOXYGEN
00042 namespace physx
00043 {
00044 #endif
00045
00046 #if PX_CHECKED
00047 void testValidAnalogValue(const PxF32 actualValue, const PxF32 minVal, const PxF32 maxVal, const char* errorString);
00048 #endif
00049
00054 struct PxVehicleKeySmoothingData
00055 {
00056 public:
00057
00061 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
00062
00066 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
00067 };
00068 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleKeySmoothingData)& 0x0f));
00069
00074 struct PxVehiclePadSmoothingData
00075 {
00076 public:
00077
00081 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
00082
00086 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
00087 };
00088 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehiclePadSmoothingData)& 0x0f));
00089
00094 class PxVehicleDrive4WRawInputData
00095 {
00096 public:
00097
00098 PxVehicleDrive4WRawInputData()
00099 {
00100 for(PxU32 i=0;i<PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS;i++)
00101 {
00102 mRawDigitalInputs[i]=false;
00103 mRawAnalogInputs[i]=0.0f;
00104 }
00105
00106 mGearUp = false;
00107 mGearDown = false;
00108 }
00109
00110 virtual ~PxVehicleDrive4WRawInputData()
00111 {
00112 }
00113
00118 void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
00119
00124 void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
00125
00130 void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
00131
00136 void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
00137
00142 void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
00143
00144
00149 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
00150
00155 bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
00156
00161 bool getDigitalHandbrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
00162
00167 bool getDigitalSteerLeft() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT];}
00168
00173 bool getDigitalSteerRight() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
00174
00175
00180 void setAnalogAccel(const PxReal accel)
00181 {
00182 #if PX_CHECKED
00183 testValidAnalogValue(accel, 0.0f, 1.0f, "Analog accel must be in range (0,1)");
00184 #endif
00185 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accel;
00186 }
00187
00192 void setAnalogBrake(const PxReal brake)
00193 {
00194 #if PX_CHECKED
00195 testValidAnalogValue(brake, 0.0f, 1.0f, "Analog brake must be in range (0,1)");
00196 #endif
00197 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brake;
00198 }
00199
00204 void setAnalogHandbrake(const PxReal handbrake)
00205 {
00206 #if PX_CHECKED
00207 testValidAnalogValue(handbrake, 0.0f, 1.0f, "Analog handbrake must be in range (0,1)");
00208 #endif
00209 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrake;
00210 }
00211
00216 void setAnalogSteer(const PxReal steer)
00217 {
00218 #if PX_CHECKED
00219 testValidAnalogValue(steer, -1.0f, 1.0f, "Analog steer must be in range (-1,1)");
00220 #endif
00221 mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steer;
00222 }
00223
00228 PxReal getAnalogAccel() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
00229
00234 PxReal getAnalogBrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
00235
00240 PxReal getAnalogHandbrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
00241
00245 PxReal getAnalogSteer() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
00246
00251 void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
00252
00257 void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
00258
00263 bool getGearUp() const {return mGearUp;}
00264
00269 bool getGearDown() const {return mGearDown;}
00270
00271 private:
00272
00273 bool mRawDigitalInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
00274 PxReal mRawAnalogInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
00275
00276 bool mGearUp;
00277 bool mGearDown;
00278 };
00279
00290 void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
00291 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
00292 const PxVehicleDrive4WRawInputData& rawInputData,
00293 const PxReal timestep,
00294 const bool isVehicleInAir,
00295 PxVehicleDrive4W& focusVehicle);
00296
00307 void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
00308 (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
00309 const PxVehicleDrive4WRawInputData& rawInputData,
00310 const PxReal timestep,
00311 const bool isVehicleInAir,
00312 PxVehicleDrive4W& focusVehicle);
00313
00314
00319 class PxVehicleDriveNWRawInputData : public PxVehicleDrive4WRawInputData
00320 {
00321 public:
00322
00323 PxVehicleDriveNWRawInputData() : PxVehicleDrive4WRawInputData(){}
00324 ~PxVehicleDriveNWRawInputData(){}
00325 };
00326
00337 void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs
00338 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
00339 const PxVehicleDriveNWRawInputData& rawInputData,
00340 const PxReal timestep,
00341 const bool isVehicleInAir,
00342 PxVehicleDriveNW& focusVehicle);
00343
00354 void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs
00355 (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable,
00356 const PxVehicleDriveNWRawInputData& rawInputData,
00357 const PxReal timestep,
00358 const bool isVehicleInAir,
00359 PxVehicleDriveNW& focusVehicle);
00360
00361
00366 class PxVehicleDriveTankRawInputData
00367 {
00368 public:
00369
00370 PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode)
00371 : mMode(mode)
00372 {
00373 for(PxU32 i=0;i<PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS;i++)
00374 {
00375 mRawAnalogInputs[i]=0.0f;
00376 mRawDigitalInputs[i]=false;
00377 }
00378
00379 mGearUp=false;
00380 mGearDown=false;
00381 }
00382
00383 ~PxVehicleDriveTankRawInputData()
00384 {
00385 }
00386
00391 PxVehicleDriveTankControlModel::Enum getDriveModel() const
00392 {
00393 return mMode;
00394 }
00395
00400 void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
00401
00406 void setDigitalLeftThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=b;}
00407
00412 void setDigitalRightThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=b;}
00413
00418 void setDigitalLeftBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=b;}
00419
00424 void setDigitalRightBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=b;}
00425
00430 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
00431
00436 bool getDigitalLeftThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];}
00437
00442 bool getDigitalRightThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];}
00443
00448 bool getDigitalLeftBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];}
00449
00454 bool getDigitalRightBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];}
00455
00456
00462 void setAnalogAccel(const PxF32 accel)
00463 {
00464 #if PX_CHECKED
00465 testValidAnalogValue(accel, 0.0f, 1.0f, "Tank analog accel must be in range (-1,1)");
00466 #endif
00467 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=accel;
00468 }
00469
00475 void setAnalogLeftThrust(const PxF32 leftThrust)
00476 {
00477 #if PX_CHECKED
00478 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
00479 {
00480 testValidAnalogValue(leftThrust, -1.0f, 1.0f, "Tank left thrust must be in range (-1,1) in eSPECIAL mode.");
00481 }
00482 else
00483 {
00484 testValidAnalogValue(leftThrust, 0.0f, 1.0f, "Tank left thrust must be in range (0,1) in eSTANDARD mode.");
00485 }
00486 #endif
00487 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=leftThrust;
00488 }
00489
00495 void setAnalogRightThrust(const PxF32 rightThrust)
00496 {
00497 #if PX_CHECKED
00498 if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
00499 {
00500 testValidAnalogValue(rightThrust, -1.0f, 1.0f, "Tank right thrust must be in range (-1,1) in eSPECIAL mode.");
00501 }
00502 else
00503 {
00504 testValidAnalogValue(rightThrust, 0.0f, 1.0f, "Tank right thrust must be in range (0,1) in eSTANDARD mode.");
00505 }
00506 #endif
00507 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=rightThrust;
00508 }
00509
00515 void setAnalogLeftBrake(const PxF32 leftBrake)
00516 {
00517 #if PX_CHECKED
00518 testValidAnalogValue(leftBrake, 0.0f, 1.0f, "Tank left brake must be in range (0,1).");
00519 #endif
00520 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=leftBrake;
00521 }
00522
00528 void setAnalogRightBrake(const PxF32 rightBrake)
00529 {
00530 #if PX_CHECKED
00531 testValidAnalogValue(rightBrake, 0.0f, 1.0f, "Tank right brake must be in range (0,1).");
00532 #endif
00533 mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake;
00534 }
00535
00540 PxF32 getAnalogAccel() const
00541 {
00542 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
00543 }
00544
00549 PxF32 getAnalogLeftThrust() const
00550 {
00551 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];
00552 }
00553
00558 PxF32 getAnalogRightThrust() const
00559 {
00560 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];
00561 }
00562
00567 PxF32 getAnalogLeftBrake() const
00568 {
00569 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];
00570 }
00571
00576 PxF32 getAnalogRightBrake() const
00577 {
00578 return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];
00579 }
00580
00585 void setGearUp(const bool gearUp) {mGearUp=gearUp;}
00586
00591 void setGearDown(const bool gearDown) {mGearDown=gearDown;}
00592
00597 bool getGearUp() const {return mGearUp;}
00598
00603 bool getGearDown() const {return mGearDown;}
00604
00605 private:
00606
00607 PxVehicleDriveTankControlModel::Enum mMode;
00608
00609 PxReal mRawAnalogInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
00610 bool mRawDigitalInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
00611
00612 bool mGearUp;
00613 bool mGearDown;
00614 };
00615
00624 void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs
00625 (const PxVehicleKeySmoothingData& keySmoothing,
00626 const PxVehicleDriveTankRawInputData& rawInputData,
00627 const PxReal timestep,
00628 PxVehicleDriveTank& focusVehicle);
00629
00630
00639 void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
00640 (const PxVehiclePadSmoothingData& padSmoothing,
00641 const PxVehicleDriveTankRawInputData& rawInputData,
00642 const PxReal timestep,
00643 PxVehicleDriveTank& focusVehicle);
00644
00645
00646 #if !PX_DOXYGEN
00647 }
00648 #endif
00649
00651 #endif //PX_VEHICLE_CONTROL_H