PxVehicleUtilControl.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2012 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 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/PxVehicleDriveTank.h" 00038 00039 #ifndef PX_DOXYGEN 00040 namespace physx 00041 { 00042 #endif 00043 00044 class PxVehicleDrive4W; 00045 00050 struct PxVehicleKeySmoothingData 00051 { 00052 public: 00053 00057 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NUM_ANALOG_INPUTS]; 00058 00062 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NUM_ANALOG_INPUTS]; 00063 }; 00064 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleKeySmoothingData)& 0x0f)); 00065 00070 struct PxVehiclePadSmoothingData 00071 { 00072 public: 00073 00077 PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NUM_ANALOG_INPUTS]; 00078 00082 PxReal mFallRates[PxVehicleDriveDynData::eMAX_NUM_ANALOG_INPUTS]; 00083 }; 00084 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehiclePadSmoothingData)& 0x0f)); 00085 00090 class PxVehicleDrive4WRawInputData 00091 { 00092 public: 00093 00094 PxVehicleDrive4WRawInputData() 00095 { 00096 for(PxU32 i=0;i<PxVehicleDrive4W::eMAX_NUM_DRIVE4W_ANALOG_INPUTS;i++) 00097 { 00098 mRawDigitalInputs[i]=false; 00099 mRawAnalogInputs[i]=0.0f; 00100 } 00101 00102 mGearUp = false; 00103 mGearDown = false; 00104 } 00105 00106 ~PxVehicleDrive4WRawInputData() 00107 { 00108 } 00109 00113 void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_ACCEL]=accelKeyPressed;} 00114 00118 void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_BRAKE]=brakeKeyPressed;} 00119 00123 void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;} 00124 00128 void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;} 00129 00133 void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;} 00134 00135 00139 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_ACCEL];} 00140 00144 bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_BRAKE];} 00145 00149 bool getDigitalHandbrake() const {return mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_HANDBRAKE];} 00150 00154 bool getDigitalSteerLeft() const {return mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_LEFT];} 00155 00159 bool getDigitalSteerRight() const {return mRawDigitalInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_RIGHT];} 00160 00161 00165 void setAnalogAccel(const PxReal accel) {mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_ACCEL]=accel;} 00166 00170 void setAnalogBrake(const PxReal brake) {mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_BRAKE]=brake;} 00171 00175 void setAnalogHandbrake(const PxReal handbrake) {mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_HANDBRAKE]=handbrake;} 00176 00180 void setAnalogSteer(const PxReal steer) {mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_RIGHT]=steer;} 00181 00182 00186 PxReal getAnalogAccel() const {return mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_ACCEL];} 00187 00191 PxReal getAnalogBrake() const {return mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_BRAKE];} 00192 00196 PxReal getAnalogHandbrake() const {return mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_HANDBRAKE];} 00197 00201 PxReal getAnalogSteer() const {return mRawAnalogInputs[PxVehicleDrive4W::eANALOG_INPUT_STEER_RIGHT];} 00202 00206 void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;} 00207 00211 void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;} 00212 00216 bool getGearUp() const {return mGearUp;} 00217 00221 bool getGearDown() const {return mGearDown;} 00222 00223 private: 00224 00225 bool mRawDigitalInputs[PxVehicleDrive4W::eMAX_NUM_DRIVE4W_ANALOG_INPUTS]; 00226 PxReal mRawAnalogInputs[PxVehicleDrive4W::eMAX_NUM_DRIVE4W_ANALOG_INPUTS]; 00227 00228 bool mGearUp; 00229 bool mGearDown; 00230 }; 00231 00236 void PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs 00237 (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, 00238 const PxVehicleDrive4WRawInputData& rawInputData, 00239 const PxReal timestep, 00240 PxVehicleDrive4W& focusVehicle); 00241 00246 void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs 00247 (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, 00248 const PxVehicleDrive4WRawInputData& rawInputData, 00249 const PxReal timestep, 00250 PxVehicleDrive4W& focusVehicle); 00251 00252 00257 class PxVehicleDriveTankRawInputData 00258 { 00259 public: 00260 00261 PxVehicleDriveTankRawInputData(const PxVehicleDriveTank::eDriveModel mode) 00262 : mMode(mode) 00263 { 00264 for(PxU32 i=0;i<PxVehicleDriveTank::eMAX_NUM_DRIVETANK_ANALOG_INPUTS;i++) 00265 { 00266 mRawAnalogInputs[i]=0.0f; 00267 mRawDigitalInputs[i]=false; 00268 } 00269 00270 mGearUp=false; 00271 mGearDown=false; 00272 } 00273 00274 ~PxVehicleDriveTankRawInputData() 00275 { 00276 } 00277 00281 PxVehicleDriveTank::eDriveModel getDriveModel() const 00282 { 00283 return mMode; 00284 } 00285 00289 void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_ACCEL]=b;} 00290 00294 void setDigitalLeftThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]=b;} 00295 00299 void setDigitalRightThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]=b;} 00300 00304 void setDigitalLeftBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT]=b;} 00305 00309 void setDigitalRightBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT]=b;} 00310 00314 bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_ACCEL];} 00315 00319 bool getDigitalLeftThrust() const {return mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT];} 00320 00324 bool getDigitalRightThrust() const {return mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT];} 00325 00329 bool getDigitalLeftBrake() const {return mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT];} 00330 00334 bool getDigitalRightBrake() const {return mRawDigitalInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT];} 00335 00336 00341 void setAnalogAccel(const PxF32 accel) 00342 { 00343 PX_ASSERT(accel>=-0.01f && accel<=1.01f); 00344 mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_ACCEL]=accel; 00345 } 00346 00351 void setAnalogLeftThrust(const PxF32 leftAccel) 00352 { 00353 PX_ASSERT(leftAccel>=-1.01f && leftAccel<=1.01f); 00354 PX_ASSERT(PxVehicleDriveTank::eDRIVE_MODEL_SPECIAL==mMode || leftAccel>=-0.1f); 00355 mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]=leftAccel; 00356 } 00357 00362 void setAnalogRightThrust(const PxF32 rightAccel) 00363 { 00364 PX_ASSERT(rightAccel>=-1.01f && rightAccel<=1.01f); 00365 PX_ASSERT(PxVehicleDriveTank::eDRIVE_MODEL_SPECIAL==mMode || rightAccel>=-0.1f); 00366 mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]=rightAccel; 00367 } 00368 00373 void setAnalogLeftBrake(const PxF32 leftBrake) 00374 { 00375 PX_ASSERT(leftBrake>=-0.01f && leftBrake<=1.01f); 00376 mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT]=leftBrake; 00377 } 00378 00383 void setAnalogRightBrake(const PxF32 rightBrake) 00384 { 00385 PX_ASSERT(rightBrake>=-0.01f && rightBrake<=1.01f); 00386 mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake; 00387 } 00388 00392 PxF32 getAnalogAccel() const 00393 { 00394 return mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_ACCEL]; 00395 } 00396 00400 PxF32 getAnalogLeftThrust() const 00401 { 00402 return mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_LEFT]; 00403 } 00404 00408 PxF32 getAnalogRightThrust() const 00409 { 00410 return mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_THRUST_RIGHT]; 00411 } 00412 00416 PxF32 getAnalogLeftBrake() const 00417 { 00418 return mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_LEFT]; 00419 } 00420 00424 PxF32 getAnalogRightBrake() const 00425 { 00426 return mRawAnalogInputs[PxVehicleDriveTank::eANALOG_INPUT_BRAKE_RIGHT]; 00427 } 00428 00432 void setGearUp(const bool gearUp) {mGearUp=gearUp;} 00433 00437 void setGearDown(const bool gearDown) {mGearDown=gearDown;} 00438 00442 bool getGearUp() const {return mGearUp;} 00443 00447 bool getGearDown() const {return mGearDown;} 00448 00449 private: 00450 00451 PxVehicleDriveTank::eDriveModel mMode; 00452 00453 PxReal mRawAnalogInputs[PxVehicleDriveTank::eMAX_NUM_DRIVETANK_ANALOG_INPUTS]; 00454 bool mRawDigitalInputs[PxVehicleDriveTank::eMAX_NUM_DRIVETANK_ANALOG_INPUTS]; 00455 bool mGearUp; 00456 bool mGearDown; 00457 }; 00458 00463 void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs 00464 (const PxVehicleKeySmoothingData& padSmoothing, 00465 const PxVehicleDriveTankRawInputData& rawInputData, 00466 const PxReal timestep, 00467 PxVehicleDriveTank& focusVehicle); 00468 00469 00474 void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs 00475 (const PxVehiclePadSmoothingData& padSmoothing, 00476 const PxVehicleDriveTankRawInputData& rawInputData, 00477 const PxReal timestep, 00478 PxVehicleDriveTank& focusVehicle); 00479 00480 00481 #ifndef PX_DOXYGEN 00482 } // namespace physx 00483 #endif 00484 00486 #endif //PX_VEHICLE_CONTROL_H
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com