// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #ifndef PX_VEHICLE_CONTROL_H #define PX_VEHICLE_CONTROL_H /** \addtogroup vehicle @{ */ #include "vehicle/PxVehicleSDK.h" #include "vehicle/PxVehicleDrive4W.h" #include "vehicle/PxVehicleDriveNW.h" #include "vehicle/PxVehicleDriveTank.h" #if !PX_DOXYGEN namespace physx { #endif #if PX_CHECKED void testValidAnalogValue(const PxF32 actualValue, const PxF32 minVal, const PxF32 maxVal, const char* errorString); #endif /** \brief Used to produce smooth vehicle driving control values from key inputs. @see PxVehicle4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicle4WSmoothAnalogRawInputsAndSetAnalogInputs */ struct PxVehicleKeySmoothingData { public: /** \brief Rise rate of each analog value if digital value is 1 */ PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS]; /** \brief Fall rate of each analog value if digital value is 0 */ PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS]; }; PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleKeySmoothingData)& 0x0f)); /** \brief Used to produce smooth analog vehicle control values from analog inputs. @see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs */ struct PxVehiclePadSmoothingData { public: /** \brief Rise rate of each analog value from previous value towards target if target>previous */ PxReal mRiseRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS]; /** \brief Rise rate of each analog value from previous value towards target if target& steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W& focusVehicle); /** \brief Used to smooth and set analog vehicle control values from analog inputs (gamepad). Also used to set boolean gearup, geardown values. \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. \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed. \param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle. \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs \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. \param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs. */ void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W& focusVehicle); /** \brief Used to produce smooth vehicle driving control values from analog and digital inputs. @see PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs */ class PxVehicleDriveNWRawInputData : public PxVehicleDrive4WRawInputData { public: PxVehicleDriveNWRawInputData() : PxVehicleDrive4WRawInputData(){} ~PxVehicleDriveNWRawInputData(){} }; /** \brief Used to smooth and set analog vehicle control values (accel,brake,handbrake,steer) from digital inputs (keyboard). Also used to set boolean gearup, geardown values. \param[in] keySmoothing describes the rise and fall rates of the corresponding analog values when keys are pressed on and off. \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed. \param[in] rawInputData is the state of all digital inputs that control the vehicle. \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs \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. \param[in] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs. */ void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW& focusVehicle); /** \brief Used to smooth and set analog vehicle control values from analog inputs (gamepad). Also used to set boolean gearup, geardown values. \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. \param[in] steerVsForwardSpeedTable is a table of maximum allowed steer versus forward vehicle speed. \param[in] rawInputData is the state of all gamepad analog inputs that will be used control the vehicle. \param[in] timestep is the time that has passed since the last call to PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs \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. \param[in] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs. */ void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW& focusVehicle); /** \brief Used to produce smooth analog tank control values from analog and digital inputs. @see PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs */ class PxVehicleDriveTankRawInputData { public: PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode) : mMode(mode) { for(PxU32 i=0;i