// 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-2023 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_UTIL_CONTROL_H #define PX_VEHICLE_UTIL_CONTROL_H #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 steering values in the presence of discontinuities when a vehicle e.g. lands on the ground. Use a zero sharpness value to disable the feature (backward compatibility with previous PhysX versions). */ struct PX_DEPRECATED PxVehicleSteerFilter { PxVehicleSteerFilter(float sharpness=0.0f) : mSharpness(sharpness), mFilteredMaxSteer(0.0f) {} static PX_FORCE_INLINE float feedbackFilter(float val, float& memory, float sharpness) { if(sharpness<0.0f) sharpness = 0.0f; else if(sharpness>1.0f) sharpness = 1.0f; return memory = val * sharpness + memory * (1.0f - sharpness); } PX_FORCE_INLINE float computeMaxSteer(const bool isVehicleInAir, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxF32 vzAbs, const PxF32 timestep) const { const PxF32 targetMaxSteer = (isVehicleInAir ? 1.0f : steerVsForwardSpeedTable.getYVal(vzAbs)); if(mSharpness==0.0f) return targetMaxSteer; else return feedbackFilter(targetMaxSteer, mFilteredMaxSteer, mSharpness*timestep); } PxReal mSharpness; mutable PxReal mFilteredMaxSteer; }; /** \brief Used to produce smooth vehicle driving control values from key inputs. @see PxVehicle4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicle4WSmoothAnalogRawInputsAndSetAnalogInputs */ struct PX_DEPRECATED PxVehicleKeySmoothingData { /** \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 PX_DEPRECATED PxVehiclePadSmoothingData { /** \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, const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(), const PxVec3& forwardAxis = PxVehicleGetDefaultContext().forwardAxis); /** \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 PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs \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. \param[in] steerFilter is an optional smoothing filter for the steering angle. \param[in] forwardAxis The axis denoting the local space forward direction of the vehicle. */ PX_DEPRECATED void PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDrive4WRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDrive4W& focusVehicle, const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(), const PxVec3& forwardAxis = PxVehicleGetDefaultContext().forwardAxis); /** \brief Used to produce smooth vehicle driving control values from analog and digital inputs. @see PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs */ class PX_DEPRECATED 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 PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs \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. \param[in] steerFilter is an optional smoothing filter for the steering angle. \param[in] forwardAxis The axis denoting the local space forward direction of the vehicle. */ PX_DEPRECATED void PxVehicleDriveNWSmoothDigitalRawInputsAndSetAnalogInputs (const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW& focusVehicle, const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(), const PxVec3& forwardAxis = PxVehicleGetDefaultContext().forwardAxis); /** \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 PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs \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. \param[in] steerFilter is an optional smoothing filter for the steering angle. \param[in] forwardAxis The axis denoting the local space forward direction of the vehicle. */ PX_DEPRECATED void PxVehicleDriveNWSmoothAnalogRawInputsAndSetAnalogInputs (const PxVehiclePadSmoothingData& padSmoothing, const PxFixedSizeLookupTable<8>& steerVsForwardSpeedTable, const PxVehicleDriveNWRawInputData& rawInputData, const PxReal timestep, const bool isVehicleInAir, PxVehicleDriveNW& focusVehicle, const PxVehicleSteerFilter& steerFilter = PxVehicleSteerFilter(), const PxVec3& forwardAxis = PxVehicleGetDefaultContext().forwardAxis); /** \brief Used to produce smooth analog tank control values from analog and digital inputs. @see PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs */ class PX_DEPRECATED PxVehicleDriveTankRawInputData { public: PxVehicleDriveTankRawInputData(const PxVehicleDriveTankControlModel::Enum mode) : mMode(mode) { for(PxU32 i=0;i