Basic physics with boxes
This commit is contained in:
1 parent
1d97a6f543
commit
b4c704f5ec
259 files changed
+48478
-91
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,565 @@
|
||||
//
|
||||
// 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-2021 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_DRIVE_H
|
||||
#define PX_VEHICLE_DRIVE_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleWheels.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxFilterData;
|
||||
class PxGeometry;
|
||||
class PxPhysics;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxShape;
|
||||
class PxMaterial;
|
||||
class PxRigidDynamic;
|
||||
|
||||
/**
|
||||
\brief Data structure describing non-wheel configuration data of a vehicle that has engine, gears, clutch, and auto-box.
|
||||
@see PxVehicleWheelsSimData for wheels configuration data.
|
||||
*/
|
||||
class PxVehicleDriveSimData
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleDriveTank;
|
||||
|
||||
/**
|
||||
\brief Return the engine data
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleEngineData& getEngineData() const
|
||||
{
|
||||
return mEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the engine data
|
||||
\param[in] engine - the data stored in engine is copied to the vehicle's engine.
|
||||
*/
|
||||
void setEngineData(const PxVehicleEngineData& engine);
|
||||
|
||||
/**
|
||||
\brief Return the gears data
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleGearsData& getGearsData() const
|
||||
{
|
||||
return mGears;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the gears data
|
||||
\param[in] gears - the data stored in gears is copied to the vehicle's gears.
|
||||
*/
|
||||
void setGearsData(const PxVehicleGearsData& gears);
|
||||
|
||||
/**
|
||||
\brief Return the clutch data
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleClutchData& getClutchData() const
|
||||
{
|
||||
return mClutch;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the clutch data
|
||||
\param[in] clutch - the data stored in clutch is copied to the vehicle's clutch.
|
||||
*/
|
||||
void setClutchData(const PxVehicleClutchData& clutch);
|
||||
|
||||
/**
|
||||
\brief Return the autobox data
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleAutoBoxData& getAutoBoxData() const
|
||||
{
|
||||
return mAutoBox;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the autobox data
|
||||
\param[in] autobox - the data stored in autobox is copied to the vehicle's autobox.
|
||||
*/
|
||||
void setAutoBoxData(const PxVehicleAutoBoxData& autobox);
|
||||
|
||||
protected:
|
||||
/*
|
||||
\brief Engine simulation data
|
||||
@see setEngineData, getEngineData
|
||||
*/
|
||||
PxVehicleEngineData mEngine;
|
||||
|
||||
/*
|
||||
\brief Gear simulation data
|
||||
@see setGearsData, getGearsData
|
||||
*/
|
||||
PxVehicleGearsData mGears;
|
||||
|
||||
/*
|
||||
\brief Clutch simulation data
|
||||
@see setClutchData, getClutchData
|
||||
*/
|
||||
PxVehicleClutchData mClutch;
|
||||
|
||||
/*
|
||||
\brief Autobox simulation data
|
||||
@see setAutoboxData, getAutoboxData
|
||||
*/
|
||||
PxVehicleAutoBoxData mAutoBox;
|
||||
|
||||
/**
|
||||
\brief Test that a PxVehicleDriveSimData instance has been configured with legal data.
|
||||
Call only after setting all components with setEngineData,setGearsData,setClutchData,setAutoBoxData
|
||||
@see PxVehicleDrive4W::setup, PxVehicleDriveTank::setup
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveSimData() {}
|
||||
PxVehicleDriveSimData(const PxEMPTY) : mEngine(PxEmpty), mGears(PxEmpty), mClutch(PxEmpty), mAutoBox(PxEmpty) {}
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimData) & 15));
|
||||
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data for vehicle with engine, clutch, gears, autobox
|
||||
@see PxVehicleWheelsDynData for wheels dynamics data.
|
||||
*/
|
||||
class PxVehicleDriveDynData
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
eMAX_NB_ANALOG_INPUTS=16
|
||||
};
|
||||
|
||||
friend class PxVehicleDrive;
|
||||
|
||||
/**
|
||||
\brief Set all dynamics data to zero to bring the vehicle to rest.
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Set an analog control value to drive the vehicle.
|
||||
\param[in] type describes the type of analog control being modified
|
||||
\param[in] analogVal is the new value of the specific analog control.
|
||||
@see PxVehicleDrive4WControl, PxVehicleDriveNWControl, PxVehicleDriveTankControl
|
||||
*/
|
||||
void setAnalogInput(const PxU32 type, const PxReal analogVal);
|
||||
|
||||
/**
|
||||
\brief Get the analog control value that has been applied to the vehicle.
|
||||
\return The value of the specified analog control value.
|
||||
@see PxVehicleDrive4WControl, PxVehicleDriveNWControl, PxVehicleDriveTankControl
|
||||
*/
|
||||
PxReal getAnalogInput(const PxU32 type) const;
|
||||
|
||||
/**
|
||||
\brief Inform the vehicle that the gear-up button has been pressed.
|
||||
|
||||
\param[in] digitalVal is the state of the gear-up button.
|
||||
|
||||
\note If digitalVal is true the vehicle will attempt to initiate a gear change at the next call to PxVehicleUpdates.
|
||||
|
||||
\note The value of mGearUpPressed is not reset by PxVehicleUpdates
|
||||
*/
|
||||
void setGearUp(const bool digitalVal)
|
||||
{
|
||||
mGearUpPressed = digitalVal;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set that the gear-down button has been pressed.
|
||||
|
||||
\param[in] digitalVal is the state of the gear-down button.
|
||||
|
||||
\note If digitalVal is true the vehicle will attempt to initiate a gear change at the next call to PxVehicleUpdates.
|
||||
|
||||
\note The value of mGearDownPressed is not reset by PxVehicleUpdates
|
||||
*/
|
||||
void setGearDown(const bool digitalVal)
|
||||
{
|
||||
mGearDownPressed = digitalVal;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Check if the gear-up button has been pressed
|
||||
\return The state of the gear-up button.
|
||||
*/
|
||||
bool getGearUp() const
|
||||
{
|
||||
return mGearUpPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Check if the gear-down button has been pressed
|
||||
\return The state of the gear-down button.
|
||||
*/
|
||||
bool getGearDown() const
|
||||
{
|
||||
return mGearDownPressed;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the flag that will be used to select auto-gears
|
||||
If useAutoGears is true the auto-box will be active.
|
||||
\param[in] useAutoGears is the active state of the auto-box.
|
||||
*/
|
||||
PX_FORCE_INLINE void setUseAutoGears(const bool useAutoGears)
|
||||
{
|
||||
mUseAutoGears=useAutoGears;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get the flag status that is used to select auto-gears
|
||||
\return The active status of the auto-box.
|
||||
*/
|
||||
PX_FORCE_INLINE bool getUseAutoGears() const
|
||||
{
|
||||
return mUseAutoGears;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Toggle the auto-gears flag
|
||||
If useAutoGears is true the auto-box will be active.
|
||||
*/
|
||||
PX_FORCE_INLINE void toggleAutoGears()
|
||||
{
|
||||
mUseAutoGears = !mUseAutoGears;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the current gear.
|
||||
|
||||
\param[in] currentGear is the vehicle's gear.
|
||||
|
||||
\note If the target gear is different from the current gear the vehicle will
|
||||
attempt to start a gear change from the current gear that has just been set
|
||||
towards the target gear at the next call to PxVehicleUpdates.
|
||||
|
||||
@see setTargetGear, PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE void setCurrentGear(PxU32 currentGear)
|
||||
{
|
||||
mCurrentGear = currentGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get the current gear.
|
||||
|
||||
\return The vehicle's current gear.
|
||||
|
||||
@see getTargetGear, PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE PxU32 getCurrentGear() const
|
||||
{
|
||||
return mCurrentGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the target gear.
|
||||
|
||||
\param[in] targetGear is the vehicle's target gear.
|
||||
|
||||
\note If the target gear is different from the current gear the vehicle will
|
||||
attempt to start a gear change towards the target gear at the next call to
|
||||
PxVehicleUpdates.
|
||||
|
||||
@see PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE void setTargetGear(PxU32 targetGear)
|
||||
{
|
||||
mTargetGear = targetGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Get the target gear.
|
||||
|
||||
\return The vehicle's target gear.
|
||||
|
||||
@see setTargetGear, PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE PxU32 getTargetGear() const
|
||||
{
|
||||
return mTargetGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Start a gear change to a target gear.
|
||||
|
||||
\param[in] targetGear is the gear the vehicle will begin a transition towards.
|
||||
|
||||
\note The gear change will begin at the next call to PxVehicleUpadates.
|
||||
|
||||
@see PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
|
||||
{
|
||||
mTargetGear=targetGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Force an immediate gear change to a target gear
|
||||
|
||||
\param[in] targetGear is the gear the vehicle will be given immediately.
|
||||
|
||||
@see PxVehicleGearsData
|
||||
*/
|
||||
PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
|
||||
{
|
||||
mTargetGear=targetGear;
|
||||
mCurrentGear=targetGear;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the rotation speed of the engine (radians per second)
|
||||
|
||||
\param[in] speed is the rotational speed (radians per second) to apply to the engine.
|
||||
*/
|
||||
PX_FORCE_INLINE void setEngineRotationSpeed(const PxF32 speed)
|
||||
{
|
||||
mEnginespeed = speed;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the rotation speed of the engine (radians per second)
|
||||
|
||||
\return The rotational speed (radians per second) of the engine.
|
||||
*/
|
||||
PX_FORCE_INLINE PxReal getEngineRotationSpeed() const
|
||||
{
|
||||
return mEnginespeed;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the time that has passed since the current gear change was initiated.
|
||||
|
||||
\return The time that has passed since the current gear change was initiated.
|
||||
|
||||
\note If no gear change is in process the gear switch time will be zero.
|
||||
|
||||
@see PxVehicleGearsData.mSwitchTime
|
||||
*/
|
||||
PX_FORCE_INLINE PxReal getGearSwitchTime() const
|
||||
{
|
||||
return mGearSwitchTime;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the time that has passed since the autobox last initiated a gear change.
|
||||
|
||||
\return The time that has passed since the autobox last initiated a gear change.
|
||||
|
||||
@see PxVehicleAutoBoxData::setLatency, PxVehicleAutoBoxData::getLatency
|
||||
*/
|
||||
PX_FORCE_INLINE PxReal getAutoBoxSwitchTime() const
|
||||
{
|
||||
return mAutoBoxSwitchTime;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief All dynamic data values are public for fast access.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
\brief Analog control values used by vehicle simulation.
|
||||
@see setAnalogInput, getAnalogInput, PxVehicleDrive4WControl, PxVehicleDriveNWControl, PxVehicleDriveTankControl
|
||||
*/
|
||||
PxReal mControlAnalogVals[eMAX_NB_ANALOG_INPUTS];
|
||||
|
||||
/**
|
||||
\brief Auto-gear flag used by vehicle simulation. Set true to enable the autobox, false to disable the autobox.
|
||||
@see setUseAutoGears, setUseAutoGears, toggleAutoGears, PxVehicleAutoBoxData
|
||||
*/
|
||||
bool mUseAutoGears;
|
||||
|
||||
/**
|
||||
\brief Gear-up digital control value used by vehicle simulation.
|
||||
|
||||
\note If true a gear change will be initiated towards currentGear+1 (or to first gear if in reverse).
|
||||
|
||||
@see setDigitalInput, getDigitalInput
|
||||
*/
|
||||
bool mGearUpPressed;
|
||||
|
||||
/**
|
||||
\brief Gear-down digital control value used by vehicle simulation.
|
||||
|
||||
\note If true a gear change will be initiated towards currentGear-1 (or to reverse if in first).
|
||||
|
||||
@see setDigitalInput, getDigitalInput
|
||||
*/
|
||||
bool mGearDownPressed;
|
||||
|
||||
/**
|
||||
\brief Current gear
|
||||
@see startGearChange, forceGearChange, getCurrentGear, PxVehicleGearsData
|
||||
*/
|
||||
PxU32 mCurrentGear;
|
||||
|
||||
/**
|
||||
\brief Target gear (different from current gear if a gear change is underway)
|
||||
@see startGearChange, forceGearChange, getTargetGear, PxVehicleGearsData
|
||||
*/
|
||||
PxU32 mTargetGear;
|
||||
|
||||
/**
|
||||
\brief Rotation speed of engine
|
||||
@see setToRestState, getEngineRotationSpeed
|
||||
*/
|
||||
PxReal mEnginespeed;
|
||||
|
||||
/**
|
||||
\brief Reported time that has passed since gear change started.
|
||||
@see setToRestState, startGearChange, PxVehicleGearsData::mSwitchTime
|
||||
*/
|
||||
PxReal mGearSwitchTime;
|
||||
|
||||
/**
|
||||
\brief Reported time that has passed since last autobox gearup/geardown decision.
|
||||
@see setToRestState, PxVehicleAutoBoxData::setLatency
|
||||
*/
|
||||
PxReal mAutoBoxSwitchTime;
|
||||
|
||||
private:
|
||||
PxU32 mPad[2];
|
||||
|
||||
/**
|
||||
\brief Test that a PxVehicleDriveDynData instance has legal values.
|
||||
@see setToRestState
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveDynData();
|
||||
PxVehicleDriveDynData(const PxEMPTY) {}
|
||||
PxU32 getNbAnalogInput() const { return eMAX_NB_ANALOG_INPUTS; }
|
||||
PX_FORCE_INLINE void setGearChange(const PxU32 gearChange) { mTargetGear= gearChange; }
|
||||
PX_FORCE_INLINE PxU32 getGearChange() const { return mTargetGear; }
|
||||
PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime) { mGearSwitchTime = switchTime; }
|
||||
PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime) { mAutoBoxSwitchTime = autoBoxSwitchTime; }
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveDynData) & 15));
|
||||
|
||||
/**
|
||||
\brief A complete vehicle with instance dynamics data and configuration data for wheels and engine,clutch,gears,autobox.
|
||||
@see PxVehicleDrive4W, PxVehicleDriveTank
|
||||
*/
|
||||
class PxVehicleDrive : public PxVehicleWheels
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Dynamics data of vehicle instance.
|
||||
@see setup
|
||||
*/
|
||||
PxVehicleDriveDynData mDriveDynData;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
\brief Test that all instanced dynamics data and configuration data have legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
\brief Set vehicle to rest.
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
@see PxVehicleDrive4W::allocate, PxVehicleDriveTank::allocate
|
||||
*/
|
||||
static PxU32 computeByteSize(const PxU32 numWheels);
|
||||
static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleDrive* vehDrive, PxU8* ptr);
|
||||
virtual void init(const PxU32 numWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicle4WDrive instance.
|
||||
@see PxVehicleDrive4W::free, PxVehicleDriveTank::free
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
@see PxVehicleDrive4W::setup, PxVehicleDriveTank::setup
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData,
|
||||
const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
|
||||
|
||||
//serialization
|
||||
public:
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
PxVehicleDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags), mDriveDynData(PxEmpty) {}
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleDrive"; }
|
||||
protected:
|
||||
PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags) : PxVehicleWheels(concreteType, baseFlags) {}
|
||||
~PxVehicleDrive() {}
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDrive", name) || PxBase::isKindOf(name); }
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_DRIVE_H
|
||||
@@ -0,0 +1,278 @@
|
||||
//
|
||||
// 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-2021 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_4WDRIVE_H
|
||||
#define PX_VEHICLE_4WDRIVE_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleDrive.h"
|
||||
#include "vehicle/PxVehicleWheels.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxFilterData;
|
||||
class PxGeometry;
|
||||
class PxPhysics;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxShape;
|
||||
class PxMaterial;
|
||||
class PxRigidDynamic;
|
||||
|
||||
/**
|
||||
\brief Data structure describing the drive model components of a vehicle with up to 4 driven wheels and up to 16 un-driven wheels.
|
||||
The drive model incorporates engine, clutch, gears, autobox, differential, and Ackermann steer correction.
|
||||
@see PxVehicleDriveSimData
|
||||
*/
|
||||
class PxVehicleDriveSimData4W : public PxVehicleDriveSimData
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleDrive4W;
|
||||
|
||||
PxVehicleDriveSimData4W()
|
||||
: PxVehicleDriveSimData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the data describing the differential.
|
||||
@see PxVehicleDifferential4WData
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleDifferential4WData& getDiffData() const
|
||||
{
|
||||
return mDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the data describing the Ackermann steer-correction.
|
||||
@see PxVehicleAckermannGeometryData
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleAckermannGeometryData& getAckermannGeometryData() const
|
||||
{
|
||||
return mAckermannGeometry;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the data describing the differential.
|
||||
@see PxVehicleDifferential4WData
|
||||
*/
|
||||
void setDiffData(const PxVehicleDifferential4WData& diff);
|
||||
|
||||
/**
|
||||
\brief Set the data describing the Ackermann steer-correction.
|
||||
@see PxVehicleAckermannGeometryData
|
||||
*/
|
||||
void setAckermannGeometryData(const PxVehicleAckermannGeometryData& ackermannData);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Differential simulation data
|
||||
@see setDiffData, getDiffData
|
||||
*/
|
||||
PxVehicleDifferential4WData mDiff;
|
||||
|
||||
/**
|
||||
\brief Data for ackermann steer angle computation.
|
||||
@see setAckermannGeometryData, getAckermannGeometryData
|
||||
*/
|
||||
PxVehicleAckermannGeometryData mAckermannGeometry;
|
||||
|
||||
/**
|
||||
\brief Test if the 4W-drive simulation data has been setup with legal data.
|
||||
\note Call only after setting all components.
|
||||
@see setEnginedata, setClutchData, setGearsData, setAutoboxData, setDiffData, setAckermannGeometryData
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveSimData4W(const PxEMPTY) : PxVehicleDriveSimData(PxEmpty), mDiff(PxEmpty), mAckermannGeometry(PxEmpty) {}
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimData4W) & 15));
|
||||
|
||||
|
||||
|
||||
/**
|
||||
\brief The ordering of the driven and steered wheels of a PxVehicleDrive4W.
|
||||
|
||||
@see PxVehicleWheelsSimData, PxVehicleWheelsDynData
|
||||
*/
|
||||
|
||||
struct PxVehicleDrive4WWheelOrder
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eFRONT_LEFT=0,
|
||||
eFRONT_RIGHT,
|
||||
eREAR_LEFT,
|
||||
eREAR_RIGHT
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
\brief The control inputs for a PxVehicleDrive4W.
|
||||
|
||||
@see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput
|
||||
*/
|
||||
|
||||
struct PxVehicleDrive4WControl
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eANALOG_INPUT_ACCEL=0,
|
||||
eANALOG_INPUT_BRAKE,
|
||||
eANALOG_INPUT_HANDBRAKE,
|
||||
eANALOG_INPUT_STEER_LEFT,
|
||||
eANALOG_INPUT_STEER_RIGHT,
|
||||
eMAX_NB_DRIVE4W_ANALOG_INPUTS
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data and configuration data of a vehicle with up to 4 driven wheels and up to 16 non-driven wheels.
|
||||
*/
|
||||
class PxVehicleDrive4W : public PxVehicleDrive
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleDrive4W instance for a 4WDrive vehicle with nbWheels (= 4 + number of un-driven wheels)
|
||||
|
||||
\param[in] nbWheels is the number of vehicle wheels (= 4 + number of un-driven wheels)
|
||||
|
||||
\return The instantiated vehicle.
|
||||
|
||||
@see free, setup
|
||||
*/
|
||||
static PxVehicleDrive4W* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleDrive4W instance.
|
||||
@see allocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Set up a vehicle using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the vehicle's drive model (gears/engine/clutch/differential/autobox). The vehicle instance takes a copy of this data.
|
||||
\param[in] nbNonDrivenWheels is the number of wheels on the vehicle that cannot be connected to the differential (= numWheels - 4).
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
\note wheelsData must contain data for at least 4 wheels. Unwanted wheels can be disabled with PxVehicleWheelsSimData::disableWheel after calling setup.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData4W& driveData,
|
||||
const PxU32 nbNonDrivenWheels);
|
||||
|
||||
/**
|
||||
\brief Allocate and set up a vehicle using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the vehicle's drive model (gears/engine/clutch/differential/autobox). The vehicle instance takes a copy of this data.
|
||||
\param[in] nbNonDrivenWheels is the number of wheels on the vehicle that cannot be connected to the differential (= numWheels - 4).
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
\note wheelsData must contain data for at least 4 wheels. Unwanted wheels can be disabled with PxVehicleWheelsSimData::disableWheel after calling setup.
|
||||
\return The instantiated vehicle.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
*/
|
||||
static PxVehicleDrive4W* create
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData4W& driveData,
|
||||
const PxU32 nbNonDrivenWheels);
|
||||
|
||||
/**
|
||||
\brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
|
||||
to the state they were in immediately after setup or create.
|
||||
\note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
|
||||
raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
|
||||
@see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Simulation data that describes the configuration of the vehicle's drive model.
|
||||
@see setup, create
|
||||
*/
|
||||
PxVehicleDriveSimData4W mDriveSimData;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Test if the instanced dynamics and configuration data has legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
//serialization
|
||||
protected:
|
||||
PxVehicleDrive4W();
|
||||
~PxVehicleDrive4W(){}
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDrive4W", name) || PxBase::isKindOf(name); }
|
||||
public:
|
||||
static PxVehicleDrive4W* createObject(PxU8*& address, PxDeserializationContext& context);
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
PxVehicleDrive4W(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags), mDriveSimData(PxEmpty) {}
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleDrive4W"; }
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive4W) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_4WDRIVE_H
|
||||
@@ -0,0 +1,236 @@
|
||||
//
|
||||
// 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-2021 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_NWDRIVE_H
|
||||
#define PX_VEHICLE_NWDRIVE_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleDrive.h"
|
||||
#include "vehicle/PxVehicleWheels.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxFilterData;
|
||||
class PxGeometry;
|
||||
class PxPhysics;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxShape;
|
||||
class PxMaterial;
|
||||
class PxRigidDynamic;
|
||||
|
||||
/**
|
||||
\brief Data structure describing configuration data of a vehicle with up to PX_MAX_NB_WHEELS driven equally through the differential. The vehicle has an
|
||||
engine, clutch, gears, autobox, differential.
|
||||
@see PxVehicleDriveSimData
|
||||
*/
|
||||
class PxVehicleDriveSimDataNW : public PxVehicleDriveSimData
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleDriveNW;
|
||||
|
||||
PxVehicleDriveSimDataNW()
|
||||
: PxVehicleDriveSimData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the data describing the differential of a vehicle with up to PX_MAX_NB_WHEELS driven wheels.
|
||||
*/
|
||||
const PxVehicleDifferentialNWData& getDiffData() const
|
||||
{
|
||||
return mDiff;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the data describing the differential of a vehicle with up to PX_MAX_NB_WHEELS driven wheels.
|
||||
The differential data describes the set of wheels that are driven by the differential.
|
||||
*/
|
||||
void setDiffData(const PxVehicleDifferentialNWData& diff);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Differential simulation data
|
||||
@see setDiffData, getDiffData
|
||||
*/
|
||||
PxVehicleDifferentialNWData mDiff;
|
||||
|
||||
/**
|
||||
\brief Test if the NW-drive simulation data has been setup with legal data.
|
||||
Call only after setting all components.
|
||||
@see setEngineData, setClutchData, setGearsData, setAutoboxData, setDiffData, setAckermannGeometryData
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveSimDataNW(const PxEMPTY) : PxVehicleDriveSimData(PxEmpty), mDiff(PxEmpty) {}
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimDataNW) & 15));
|
||||
|
||||
|
||||
/**
|
||||
\brief The control inputs for a PxVehicleDriveNW.
|
||||
|
||||
@see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput
|
||||
*/
|
||||
struct PxVehicleDriveNWControl
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eANALOG_INPUT_ACCEL=0,
|
||||
eANALOG_INPUT_BRAKE,
|
||||
eANALOG_INPUT_HANDBRAKE,
|
||||
eANALOG_INPUT_STEER_LEFT,
|
||||
eANALOG_INPUT_STEER_RIGHT,
|
||||
eMAX_NB_DRIVENW_ANALOG_INPUTS
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data and configuration data of a vehicle with up to PX_MAX_NB_WHEELS driven wheels.
|
||||
*/
|
||||
class PxVehicleDriveNW : public PxVehicleDrive
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleDriveNW instance for a NWDrive vehicle with nbWheels
|
||||
|
||||
\param[in] nbWheels is the number of wheels on the vehicle.
|
||||
|
||||
\return The instantiated vehicle.
|
||||
|
||||
@see free, setup
|
||||
*/
|
||||
static PxVehicleDriveNW* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleDriveNW instance.
|
||||
@see allocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Set up a vehicle using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the vehicle's drive model (gears/engine/clutch/differential/autobox). The vehicle instance takes a copy of this data.
|
||||
\param[in] nbWheels is the number of wheels on the vehicle.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimDataNW& driveData,
|
||||
const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Allocate and set up a vehicle using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the vehicle's drive model (gears/engine/clutch/differential/autobox). The vehicle instance takes a copy of this data.
|
||||
\param[in] nbWheels is the number of wheels on the vehicle.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
\return The instantiated vehicle.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
*/
|
||||
static PxVehicleDriveNW* create
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimDataNW& driveData,
|
||||
const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
|
||||
to the state they were in immediately after setup or create.
|
||||
\note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
|
||||
raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
|
||||
@see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Simulation data that describes the configuration of the vehicle's drive model.
|
||||
@see setup, create
|
||||
*/
|
||||
PxVehicleDriveSimDataNW mDriveSimData;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Test if the instanced dynamics and configuration data has legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveNW(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags), mDriveSimData(PxEmpty) {}
|
||||
PxVehicleDriveNW();
|
||||
~PxVehicleDriveNW(){}
|
||||
static PxVehicleDriveNW* createObject(PxU8*& address, PxDeserializationContext& context);
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleDriveNW"; }
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDriveNW", name) || PxBase::isKindOf(name); }
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveNW) & 15));
|
||||
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_NWDRIVE_H
|
||||
@@ -0,0 +1,280 @@
|
||||
//
|
||||
// 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-2021 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_DRIVE_TANK_H
|
||||
#define PX_VEHICLE_DRIVE_TANK_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleDrive.h"
|
||||
#include "vehicle/PxVehicleWheels.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxFilterData;
|
||||
class PxGeometry;
|
||||
class PxPhysics;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxShape;
|
||||
class PxMaterial;
|
||||
class PxRigidDynamic;
|
||||
|
||||
/**
|
||||
\brief The ordering of the wheels of a PxVehicleDriveTank.
|
||||
|
||||
@see PxVehicleWheelsSimData, PxVehicleWheelsDynData
|
||||
*/
|
||||
struct PxVehicleDriveTankWheelOrder
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eFRONT_LEFT=0,
|
||||
eFRONT_RIGHT,
|
||||
e1ST_FROM_FRONT_LEFT,
|
||||
e1ST_FROM_FRONT_RIGHT,
|
||||
e2ND_FROM_FRONT_LEFT,
|
||||
e2ND_FROM_FRONT_RIGHT,
|
||||
e3RD_FROM_FRONT_LEFT,
|
||||
e3RD_FROM_FRONT_RIGHT,
|
||||
e4TH_FROM_FRONT_LEFT,
|
||||
e4TH_FROM_FRONT_RIGHT,
|
||||
e5TH_FROM_FRONT_LEFT,
|
||||
e5TH_FROM_FRONT_RIGHT,
|
||||
e6TH_FROM_FRONT_LEFT,
|
||||
e6TH_FROM_FRONT_RIGHT,
|
||||
e7TH_FROM_FRONT_LEFT,
|
||||
e7TH_FROM_FRONT_RIGHT,
|
||||
e8TH_FROM_FRONT_LEFT,
|
||||
e8TH_FROM_FRONT_RIGHT,
|
||||
e9TH_FROM_FRONT_LEFT,
|
||||
e9TH_FROM_FRONT_RIGHT
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief The control inputs for a PxVehicleDriveTank.
|
||||
|
||||
\note The values of eANALOG_INPUT_THRUST_LEFT and eANALOG_INPUT_THRUST_RIGHT determine how much
|
||||
of the total available drive torque is diverted to the left and right wheels. These entries in the
|
||||
enumerated list represent the state of the left and right control sticks of a tank. The total available
|
||||
drive torque available is controlled by eANALOG_INPUT_ACCEL, which represents the state of the acceleration
|
||||
pedal and controls how much torque will be applied to the engine.
|
||||
|
||||
\note To accelerate forwards eANALOG_INPUT_ACCEL must be greater than zero so that torque is applied to drive the
|
||||
engine, while eANALOG_INPUT_THRUST_LEFT and eANALOG_INPUT_THRUST_RIGHT must also be greater than zero
|
||||
to divert the available drive torque to the left and wheels. If eANALOG_INPUT_THRUST_LEFT > eANALOG_INPUT_THRUST_RIGHT
|
||||
the tank will turn to the right. If eANALOG_INPUT_THRUST_RIGHT > eANALOG_INPUT_THRUST_LEFT
|
||||
the tank will turn to the left.
|
||||
|
||||
@see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput
|
||||
*/
|
||||
|
||||
struct PxVehicleDriveTankControl
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eANALOG_INPUT_ACCEL=0,
|
||||
eANALOG_INPUT_BRAKE_LEFT,
|
||||
eANALOG_INPUT_BRAKE_RIGHT,
|
||||
eANALOG_INPUT_THRUST_LEFT,
|
||||
eANALOG_INPUT_THRUST_RIGHT,
|
||||
eMAX_NB_DRIVETANK_ANALOG_INPUTS
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Two driving models are supported.
|
||||
|
||||
\note If eSTANDARD is chosen the left and right wheels are always driven in the same direction. If the tank is in
|
||||
a forward gear the left and right wheels will all be driven forwards, while in reverse gear the left and right wheels
|
||||
will all be driven backwards. With eSTANDARD the legal range of left and right thrust is (0,1).
|
||||
|
||||
\note If eSPECIAL is chosen it is possible to drive the left and right wheels in different directions.
|
||||
With eSPECIAL the legal range of left and right thrust is (-1,1). In forward(reverse) gear negative thrust values drive the wheels
|
||||
backwards(forwards), while positive thrust values drives the wheels forwards(backwards).
|
||||
|
||||
\note A sharp left turn can be achieved in eSTANDARD mode by braking with the left wheels and thrusting forward with the
|
||||
right wheels. A smaller turning circle can theoretically be achieved in eSPECIAL mode by applying negative thrust to the left wheels and positive
|
||||
thrust to the right wheels.
|
||||
|
||||
\note In both modes the legal ranges of acceleration and left/right brake are all (0,1).
|
||||
|
||||
@see PxVehicleDriveTank::setDriveModel
|
||||
*/
|
||||
struct PxVehicleDriveTankControlModel
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eSTANDARD=0,
|
||||
eSPECIAL
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data and configuration data of a tank.
|
||||
*/
|
||||
class PxVehicleDriveTank : public PxVehicleDrive
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleTankDrive instance for a tank with nbWheels
|
||||
|
||||
\param[in] nbWheels is the number of wheels on the vehicle.
|
||||
|
||||
\note It is assumed that all wheels are driven wheels.
|
||||
|
||||
\return The instantiated vehicle.
|
||||
|
||||
@see free, setup
|
||||
*/
|
||||
static PxVehicleDriveTank* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleDriveTank instance.
|
||||
@see allocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Set up a tank using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the tank in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the tank. The tank instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the tank's drive model (gears/engine/clutch/autobox). The tank instance takes a copy of this data.
|
||||
\param[in] nbDrivenWheels is the number of wheels on the tank.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
\note nbDrivenWheels must be an even number
|
||||
\note The wheels must be arranged according to PxVehicleDriveTankWheelOrder; that is,
|
||||
the even wheels are on the left side of the tank and the odd wheels are on the right side of the tank.
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData& driveData,
|
||||
const PxU32 nbDrivenWheels);
|
||||
|
||||
/**
|
||||
\brief Allocate and set up a tank using simulation data for the wheels and drive model.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the tank.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the tank in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the tank. The tank instance takes a copy of this data.
|
||||
\param[in] driveData describes the properties of the tank's drive model (gears/engine/clutch/differential/autobox). The tank instance takes a copy of this data.
|
||||
\param[in] nbDrivenWheels is the number of wheels on the tank.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheelsSimData::setWheelShapeMapping.
|
||||
\return The instantiated vehicle.
|
||||
@see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
|
||||
*/
|
||||
static PxVehicleDriveTank* create
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData& driveData,
|
||||
const PxU32 nbDrivenWheels);
|
||||
|
||||
/**
|
||||
\brief Set the control model used by the tank.
|
||||
\note eDRIVE_MODEL_STANDARD: turning achieved by braking on one side, accelerating on the other side.
|
||||
\note eDRIVE_MODEL_SPECIAL: turning achieved by accelerating forwards on one side, accelerating backwards on the other side.
|
||||
\note The default value is eDRIVE_MODEL_STANDARD
|
||||
*/
|
||||
void setDriveModel(const PxVehicleDriveTankControlModel::Enum driveModel)
|
||||
{
|
||||
mDriveModel=driveModel;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the control model used by the tank.
|
||||
*/
|
||||
PxVehicleDriveTankControlModel::Enum getDriveModel() const {return mDriveModel;}
|
||||
|
||||
/**
|
||||
\brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
|
||||
to the state they were in immediately after setup or create.
|
||||
\note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
|
||||
raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
|
||||
@see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Simulation data that models vehicle components
|
||||
@see setup, create
|
||||
*/
|
||||
PxVehicleDriveSimData mDriveSimData;
|
||||
|
||||
private:
|
||||
/**
|
||||
\brief Test if the instanced dynamics and configuration data has legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
\brief Drive model
|
||||
@see setDriveModel, getDriveModel, PxVehicleDriveTankControlModel
|
||||
*/
|
||||
PxVehicleDriveTankControlModel::Enum mDriveModel;
|
||||
|
||||
PxU32 mPad[3];
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleDriveTank(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags) {}
|
||||
static PxVehicleDriveTank* createObject(PxU8*& address, PxDeserializationContext& context);
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleDriveTank"; }
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDriveTank", name) || PxBase::isKindOf(name); }
|
||||
protected:
|
||||
PxVehicleDriveTank();
|
||||
~PxVehicleDriveTank(){}
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveTank) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_DRIVE_TANK_H
|
||||
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// 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-2021 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_NO_DRIVE_H
|
||||
#define PX_VEHICLE_NO_DRIVE_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleWheels.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxFilterData;
|
||||
class PxGeometry;
|
||||
class PxPhysics;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxShape;
|
||||
class PxMaterial;
|
||||
class PxRigidDynamic;
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data and configuration data of a vehicle with no drive model.
|
||||
*/
|
||||
class PxVehicleNoDrive : public PxVehicleWheels
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleNoDrive instance for a vehicle without drive model and with nbWheels
|
||||
|
||||
\param[in] nbWheels is the number of wheels on the vehicle.
|
||||
|
||||
\return The instantiated vehicle.
|
||||
|
||||
@see free, setup
|
||||
*/
|
||||
static PxVehicleNoDrive* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleNoDrive instance.
|
||||
@see allocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Set up a vehicle using simulation data for the wheels.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheels::setWheelShapeMapping.
|
||||
@see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData);
|
||||
|
||||
/**
|
||||
\brief Allocate and set up a vehicle using simulation data for the wheels.
|
||||
\param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
|
||||
\param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK.
|
||||
\param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data.
|
||||
\note It is assumed that the first shapes of the actor are the wheel shapes, followed by the chassis shapes. To break this assumption use PxVehicleWheels::setWheelShapeMapping.
|
||||
\return The instantiated vehicle.
|
||||
@see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping
|
||||
*/
|
||||
static PxVehicleNoDrive* create
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData);
|
||||
|
||||
/**
|
||||
\brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
|
||||
to the state they were in immediately after setup or create.
|
||||
\note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
|
||||
raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
|
||||
@see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Set the brake torque to be applied to a specific wheel
|
||||
|
||||
\note The applied brakeTorque persists until the next call to setBrakeTorque
|
||||
|
||||
\note The brake torque is specified in Newton metres.
|
||||
|
||||
\param[in] id is the wheel being given the brake torque
|
||||
\param[in] brakeTorque is the value of the brake torque
|
||||
*/
|
||||
void setBrakeTorque(const PxU32 id, const PxReal brakeTorque);
|
||||
|
||||
/**
|
||||
\brief Set the drive torque to be applied to a specific wheel
|
||||
|
||||
\note The applied driveTorque persists until the next call to setDriveTorque
|
||||
|
||||
\note The brake torque is specified in Newton metres.
|
||||
|
||||
\param[in] id is the wheel being given the brake torque
|
||||
\param[in] driveTorque is the value of the brake torque
|
||||
*/
|
||||
void setDriveTorque(const PxU32 id, const PxReal driveTorque);
|
||||
|
||||
/**
|
||||
\brief Set the steer angle to be applied to a specific wheel
|
||||
|
||||
\note The applied steerAngle persists until the next call to setSteerAngle
|
||||
|
||||
\note The steer angle is specified in radians.
|
||||
|
||||
\param[in] id is the wheel being given the steer angle
|
||||
\param[in] steerAngle is the value of the steer angle in radians.
|
||||
*/
|
||||
void setSteerAngle(const PxU32 id, const PxReal steerAngle);
|
||||
|
||||
/**
|
||||
\brief Get the brake torque that has been applied to a specific wheel
|
||||
\param[in] id is the wheel being queried for its brake torque
|
||||
\return The brake torque applied to the queried wheel.
|
||||
*/
|
||||
PxReal getBrakeTorque(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Get the drive torque that has been applied to a specific wheel
|
||||
\param[in] id is the wheel being queried for its drive torque
|
||||
\return The drive torque applied to the queried wheel.
|
||||
*/
|
||||
PxReal getDriveTorque(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Get the steer angle that has been applied to a specific wheel
|
||||
\param[in] id is the wheel being queried for its steer angle
|
||||
\return The steer angle (in radians) applied to the queried wheel.
|
||||
*/
|
||||
PxReal getSteerAngle(const PxU32 id) const;
|
||||
|
||||
private:
|
||||
|
||||
PxReal* mSteerAngles;
|
||||
PxReal* mDriveTorques;
|
||||
PxReal* mBrakeTorques;
|
||||
|
||||
#if PX_P64_FAMILY
|
||||
PxU32 mPad[2];
|
||||
#else
|
||||
PxU32 mPad[1];
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief Test if the instanced dynamics and configuration data has legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleNoDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags) {}
|
||||
virtual void exportExtraData(PxSerializationContext&);
|
||||
void importExtraData(PxDeserializationContext&);
|
||||
static PxVehicleNoDrive* createObject(PxU8*& address, PxDeserializationContext& context);
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleNoDrive"; }
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleNoDrive", name) || PxBase::isKindOf(name); }
|
||||
PxU32 getNbSteerAngle() const { return mWheelsSimData.getNbWheels(); }
|
||||
PxU32 getNbDriveTorque() const { return mWheelsSimData.getNbWheels(); }
|
||||
PxU32 getNbBrakeTorque() const { return mWheelsSimData.getNbWheels(); }
|
||||
protected:
|
||||
PxVehicleNoDrive();
|
||||
~PxVehicleNoDrive() {}
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleNoDrive) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_NO_DRIVE_H
|
||||
@@ -0,0 +1,237 @@
|
||||
//
|
||||
// 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-2021 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_SDK_H
|
||||
#define PX_VEHICLE_SDK_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "foundation/Px.h"
|
||||
#include "common/PxTypeInfo.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
class PxPhysics;
|
||||
class PxSerializationRegistry;
|
||||
|
||||
/**
|
||||
\brief Initialize the PhysXVehicle library.
|
||||
|
||||
Call this before using any of the vehicle functions.
|
||||
|
||||
\param physics The PxPhysics instance.
|
||||
\param serializationRegistry PxSerializationRegistry instance, if NULL vehicle serialization is not supported.
|
||||
|
||||
\note This function must be called after PxFoundation and PxPhysics instances have been created.
|
||||
\note If a PxSerializationRegistry instance is specified then PhysXVehicle is also dependent on PhysXExtensions.
|
||||
|
||||
@see PxCloseVehicleSDK
|
||||
*/
|
||||
PX_C_EXPORT bool PX_CALL_CONV PxInitVehicleSDK(PxPhysics& physics, PxSerializationRegistry* serializationRegistry = NULL);
|
||||
|
||||
|
||||
/**
|
||||
\brief Shut down the PhysXVehicle library.
|
||||
|
||||
Call this function as part of the physx shutdown process.
|
||||
|
||||
\param serializationRegistry PxSerializationRegistry instance, if non-NULL must be the same as passed into PxInitVehicleSDK.
|
||||
|
||||
\note This function must be called prior to shutdown of PxFoundation and PxPhysics.
|
||||
\note If the PxSerializationRegistry instance is specified this function must additionally be called prior to shutdown of PhysXExtensions.
|
||||
|
||||
@see PxInitVehicleSDK
|
||||
*/
|
||||
PX_C_EXPORT void PX_CALL_CONV PxCloseVehicleSDK(PxSerializationRegistry* serializationRegistry = NULL);
|
||||
|
||||
|
||||
/**
|
||||
\brief This number is the maximum number of wheels allowed for a vehicle.
|
||||
*/
|
||||
#define PX_MAX_NB_WHEELS (20)
|
||||
|
||||
|
||||
/**
|
||||
\brief Compiler setting to enable recording of telemetry data
|
||||
|
||||
@see PxVehicleUpdateSingleVehicleAndStoreTelemetryData, PxVehicleTelemetryData
|
||||
*/
|
||||
#define PX_DEBUG_VEHICLE_ON (1)
|
||||
|
||||
|
||||
/**
|
||||
@see PxVehicleDrive4W, PxVehicleDriveTank, PxVehicleDriveNW, PxVehicleNoDrive, PxVehicleWheels::getVehicleType
|
||||
*/
|
||||
struct PxVehicleTypes
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eDRIVE4W=0,
|
||||
eDRIVENW,
|
||||
eDRIVETANK,
|
||||
eNODRIVE,
|
||||
eUSER1,
|
||||
eUSER2,
|
||||
eUSER3,
|
||||
eMAX_NB_VEHICLE_TYPES
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief An enumeration of concrete vehicle classes inheriting from PxBase.
|
||||
\note This enum can be used to identify a vehicle object stored in a PxCollection.
|
||||
@see PxBase, PxTypeInfo, PxBase::getConcreteType
|
||||
*/
|
||||
struct PxVehicleConcreteType
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eVehicleNoDrive = PxConcreteType::eFIRST_VEHICLE_EXTENSION,
|
||||
eVehicleDrive4W,
|
||||
eVehicleDriveNW,
|
||||
eVehicleDriveTank
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief Set the basis vectors of the vehicle simulation
|
||||
|
||||
Default values PxVec3(0,1,0), PxVec3(0,0,1)
|
||||
|
||||
Call this function before using PxVehicleUpdates unless the default values are correct.
|
||||
*/
|
||||
void PxVehicleSetBasisVectors(const PxVec3& up, const PxVec3& forward);
|
||||
|
||||
|
||||
/**
|
||||
@see PxVehicleSetUpdateMode
|
||||
*/
|
||||
struct PxVehicleUpdateMode
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eVELOCITY_CHANGE,
|
||||
eACCELERATION
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
\brief Set the effect of PxVehicleUpdates to be either to modify each vehicle's rigid body actor
|
||||
|
||||
with an acceleration to be applied in the next PhysX SDK update or as an immediate velocity modification.
|
||||
|
||||
Default behavior is immediate velocity modification.
|
||||
|
||||
Call this function before using PxVehicleUpdates for the first time if the default is not the desired behavior.
|
||||
|
||||
@see PxVehicleUpdates
|
||||
*/
|
||||
void PxVehicleSetUpdateMode(PxVehicleUpdateMode::Enum vehicleUpdateMode);
|
||||
|
||||
/**
|
||||
|
||||
\brief Set threshold angles that are used to determine if a wheel hit is to be resolved by vehicle suspension or by rigid body collision.
|
||||
|
||||
|
||||
\note ^
|
||||
N ___
|
||||
|**
|
||||
**
|
||||
**
|
||||
%%% %%% **
|
||||
%%% %%% ** /
|
||||
/
|
||||
%%% %%% /
|
||||
/
|
||||
%%% %%% /
|
||||
C /
|
||||
%%% | ** %%% /
|
||||
| ** /
|
||||
%%% | **%%%/
|
||||
| X**
|
||||
%%% | %%% / **_| ^
|
||||
| / D
|
||||
%%% | %%% /
|
||||
| /
|
||||
| /
|
||||
| /
|
||||
|
|
||||
^ |
|
||||
S \|/
|
||||
|
||||
The diagram above depicts a wheel centered at "C" that has hit an inclined plane at point "X".
|
||||
The inclined plane has unit normal "N", while the suspension direction has unit vector "S".
|
||||
The unit vector from the wheel center to the hit point is "D".
|
||||
Hit points are analyzed by comparing the unit vectors D and N with the suspension direction S.
|
||||
This analysis is performed in the contact modification callback PxVehicleModifyWheelContacts (when enabled) and in
|
||||
PxVehicleUpdates (when non-blocking sweeps are enabled).
|
||||
If the angle between D and S is less than pointRejectAngle the hit is accepted by the suspension in PxVehicleUpdates and rejected
|
||||
by the contact modification callback PxVehicleModifyWheelContacts.
|
||||
If the angle between -N and S is less than normalRejectAngle the hit is accepted by the suspension in PxVehicleUpdates and rejected
|
||||
by the contact modification callback PxVehicleModifyWheelContacts.
|
||||
|
||||
\param pointRejectAngle is the threshold angle used when comparing the angle between D and S.
|
||||
|
||||
\param normalRejectAngle is the threshold angle used when comparing the angle between -N and S.
|
||||
|
||||
\note PxVehicleUpdates ignores the rejection angles for raycasts and for sweeps that return blocking hits.
|
||||
|
||||
\note Both angles have default values of Pi/4.
|
||||
|
||||
@see PxVehicleSuspensionSweeps, PxVehicleModifyWheelContacts
|
||||
*/
|
||||
void PxVehicleSetSweepHitRejectionAngles(const PxF32 pointRejectAngle, const PxF32 normalRejectAngle);
|
||||
|
||||
|
||||
/**
|
||||
\brief Determine the maximum acceleration experienced by PxRigidDynamic instances that are found to be in contact
|
||||
with a wheel.
|
||||
|
||||
\note Newton's Third Law states that every force has an equal and opposite force. As a consequence, forces applied to
|
||||
the suspension must be applied to dynamic objects that lie under the wheel. This can lead to instabilities, particularly
|
||||
when a heavy wheel is driving on a light object. The value of maxHitActorAcceleration clamps the applied force so that it never
|
||||
generates an acceleration greater than the specified value.
|
||||
|
||||
\note Default value of maxHitActorAcceleration is PX_MAX_REAL
|
||||
*/
|
||||
void PxVehicleSetMaxHitActorAcceleration(const PxF32 maxHitActorAcceleration);
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_SDK_H
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// 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-2021 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_SHADERS_H
|
||||
#define PX_VEHICLE_SHADERS_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief Prototype of shader function that is used to compute wheel torque and tire forces.
|
||||
\param[in] shaderData is the shader data for the tire being processed. The shader data describes the tire data in the format required by the tire model that is implemented by the shader function.
|
||||
\param[in] tireFriction is the value of friction for the contact between the tire and the ground.
|
||||
\param[in] longSlip is the value of longitudinal slip experienced by the tire.
|
||||
\param[in] latSlip is the value of lateral slip experienced by the tire.
|
||||
\param[in] camber is the camber angle of the tire in radians.
|
||||
\param[in] wheelOmega is the rotational speed of the wheel.
|
||||
\param[in] wheelRadius is the distance from the tire surface to the center of the wheel.
|
||||
\param[in] recipWheelRadius is the reciprocal of wheelRadius.
|
||||
\param[in] restTireLoad is the load force experienced by the tire when the vehicle is at rest.
|
||||
\param[in] normalisedTireLoad is a pre-computed value equal to the load force on the tire divided by restTireLoad.
|
||||
\param[in] tireLoad is the load force currently experienced by the tire (= restTireLoad*normalisedTireLoad)
|
||||
\param[in] gravity is the magnitude of gravitational acceleration.
|
||||
\param[in] recipGravity is the reciprocal of the magnitude of gravitational acceleration.
|
||||
\param[out] wheelTorque is the torque that is to be applied to the wheel around the wheel's axle.
|
||||
\param[out] tireLongForceMag is the magnitude of the longitudinal tire force to be applied to the vehicle's rigid body.
|
||||
\param[out] tireLatForceMag is the magnitude of the lateral tire force to be applied to the vehicle's rigid body.
|
||||
\param[out] tireAlignMoment is the aligning moment of the tire that is to be applied to the vehicle's rigid body (not currently used).
|
||||
@see PxVehicleWheelsDynData::setTireForceShaderFunction, PxVehicleWheelsDynData::setTireForceShaderData
|
||||
*/
|
||||
typedef void (*PxVehicleComputeTireForce)
|
||||
(const void* shaderData,
|
||||
const PxF32 tireFriction,
|
||||
const PxF32 longSlip, const PxF32 latSlip, const PxF32 camber,
|
||||
const PxF32 wheelOmega, const PxF32 wheelRadius, const PxF32 recipWheelRadius,
|
||||
const PxF32 restTireLoad, const PxF32 normalisedTireLoad, const PxF32 tireLoad,
|
||||
const PxF32 gravity, const PxF32 recipGravity,
|
||||
PxF32& wheelTorque, PxF32& tireLongForceMag, PxF32& tireLatForceMag, PxF32& tireAlignMoment);
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_SHADERS_H
|
||||
@@ -0,0 +1,223 @@
|
||||
//
|
||||
// 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-2021 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_TIREFRICTION_H
|
||||
#define PX_VEHICLE_TIREFRICTION_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
class PxMaterial;
|
||||
|
||||
/**
|
||||
\brief Driving surface type. Each PxMaterial is associated with a corresponding PxVehicleDrivableSurfaceType.
|
||||
@see PxMaterial, PxVehicleDrivableSurfaceToTireFrictionPairs
|
||||
*/
|
||||
struct PxVehicleDrivableSurfaceType
|
||||
{
|
||||
enum
|
||||
{
|
||||
eSURFACE_TYPE_UNKNOWN=0xffffffff
|
||||
};
|
||||
PxU32 mType;
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Friction for each combination of driving surface type and tire type.
|
||||
@see PxVehicleDrivableSurfaceType, PxVehicleTireData::mType
|
||||
*/
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs
|
||||
{
|
||||
public:
|
||||
|
||||
friend class VehicleSurfaceTypeHashTable;
|
||||
|
||||
enum
|
||||
{
|
||||
eMAX_NB_SURFACE_TYPES=256
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Allocate the memory for a PxVehicleDrivableSurfaceToTireFrictionPairs instance
|
||||
that can hold data for combinations of tire type and surface type with up to maxNbTireTypes types of tire and maxNbSurfaceTypes types of surface.
|
||||
|
||||
\param[in] maxNbTireTypes is the maximum number of allowed tire types.
|
||||
\param[in] maxNbSurfaceTypes is the maximum number of allowed surface types. Must be less than or equal to eMAX_NB_SURFACE_TYPES
|
||||
|
||||
\return a PxVehicleDrivableSurfaceToTireFrictionPairs instance that can be reused later with new type and friction data.
|
||||
|
||||
@see setup
|
||||
*/
|
||||
static PxVehicleDrivableSurfaceToTireFrictionPairs* allocate
|
||||
(const PxU32 maxNbTireTypes, const PxU32 maxNbSurfaceTypes);
|
||||
|
||||
/**
|
||||
\brief Set up a PxVehicleDrivableSurfaceToTireFrictionPairs instance for combinations of nbTireTypes tire types and nbSurfaceTypes surface types.
|
||||
|
||||
\param[in] nbTireTypes is the number of different types of tire. This value must be less than or equal to maxNbTireTypes specified in allocate().
|
||||
\param[in] nbSurfaceTypes is the number of different types of surface. This value must be less than or equal to maxNbSurfaceTypes specified in allocate().
|
||||
\param[in] drivableSurfaceMaterials is an array of PxMaterial pointers of length nbSurfaceTypes.
|
||||
\param[in] drivableSurfaceTypes is an array of PxVehicleDrivableSurfaceType instances of length nbSurfaceTypes.
|
||||
|
||||
\note If the pointer to the PxMaterial that touches the tire is found in drivableSurfaceMaterials[x] then the surface type is drivableSurfaceTypes[x].mType
|
||||
and the friction is the value that is set with setTypePairFriction(drivableSurfaceTypes[x].mType, PxVehicleTireData::mType, frictionValue).
|
||||
|
||||
\note A friction value of 1.0 will be assigned as default to each combination of tire and surface type. To override this use setTypePairFriction.
|
||||
@see release, setTypePairFriction, getTypePairFriction, PxVehicleTireData.mType
|
||||
*/
|
||||
void setup
|
||||
(const PxU32 nbTireTypes, const PxU32 nbSurfaceTypes,
|
||||
const PxMaterial** drivableSurfaceMaterials, const PxVehicleDrivableSurfaceType* drivableSurfaceTypes);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleDrivableSurfaceToTireFrictionPairs instance
|
||||
*/
|
||||
void release();
|
||||
|
||||
/**
|
||||
\brief Set the friction for a specified pair of tire type and drivable surface type.
|
||||
|
||||
\param[in] surfaceType describes the surface type
|
||||
\param[in] tireType describes the tire type.
|
||||
\param[in] value describes the friction coefficient for the combination of surface type and tire type.
|
||||
*/
|
||||
void setTypePairFriction(const PxU32 surfaceType, const PxU32 tireType, const PxReal value);
|
||||
|
||||
/**
|
||||
\brief Return the friction for a specified combination of surface type and tire type.
|
||||
\return The friction for a specified combination of surface type and tire type.
|
||||
\note The final friction value used by the tire model is the value returned by getTypePairFriction
|
||||
multiplied by the value computed from PxVehicleTireData::mFrictionVsSlipGraph
|
||||
@see PxVehicleTireData::mFrictionVsSlipGraph
|
||||
*/
|
||||
PxReal getTypePairFriction(const PxU32 surfaceType, const PxU32 tireType) const;
|
||||
|
||||
/**
|
||||
\brief Return the maximum number of surface types
|
||||
\return The maximum number of surface types
|
||||
@see allocate
|
||||
*/
|
||||
PxU32 getMaxNbSurfaceTypes() const {return mMaxNbSurfaceTypes;}
|
||||
|
||||
/**
|
||||
\brief Return the maximum number of tire types
|
||||
\return The maximum number of tire types
|
||||
@see allocate
|
||||
*/
|
||||
PxU32 getMaxNbTireTypes() const {return mMaxNbTireTypes;}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Ptr to base address of a 2d PxReal array with dimensions [mNbSurfaceTypes][mNbTireTypes]
|
||||
|
||||
\note Each element of the array describes the maximum friction provided by a surface type-tire type combination.
|
||||
eg the friction corresponding to a combination of surface type x and tire type y is mPairs[x][y]
|
||||
*/
|
||||
PxReal* mPairs;
|
||||
|
||||
/**
|
||||
\brief Ptr to 1d array of material ptrs that is of length mNbSurfaceTypes.
|
||||
|
||||
\note If the PxMaterial that touches the tire corresponds to mDrivableSurfaceMaterials[x] then the drivable surface
|
||||
type is mDrivableSurfaceTypes[x].mType and the friction for that contact is mPairs[mDrivableSurfaceTypes[x].mType][y],
|
||||
assuming a tire type y.
|
||||
|
||||
\note If the PxMaterial that touches the tire is not found in mDrivableSurfaceMaterials then the friction is
|
||||
mPairs[0][y], assuming a tire type y.
|
||||
*/
|
||||
const PxMaterial** mDrivableSurfaceMaterials;
|
||||
|
||||
/**
|
||||
\brief Ptr to 1d array of PxVehicleDrivableSurfaceType that is of length mNbSurfaceTypes.
|
||||
|
||||
\note If the PxMaterial that touches the tire is found in mDrivableSurfaceMaterials[x] then the drivable surface
|
||||
type is mDrivableSurfaceTypes[x].mType and the friction for that contact is mPairs[mDrivableSurfaceTypes[x].mType][y],
|
||||
assuming a tire type y.
|
||||
|
||||
\note If the PxMaterial that touches the tire is not found in mDrivableSurfaceMaterials then the friction is
|
||||
mPairs[0][y], assuming a tire type y.
|
||||
*/
|
||||
PxVehicleDrivableSurfaceType* mDrivableSurfaceTypes;
|
||||
|
||||
/**
|
||||
\brief Number of different driving surface types.
|
||||
|
||||
\note mDrivableSurfaceMaterials and mDrivableSurfaceTypes are both 1d arrays of length mMaxNbSurfaceTypes.
|
||||
|
||||
\note mNbSurfaceTypes must be less than or equal to mMaxNbSurfaceTypes.
|
||||
*/
|
||||
PxU32 mNbSurfaceTypes;
|
||||
|
||||
/**
|
||||
\brief Maximum number of different driving surface types.
|
||||
|
||||
\note mMaxNbSurfaceTypes must be less than or equal to eMAX_NB_SURFACE_TYPES.
|
||||
*/
|
||||
PxU32 mMaxNbSurfaceTypes;
|
||||
|
||||
/**
|
||||
\brief Number of different tire types.
|
||||
|
||||
\note Tire types stored in PxVehicleTireData.mType
|
||||
*/
|
||||
PxU32 mNbTireTypes;
|
||||
|
||||
/**
|
||||
\brief Maximum number of different tire types.
|
||||
|
||||
\note Tire types stored in PxVehicleTireData.mType
|
||||
*/
|
||||
PxU32 mMaxNbTireTypes;
|
||||
|
||||
|
||||
#if !PX_P64_FAMILY
|
||||
PxU32 mPad[1];
|
||||
#else
|
||||
PxU32 mPad[2];
|
||||
#endif
|
||||
|
||||
PxVehicleDrivableSurfaceToTireFrictionPairs(){}
|
||||
~PxVehicleDrivableSurfaceToTireFrictionPairs(){}
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrivableSurfaceToTireFrictionPairs) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_TIREFRICTION_H
|
||||
@@ -0,0 +1,594 @@
|
||||
//
|
||||
// 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-2021 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_UPDATE_H
|
||||
#define PX_VEHICLE_UPDATE_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleSDK.h"
|
||||
#include "vehicle/PxVehicleTireFriction.h"
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
#include "foundation/PxMemory.h"
|
||||
#include "foundation/PxTransform.h"
|
||||
#include "PxBatchQueryDesc.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
class PxBatchQuery;
|
||||
class PxContactModifyPair;
|
||||
class PxVehicleWheels;
|
||||
class PxVehicleDrivableSurfaceToTireFrictionPairs;
|
||||
class PxVehicleTelemetryData;
|
||||
|
||||
/**
|
||||
\brief Structure containing data describing the non-persistent state of each suspension/wheel/tire unit.
|
||||
This structure is filled out in PxVehicleUpdates and PxVehicleUpdateSingleVehicleAndStoreTelemetryData
|
||||
@see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData
|
||||
*/
|
||||
struct PxWheelQueryResult
|
||||
{
|
||||
PxWheelQueryResult()
|
||||
{
|
||||
PxMemZero(this, sizeof(PxWheelQueryResult));
|
||||
isInAir=true;
|
||||
tireSurfaceType = PxU32(PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN);
|
||||
localPose = PxTransform(PxIdentity);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Start point of suspension line raycast/sweep used in the raycast/sweep completed immediately before PxVehicleUpdates.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored.
|
||||
@see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts
|
||||
*/
|
||||
PxVec3 suspLineStart;
|
||||
|
||||
/**
|
||||
\brief Directions of suspension line raycast/sweep used in the raycast/sweep completed immediately before PxVehicleUpdates.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored.
|
||||
@see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts
|
||||
*/
|
||||
PxVec3 suspLineDir;
|
||||
|
||||
/**
|
||||
\brief Lengths of suspension line raycast/sweep used in raycast/sweep completed immediately before PxVehicleUpdates.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then 0 is stored.
|
||||
@see PxVehicleSuspensionRaycasts, PxVehicleSuspensionRaycasts
|
||||
*/
|
||||
PxReal suspLineLength;
|
||||
|
||||
/**
|
||||
\brief If suspension travel limits forbid the wheel from touching the drivable surface then isInAir is true.
|
||||
\note If the wheel can be placed on the contact plane of the most recent suspension line raycast/sweep then isInAir is false.
|
||||
\note If #PxVehicleWheelsSimFlag::eLIMIT_SUSPENSION_EXPANSION_VELOCITY is set, then isInAir will also be true if the suspension
|
||||
force is not large enough to expand to the target length in the given simulation time step.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then isInAir
|
||||
is computed using the contact plane that was hit by the most recent suspension line raycast/sweep.
|
||||
*/
|
||||
bool isInAir;
|
||||
|
||||
/**
|
||||
\brief PxActor instance of the driving surface under the corresponding vehicle wheel.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireContactActor is NULL.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored.
|
||||
*/
|
||||
PxActor* tireContactActor;
|
||||
|
||||
/**
|
||||
\brief PxShape instance of the driving surface under the corresponding vehicle wheel.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireContactShape is NULL.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored.
|
||||
*/
|
||||
PxShape* tireContactShape;
|
||||
|
||||
/**
|
||||
\brief PxMaterial instance of the driving surface under the corresponding vehicle wheel.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireSurfaceMaterial is NULL.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then NULL is stored.
|
||||
*/
|
||||
const PxMaterial* tireSurfaceMaterial;
|
||||
|
||||
/**
|
||||
\brief Surface type integer that corresponds to the mapping between tireSurfaceMaterial and integer as
|
||||
described in PxVehicleDrivableSurfaceToTireFrictionPairs.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireSurfaceType is
|
||||
PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN.
|
||||
\note If no raycast/sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then
|
||||
PxVehicleDrivableSurfaceType::eSURFACE_TYPE_UNKNOWN is stored.
|
||||
@see PxVehicleDrivableSurfaceToTireFrictionPairs
|
||||
*/
|
||||
PxU32 tireSurfaceType;
|
||||
|
||||
/**
|
||||
\brief Point on the drivable surface hit by the most recent suspension raycast or sweep.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then the contact point is (0,0,0).
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored.
|
||||
*/
|
||||
PxVec3 tireContactPoint;
|
||||
|
||||
/**
|
||||
\brief Normal on the drivable surface at the hit point of the most recent suspension raycast or sweep.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then the contact normal is (0,0,0).
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then (0,0,0) is stored.
|
||||
*/
|
||||
PxVec3 tireContactNormal;
|
||||
|
||||
/**
|
||||
\brief Friction experienced by the tire for the combination of tire type and surface type after accounting
|
||||
for the friction vs slip graph.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then the tire friction is 0.
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
stored tire friction is the value computed in PxVehicleUpdates that immediately followed the last raycast or sweep.
|
||||
@see PxVehicleDrivableSurfaceToTireFrictionPairs, PxVehicleTireData
|
||||
*/
|
||||
PxReal tireFriction;
|
||||
|
||||
/**
|
||||
\brief Compression of the suspension spring.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then the jounce is -PxVehicleSuspensionData.mMaxDroop
|
||||
The jounce can never exceed PxVehicleSuspensionData.mMaxCompression. Positive values result when the suspension is compressed from
|
||||
the rest position, while negative values mean the suspension is elongated from the rest position.
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
suspension compression is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
*/
|
||||
PxReal suspJounce;
|
||||
|
||||
/**
|
||||
\brief Magnitude of force applied by the suspension spring along the direction of suspension travel.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then the force is 0
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
suspension spring force is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
@see PxVehicleWheelsSimData::getSuspTravelDirection
|
||||
*/
|
||||
PxReal suspSpringForce;
|
||||
|
||||
/**
|
||||
\brief Forward direction of the wheel/tire accounting for steer/toe/camber angle projected on to the contact plane of the drivable surface.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireLongitudinalDir is (0,0,0)
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
tire longitudinal direction is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
*/
|
||||
PxVec3 tireLongitudinalDir;
|
||||
|
||||
/**
|
||||
\brief Lateral direction of the wheel/tire accounting for steer/toe/camber angle projected on to the contact plan of the drivable surface.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then tireLateralDir is (0,0,0)
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
tire lateral direction is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
*/
|
||||
PxVec3 tireLateralDir;
|
||||
|
||||
/**
|
||||
\brief Longitudinal slip of the tire.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then longitudinalSlip is 0.0
|
||||
\note The longitudinal slip is approximately (w*r - vz) / PxAbs(vz) where w is the angular speed of the wheel, r is the radius of the wheel, and
|
||||
vz component of rigid body velocity computed at the wheel base along the longitudinal direction of the tire.
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
tire longitudinal slip is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
*/
|
||||
PxReal longitudinalSlip;
|
||||
|
||||
/**
|
||||
\brief Lateral slip of the tire.
|
||||
\note If suspension travel limits forbid the wheel from touching the drivable surface then lateralSlip is 0.0
|
||||
\note The lateral slip angle is approximately PxAtan(vx / PxAbs(vz)) where vx and vz are the components of rigid body velocity at the wheel base
|
||||
along the wheel's lateral and longitudinal directions, respectively.
|
||||
\note If no raycast or sweep for the corresponding suspension was performed immediately prior to PxVehicleUpdates then the
|
||||
tire lateral slip is computed using the contact plane that was hit by the most recent suspension line raycast or sweep.
|
||||
*/
|
||||
PxReal lateralSlip;
|
||||
|
||||
/**
|
||||
\brief Steer angle of the wheel about the "up" vector accounting for input steer and toe and, if applicable, Ackermann steer correction.
|
||||
@see PxVehicleWheelData::mToeAngle
|
||||
*/
|
||||
PxReal steerAngle;
|
||||
|
||||
/**
|
||||
\brief Local pose of the wheel.
|
||||
*/
|
||||
PxTransform localPose;
|
||||
};
|
||||
|
||||
struct PxVehicleWheelQueryResult
|
||||
{
|
||||
/**
|
||||
\brief Pointer to an PxWheelQueryResult buffer of length nbWheelQueryResults
|
||||
The wheelQueryResults buffer must persist until the end of PxVehicleUpdates
|
||||
A NULL pointer is permitted.
|
||||
The wheelQueryResults buffer is left unmodified in PxVehicleUpdates for vehicles with sleeping rigid bodies
|
||||
whose control inputs indicate they should remain inert.
|
||||
@see PxVehicleUpdates
|
||||
*/
|
||||
PxWheelQueryResult* wheelQueryResults;
|
||||
|
||||
/**
|
||||
\brief The length of the wheelQueryResults buffer. This value corresponds to the
|
||||
number of wheels in the associated vehicle in PxVehicleUpdates.
|
||||
*/
|
||||
PxU32 nbWheelQueryResults;
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Structure containing data that is computed for a wheel during concurrent calls to PxVehicleUpdates or
|
||||
PxVehicleUpdateSingleVehicleAndStoreTelemetryData but which cannot be safely concurrently applied.
|
||||
|
||||
@see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData, PxVehiclePostUpdates, PxVehicleConcurrentUpdate
|
||||
*/
|
||||
struct PxVehicleWheelConcurrentUpdateData
|
||||
{
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
PxVehicleWheelConcurrentUpdateData()
|
||||
: localPose(PxTransform(PxIdentity)),
|
||||
hitActor(NULL),
|
||||
hitActorForce(PxVec3(0,0,0)),
|
||||
hitActorForcePosition(PxVec3(0,0,0))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
PxTransform localPose;
|
||||
PxRigidDynamic* hitActor;
|
||||
PxVec3 hitActorForce;
|
||||
PxVec3 hitActorForcePosition;
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Structure containing data that is computed for a vehicle and its wheels during concurrent calls to PxVehicleUpdates or
|
||||
PxVehicleUpdateSingleVehicleAndStoreTelemetryData but which cannot be safely concurrently applied.
|
||||
|
||||
@see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData, PxVehiclePostUpdates, PxVehicleWheelConcurrentUpdateData
|
||||
*/
|
||||
|
||||
struct PxVehicleConcurrentUpdateData
|
||||
{
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
PxVehicleConcurrentUpdateData()
|
||||
: concurrentWheelUpdates(NULL),
|
||||
nbConcurrentWheelUpdates(0),
|
||||
linearMomentumChange(PxVec3(0,0,0)),
|
||||
angularMomentumChange(PxVec3(0,0,0)),
|
||||
staySleeping(false),
|
||||
wakeup(false)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Pointer to an PxVehicleWheelConcurrentUpdate buffer of length nbConcurrentWheelUpdates
|
||||
The concurrentWheelUpdates buffer must persist until the end of PxVehiclePostUpdates
|
||||
A NULL pointer is not permitted.
|
||||
@see PxVehicleUpdates, PxVehiclePostUpdates
|
||||
*/
|
||||
PxVehicleWheelConcurrentUpdateData* concurrentWheelUpdates;
|
||||
|
||||
/**
|
||||
\brief The length of the concurrentWheelUpdates buffer. This value corresponds to the
|
||||
number of wheels in the associated vehicle passed to PxVehicleUpdates.
|
||||
*/
|
||||
PxU32 nbConcurrentWheelUpdates;
|
||||
|
||||
private:
|
||||
|
||||
PxVec3 linearMomentumChange;
|
||||
PxVec3 angularMomentumChange;
|
||||
bool staySleeping;
|
||||
bool wakeup;
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Perform raycasts for all suspension lines for all vehicles.
|
||||
|
||||
\param[in] batchQuery is a PxBatchQuery instance used to specify shader data and functions for the raycast scene queries.
|
||||
|
||||
\param[in] nbVehicles is the number of vehicles in the vehicles array.
|
||||
|
||||
\param[in] vehicles is an array of all vehicles that are to have a raycast issued from each wheel.
|
||||
|
||||
\param[in] nbSceneQueryResults must be greater than or equal to the total number of wheels of all the vehicles in the vehicles array; that is,
|
||||
sceneQueryResults must have dimensions large enough for one raycast hit result per wheel for all the vehicles in the vehicles array.
|
||||
|
||||
\param[in] sceneQueryResults must persist without being overwritten until the end of the next PxVehicleUpdates call.
|
||||
|
||||
\param[in] vehiclesToRaycast is an array of bools of length nbVehicles that is used to decide if raycasts will be performed for the corresponding vehicle
|
||||
in the vehicles array. If vehiclesToRaycast[i] is true then suspension line raycasts will be performed for vehicles[i]. If vehiclesToRaycast[i] is
|
||||
false then suspension line raycasts will not be performed for vehicles[i].
|
||||
|
||||
\note If vehiclesToRaycast is NULL then raycasts are performed for all vehicles in the vehicles array.
|
||||
|
||||
\note If vehiclesToRaycast[i] is false then the vehicle stored in vehicles[i] will automatically use the raycast or sweep hit planes recorded by the most recent
|
||||
suspension sweeps or raycasts for that vehicle. For vehicles far from the camera or not visible on the screen it can be
|
||||
optimal to only perform suspension line raycasts every Nth update rather than every single update. The accuracy of the cached contact plane
|
||||
naturally diminishes as N increase, meaning that wheels might start to hover or intersect the ground for large values of N or even with values close to 1 in
|
||||
conjunction with large vehicle speeds and/or geometry that has low spatial coherence.
|
||||
|
||||
\note Calling setToRestState invalidates any cached hit planes. Prior to calling PxVehicleUpdates each vehicle needs to perform suspension line raycasts
|
||||
or sweeps at least once after instantiation and at least once after calling setToRestState.
|
||||
|
||||
\note Each raycast casts along the suspension travel direction from the position of the top of the wheel at maximum suspension compression
|
||||
to the position of the base of the wheel at maximum droop. Raycasts that start inside a PxShape are subsequently ignored by the
|
||||
corresponding vehicle.
|
||||
|
||||
\note Only blocking hits are supported (PxQueryHitType::eBLOCK).
|
||||
|
||||
@see PxVehicleDrive4W::setToRestState, PxVehicleDriveNW::setToRestState, PxVehicleDriveTank::setToRestState, PxVehicleNoDrive::setToRestState
|
||||
*/
|
||||
void PxVehicleSuspensionRaycasts
|
||||
(PxBatchQuery* batchQuery,
|
||||
const PxU32 nbVehicles, PxVehicleWheels** vehicles,
|
||||
const PxU32 nbSceneQueryResults, PxRaycastQueryResult* sceneQueryResults,
|
||||
const bool* vehiclesToRaycast = NULL);
|
||||
|
||||
|
||||
/**
|
||||
\brief Perform sweeps for all suspension lines for all vehicles.
|
||||
|
||||
\param[in] batchQuery is a PxBatchQuery instance used to specify shader data and functions for the sweep scene queries.
|
||||
|
||||
\param[in] nbVehicles is the number of vehicles in the vehicles array.
|
||||
|
||||
\param[in] vehicles is an array of all vehicles that are to have a sweep issued from each wheel.
|
||||
|
||||
\param[in] nbSceneQueryResults must be greater than or equal to the total number of wheels of all the vehicles in the vehicles array; that is,
|
||||
sceneQueryResults must have dimensions large enough for one sweep hit result per wheel for all the vehicles in the vehicles array.
|
||||
|
||||
\param[in] sceneQueryResults must persist without being overwritten until the end of the next PxVehicleUpdates call.
|
||||
|
||||
\param[in] nbHitsPerQuery is the maximum numbers of hits that will be returned for each query.
|
||||
|
||||
\param[in] vehiclesToSweep is an array of bools of length nbVehicles that is used to decide if sweeps will be performed for the corresponding vehicle
|
||||
in the vehicles array. If vehiclesToSweep[i] is true then suspension sweeps will be performed for vehicles[i]. If vehiclesToSweep[i] is
|
||||
false then suspension sweeps will not be performed for vehicles[i].
|
||||
|
||||
\param[in] sweepWidthScale scales the geometry of the wheel used in the sweep. Values < 1 result in a thinner swept wheel, while values > 1 result in a fatter swept wheel.
|
||||
|
||||
\param[in] sweepRadiusScale scales the geometry of the wheel used in the sweep. Values < 1 result in a larger swept wheel, while values > 1 result in a smaller swept wheel.
|
||||
|
||||
\param[in] sweepInflation Inflation parameter for sweeps. This is the inflation parameter from PxScene::sweep(). It inflates the shape and makes it rounder,
|
||||
which gives smoother and more reliable normals.
|
||||
|
||||
\note If vehiclesToSweep is NULL then sweeps are performed for all vehicles in the vehicles array.
|
||||
|
||||
\note If vehiclesToSweep[i] is false then the vehicle stored in vehicles[i] will automatically use the most recent sweep or raycast hit planes
|
||||
recorded by the most recent suspension sweeps or raycasts for that vehicle. For vehicles far from the camera or not visible on the screen it can be
|
||||
optimal to only perform suspension queries every Nth update rather than every single update. The accuracy of the cached contact plane
|
||||
naturally diminishes as N increase, meaning that wheels might start to hover or intersect the ground for large values of N or even with values close to 1 in
|
||||
conjunction with large vehicle speeds and/or geometry that has low spatial coherence.
|
||||
|
||||
\note Calling setToRestState invalidates any cached hit planes. Prior to calling PxVehicleUpdates each vehicle needs to perform suspension raycasts
|
||||
or sweeps at least once after instantiation and at least once after calling setToRestState.
|
||||
|
||||
\note Each sweep casts the wheel's shape along the suspension travel direction from the position of the top of the wheel at maximum suspension compression
|
||||
to the position of the base of the wheel at maximum droop. Sweeps that start inside a PxShape are subsequently ignored by the
|
||||
corresponding vehicle.
|
||||
|
||||
\note A scale can be applied to the shape so that a modified shape is swept through the scene. The parameters sweepWidthScale and sweepRadiusScale scale the
|
||||
swept wheel shape in the width and radial directions. It is sometimes a good idea to sweep a thinner wheel to allow contact with other dynamic actors to be resolved
|
||||
first before attempting to drive on them.
|
||||
|
||||
\note Blocking hits (PxQueryHitType::eBLOCK) and non-blocking hits (PxQueryHitType::TOUCH) are supported. If the pre-and post-filter functions of the PxBatchQuery
|
||||
instance are set up to return blocking hits it is recommended to set nbHitsPerQuery = 1. If the filter functions returns touch hits then it is recommended to
|
||||
set nbHitsPerQuery > 1. The exact value depends on the expected complexity of the geometry that lies under the wheel. For complex geometry, especially with dynamic
|
||||
objects, it is recommended to use non-blocking hits. The vehicle update function will analyze all returned hits and choose the most appropriate using the thresholds
|
||||
set in PxVehicleSetSweepHitRejectionAngles.
|
||||
|
||||
@see PxVehicleDrive4W::setToRestState, PxVehicleDriveNW::setToRestState, PxVehicleDriveTank::setToRestState, PxVehicleNoDrive::setToRestState
|
||||
|
||||
@see PxBatchQuery::sweep PxScene::sweep()
|
||||
|
||||
@see PxVehicleSetSweepHitRejectionAngles
|
||||
*/
|
||||
void PxVehicleSuspensionSweeps
|
||||
(PxBatchQuery* batchQuery,
|
||||
const PxU32 nbVehicles, PxVehicleWheels** vehicles,
|
||||
const PxU32 nbSceneQueryResults, PxSweepQueryResult* sceneQueryResults, const PxU16 nbHitsPerQuery,
|
||||
const bool* vehiclesToSweep = NULL,
|
||||
const PxF32 sweepWidthScale = 1.0f, const PxF32 sweepRadiusScale = 1.0f, const PxF32 sweepInflation = 0.0f);
|
||||
|
||||
/**
|
||||
\brief A function called from PxContactModifyCallback::onContactModify. The function determines if rigid body contact points
|
||||
recorded for the wheel's PxShape are likely to be duplicated and resolved by the wheel's suspension raycast. Contact points that will be
|
||||
resolved by the suspension are ignored. Contact points that are accepted (rather than ignored) are modified to account for the effect of the
|
||||
suspension geometry and the angular speed of the wheel.
|
||||
|
||||
\param[in] vehicle is a reference to the PxVehicleWheels instance that owns the wheel
|
||||
|
||||
\param[in] wheelId is the id of the wheel
|
||||
|
||||
\param[in] wheelTangentVelocityMultiplier determines the amount of wheel angular velocity that is used to modify the target relative velocity of the contact.
|
||||
The target relative velocity is modified by adding a vector equal to the tangent velocity of the rotating wheel at the contact point and scaled by
|
||||
wheelTangentVelocityMultiplier. The value of wheelTangentVelocityMultiplier is limited to the range (0,1). Higher values mimic higher values of friction
|
||||
and tire load, while lower values mimic lower values of friction and tire load.
|
||||
|
||||
\param[in] maxImpulse determines the maximum impulse strength that the contacts can apply when a wheel is in contact with a PxRigidDynamic. This value is ignored for
|
||||
contacts with PxRigidStatic instances.
|
||||
|
||||
\param[in,out] contactModifyPair describes the set of contacts involving the PxShape of the specified wheel and one other shape. The contacts in the contact set are
|
||||
ignored or modified as required.
|
||||
|
||||
\note[in] Contact points are accepted or rejected using the threshold angles specified in the function PxVehicleSetSweepHitRejectionAngles.
|
||||
|
||||
\note If a contact point is not rejected it is modified to account for the wheel rotation speed.
|
||||
|
||||
\note Set maxImpulse to PX_MAX_F32 to allow any impulse value to be applied.
|
||||
|
||||
\note Reduce maxImpulse if the wheels are frequently colliding with light objects with mass much less than the vehicle's mass.
|
||||
Reducing this value encourages numerical stability.
|
||||
|
||||
@see PxContactModifyCallback::onContactModify, PxVehicleSetSweepHitRejectionAngles
|
||||
*/
|
||||
PxU32 PxVehicleModifyWheelContacts
|
||||
(const PxVehicleWheels& vehicle, const PxU32 wheelId,
|
||||
const PxF32 wheelTangentVelocityMultiplier, const PxReal maxImpulse,
|
||||
PxContactModifyPair& contactModifyPair);
|
||||
|
||||
|
||||
/**
|
||||
\brief Update an array of vehicles by either applying an acceleration to the rigid body actor associated with
|
||||
each vehicle or by an immediate update of the velocity of the actor.
|
||||
|
||||
\note The update mode (acceleration or velocity change) can be selected with PxVehicleSetUpdateMode.
|
||||
|
||||
\param[in] timestep is the timestep of the update
|
||||
|
||||
\param[in] gravity is the value of gravitational acceleration
|
||||
|
||||
\param[in] vehicleDrivableSurfaceToTireFrictionPairs describes the mapping between each PxMaterial ptr and an integer representing a
|
||||
surface type. It also stores the friction value for each combination of surface and tire type.
|
||||
|
||||
\param[in] nbVehicles is the number of vehicles pointers in the vehicles array
|
||||
|
||||
\param[in,out] vehicles is an array of length nbVehicles containing all vehicles to be updated by the specified timestep
|
||||
|
||||
\param[out] vehicleWheelQueryResults is an array of length nbVehicles storing the wheel query results of each corresponding vehicle and wheel in the
|
||||
vehicles array. A NULL pointer is permitted.
|
||||
|
||||
\param[out] vehicleConcurrentUpdates is an array of length nbVehicles. It is only necessary to specify vehicleConcurrentUpdates if PxVehicleUpdates is
|
||||
called concurrently (also concurrently with PxVehicleUpdateSingleVehicleAndStoreTelemetryData). The element vehicleConcurrentUpdates[i] of the array
|
||||
stores data that is computed for vehicle[i] during PxVehicleUpdates but which cannot be safely written when concurrently called. The data computed and
|
||||
stored in vehicleConcurrentUpdates must be passed to PxVehiclePostUpdates, where it is applied to all relevant actors in sequence. A NULL pointer is permitted.
|
||||
|
||||
\note The vehicleWheelQueryResults buffer must persist until the end of PxVehicleUpdates.
|
||||
|
||||
\note The vehicleWheelQueryResults buffer is left unmodified for vehicles with sleeping rigid bodies whose control inputs indicate they should remain inert.
|
||||
|
||||
\note If PxVehicleUpdates is called concurrently then vehicleConcurrentUpdates must be specified. Do not specify vehicleConcurrentUpdates if PxVehicleUpdates
|
||||
is not called concurrently.
|
||||
|
||||
\note The vehicleConcurrentUpdates buffer must persist until the end of PxVehiclePostUpdate.
|
||||
|
||||
\note If any vehicle has one or more disabled wheels (PxVehicleWheelsSimData::disableWheel) then the disabled wheels must not be associated
|
||||
with a PxShape (PxVehicleWheelsSimData::setWheelShapeMapping); the differential of the vehicle must be configured so that no drive torque
|
||||
is delivered to a disabled wheel; and the wheel must have zero rotation speed (PxVehicleWheelsDynData::setWheelRotationSpeed)
|
||||
|
||||
\note Concurrent calls to PxVehicleUpdates and PxVehicleUpdateSingleVehicleAndStoreTelemetryData are permitted if the parameter
|
||||
vehicleConcurrentUpdates is used.
|
||||
|
||||
@see PxVehicleSetUpdateMode, PxVehicleWheelsSimData::disableWheel, PxVehicleWheelsSimData::setWheelShapeMapping, PxVehicleWheelsDynData::setWheelRotationSpeed,
|
||||
PxVehiclePostUpdates
|
||||
*/
|
||||
void PxVehicleUpdates(
|
||||
const PxReal timestep, const PxVec3& gravity,
|
||||
const PxVehicleDrivableSurfaceToTireFrictionPairs& vehicleDrivableSurfaceToTireFrictionPairs,
|
||||
const PxU32 nbVehicles, PxVehicleWheels** vehicles, PxVehicleWheelQueryResult* vehicleWheelQueryResults, PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates = NULL);
|
||||
|
||||
|
||||
/**
|
||||
\brief Apply actor changes that were computed in concurrent calls to PxVehicleUpdates or PxVehicleUpdateSingleVehicleAndStoreTelemetryData but
|
||||
which could not be safely applied due to the concurrency.
|
||||
|
||||
\param[in] vehicleConcurrentUpdates is an array of length nbVehicles where vehicleConcurrentUpdates[i] contains data describing actor changes that
|
||||
were computed for vehicles[i] during concurrent calls to PxVehicleUpdates or PxVehicleUpdateSingleVehicleAndStoreTelemetryData.
|
||||
|
||||
\param[in] nbVehicles is the number of vehicles pointers in the vehicles array
|
||||
|
||||
\param[in,out] vehicles is an array of length nbVehicles containing all vehicles that were partially updated in concurrent calls to PxVehicleUpdates or
|
||||
PxVehicleUpdateSingleVehicleAndStoreTelemetryData.
|
||||
|
||||
@see PxVehicleUpdates, PxVehicleUpdateSingleVehicleAndStoreTelemetryData
|
||||
*/
|
||||
void PxVehiclePostUpdates(
|
||||
const PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates, const PxU32 nbVehicles, PxVehicleWheels** vehicles);
|
||||
|
||||
|
||||
/**
|
||||
\brief Shift the origin of vehicles by the specified vector.
|
||||
|
||||
Call this method to adjust the internal data structures of vehicles to reflect the shifted origin location
|
||||
(the shift vector will get subtracted from all world space spatial data).
|
||||
|
||||
\note It is the user's responsibility to keep track of the summed total origin shift and adjust all input/output to/from PhysXVehicle accordingly.
|
||||
|
||||
\note This call will not automatically shift the PhysX scene and its objects. You need to call PxScene::shiftOrigin() seperately to keep the systems in sync.
|
||||
|
||||
\param[in] shift is the translation vector to shift the origin by.
|
||||
|
||||
\param[in] nbVehicles is the number of vehicles in the vehicles array.
|
||||
|
||||
\param[in,out] vehicles is an array of all vehicles that should be updated to map to the new scene origin.
|
||||
*/
|
||||
void PxVehicleShiftOrigin(const PxVec3& shift, const PxU32 nbVehicles, PxVehicleWheels** vehicles);
|
||||
|
||||
#if PX_DEBUG_VEHICLE_ON
|
||||
/**
|
||||
\brief Update an single vehicle by either applying an acceleration to the rigid body actor associated with
|
||||
each vehicle or by an immediate update of the velocity of the actor. Also record telemetry data from the
|
||||
vehicle so that it may be visualized or queried.
|
||||
|
||||
\note The update mode (acceleration or velocity change) can be selected with PxVehicleSetUpdateMode.
|
||||
|
||||
\param[in] timestep is the timestep of the update
|
||||
|
||||
\param[in] gravity is the value of gravitational acceleration
|
||||
|
||||
\param[in] vehicleDrivableSurfaceToTireFrictionPairs describes the mapping between each PxMaterial ptr and an integer representing a
|
||||
surface type. It also stores the friction value for each combination of surface and tire type.
|
||||
|
||||
\param[in,out] focusVehicle is the vehicle to be updated and have its telemetry data recorded
|
||||
|
||||
\param[out] vehicleWheelQueryResults is an array of length 1 storing the wheel query results of each wheel of the vehicle/
|
||||
A NULL pointer is permitted.
|
||||
|
||||
\param[out] telemetryData is the data structure used to record telemetry data during the update for later query or visualization
|
||||
|
||||
\param[out] vehicleConcurrentUpdates is an array of length 1. It is only necessary to specify vehicleConcurrentUpdates if
|
||||
PxVehicleUpdateSingleVehicleAndStoreTelemetryData is called concurrently (also concurrently with PxVehicleUpdates). The
|
||||
PxVehicleConcurrentUpdateData struct stores data that cannot be safely written when concurrently called. The data computed and
|
||||
stored in vehicleConcurrentUpdates must be passed to PxVehiclePostUpdates, where it is applied to the vehicle actor. A NULL
|
||||
pointer is permitted.
|
||||
|
||||
\note The vehicleWheelQueryResults buffer must persist until the end of PxVehicleUpdateSingleVehicleAndStoreTelemetryData
|
||||
|
||||
\note The vehicleWheelQueryResults buffer is left unmodified for vehicles with sleeping rigid bodies whose control inputs indicate they should remain inert.
|
||||
|
||||
\note Concurrent calls to PxVehicleUpdateSingleVehicleAndStoreTelemetryData and PxVehicleUpdates are permitted if the parameter
|
||||
vehicleConcurrentUpdates is used.
|
||||
|
||||
@see PxVehiclePostUpdates, PxVehicleSetUpdateMode, PxVehicleTelemetryData
|
||||
*/
|
||||
void PxVehicleUpdateSingleVehicleAndStoreTelemetryData
|
||||
(const PxReal timestep, const PxVec3& gravity,
|
||||
const PxVehicleDrivableSurfaceToTireFrictionPairs& vehicleDrivableSurfaceToTireFrictionPairs,
|
||||
PxVehicleWheels* focusVehicle, PxVehicleWheelQueryResult* vehicleWheelQueryResults,
|
||||
PxVehicleTelemetryData& telemetryData,
|
||||
PxVehicleConcurrentUpdateData* vehicleConcurrentUpdates = NULL);
|
||||
#endif
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_UPDATE_H
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// 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-2021 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_UTILHELPER_H
|
||||
#define PX_VEHICLE_UTILHELPER_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "foundation/Px.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
struct PxVehicleWheelQueryResult;
|
||||
|
||||
/**
|
||||
\brief Test if all wheels of a vehicle are in the air by querying the wheel query data
|
||||
stored in the last call to PxVehicleUpdates. If all wheels are in the air then true is returned.
|
||||
|
||||
\note False is returned if any wheel can reach to the ground.
|
||||
|
||||
\note If vehWheelQueryResults.wheelQueryResults is NULL or vehWheelQueryResults.nbWheelQueryResults is 0 then true is returned.
|
||||
This function does not account for wheels that have been disabled since the last execution of PxVehicleUpdates so it is possible
|
||||
that wheels disabled more recently than the last call to PxVehicleUpdates report are treated as touching the ground.
|
||||
|
||||
\return True if the vehicle is in the air, false if any wheel is touching the ground.
|
||||
*/
|
||||
bool PxVehicleIsInAir(const PxVehicleWheelQueryResult& vehWheelQueryResults);
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_UTILHELPER_H
|
||||
@@ -0,0 +1,651 @@
|
||||
//
|
||||
// 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-2021 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<previous
|
||||
*/
|
||||
PxReal mFallRates[PxVehicleDriveDynData::eMAX_NB_ANALOG_INPUTS];
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehiclePadSmoothingData)& 0x0f));
|
||||
|
||||
/**
|
||||
\brief Used to produce smooth vehicle driving control values from analog and digital inputs.
|
||||
@see PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs, PxVehicleDrive4WSmoothAnalogRawInputsAndSetAnalogInputs
|
||||
*/
|
||||
class PxVehicleDrive4WRawInputData
|
||||
{
|
||||
public:
|
||||
|
||||
PxVehicleDrive4WRawInputData()
|
||||
{
|
||||
for(PxU32 i=0;i<PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS;i++)
|
||||
{
|
||||
mRawDigitalInputs[i]=false;
|
||||
mRawAnalogInputs[i]=0.0f;
|
||||
}
|
||||
|
||||
mGearUp = false;
|
||||
mGearDown = false;
|
||||
}
|
||||
|
||||
virtual ~PxVehicleDrive4WRawInputData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Record if the accel button has been pressed on keyboard.
|
||||
\param[in] accelKeyPressed is true if the accelerator key has been pressed and false otherwise.
|
||||
*/
|
||||
void setDigitalAccel(const bool accelKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accelKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Record if the brake button has been pressed on keyboard.
|
||||
\param[in] brakeKeyPressed is true if the brake key has been pressed and false otherwise.
|
||||
*/
|
||||
void setDigitalBrake(const bool brakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brakeKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Record if the handbrake button has been pressed on keyboard.
|
||||
\param[in] handbrakeKeyPressed is true if the handbrake key has been pressed and false otherwise.
|
||||
*/
|
||||
void setDigitalHandbrake(const bool handbrakeKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrakeKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Record if the left steer button has been pressed on keyboard.
|
||||
\param[in] steerLeftKeyPressed is true if the steer-left key has been pressed and false otherwise.
|
||||
*/
|
||||
void setDigitalSteerLeft(const bool steerLeftKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT]=steerLeftKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Record if the right steer button has been pressed on keyboard.
|
||||
\param[in] steerRightKeyPressed is true if the steer-right key has been pressed and false otherwise.
|
||||
*/
|
||||
void setDigitalSteerRight(const bool steerRightKeyPressed) {mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steerRightKeyPressed;}
|
||||
|
||||
|
||||
/**
|
||||
\brief Return if the accel button has been pressed on keyboard.
|
||||
\return True if the accel button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
|
||||
|
||||
/**
|
||||
\brief Return if the brake button has been pressed on keyboard.
|
||||
\return True if the brake button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalBrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
|
||||
|
||||
/**
|
||||
\brief Return if the handbrake button has been pressed on keyboard.
|
||||
\return True if the handbrake button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalHandbrake() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
|
||||
|
||||
/**
|
||||
\brief Return if the left steer button has been pressed on keyboard.
|
||||
\return True if the steer-left button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalSteerLeft() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_LEFT];}
|
||||
|
||||
/**
|
||||
\brief Return if the right steer button has been pressed on keyboard.
|
||||
\return True if the steer-right button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalSteerRight() const {return mRawDigitalInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set the analog accel value from the gamepad
|
||||
\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.
|
||||
*/
|
||||
void setAnalogAccel(const PxReal accel)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(accel, 0.0f, 1.0f, "Analog accel must be in range (0,1)");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL]=accel;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog brake value from the gamepad
|
||||
\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.
|
||||
*/
|
||||
void setAnalogBrake(const PxReal brake)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(brake, 0.0f, 1.0f, "Analog brake must be in range (0,1)");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE]=brake;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog handbrake value from the gamepad
|
||||
\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.
|
||||
*/
|
||||
void setAnalogHandbrake(const PxReal handbrake)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(handbrake, 0.0f, 1.0f, "Analog handbrake must be in range (0,1)");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE]=handbrake;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog steer value from the gamepad
|
||||
\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.
|
||||
*/
|
||||
void setAnalogSteer(const PxReal steer)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(steer, -1.0f, 1.0f, "Analog steer must be in range (-1,1)");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT]=steer;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog accel value from the gamepad
|
||||
\return The analog accel value.
|
||||
*/
|
||||
PxReal getAnalogAccel() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_ACCEL];}
|
||||
|
||||
/**
|
||||
\brief Return the analog brake value from the gamepad
|
||||
\return The analog brake value.
|
||||
*/
|
||||
PxReal getAnalogBrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_BRAKE];}
|
||||
|
||||
/**
|
||||
\brief Return the analog handbrake value from the gamepad
|
||||
\return The analog handbrake value.
|
||||
*/
|
||||
PxReal getAnalogHandbrake() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_HANDBRAKE];}
|
||||
|
||||
/**
|
||||
\brief Return the analog steer value from the gamepad
|
||||
*/
|
||||
PxReal getAnalogSteer() const {return mRawAnalogInputs[PxVehicleDrive4WControl::eANALOG_INPUT_STEER_RIGHT];}
|
||||
|
||||
/**
|
||||
\brief Record if the gearup button has been pressed on keyboard or gamepad
|
||||
\param[in] gearUpKeyPressed is true if the gear-up button has been pressed, false otherwise.
|
||||
*/
|
||||
void setGearUp(const bool gearUpKeyPressed) {mGearUp=gearUpKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Record if the geardown button has been pressed on keyboard or gamepad
|
||||
\param[in] gearDownKeyPressed is true if the gear-down button has been pressed, false otherwise.
|
||||
*/
|
||||
void setGearDown(const bool gearDownKeyPressed) {mGearDown=gearDownKeyPressed;}
|
||||
|
||||
/**
|
||||
\brief Return if the gearup button has been pressed on keyboard or gamepad
|
||||
\return The value of the gear-up button.
|
||||
*/
|
||||
bool getGearUp() const {return mGearUp;}
|
||||
|
||||
/**
|
||||
\brief Record if the geardown button has been pressed on keyboard or gamepad
|
||||
\return The value of the gear-down button.
|
||||
*/
|
||||
bool getGearDown() const {return mGearDown;}
|
||||
|
||||
private:
|
||||
|
||||
bool mRawDigitalInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
|
||||
PxReal mRawAnalogInputs[PxVehicleDrive4WControl::eMAX_NB_DRIVE4W_ANALOG_INPUTS];
|
||||
|
||||
bool mGearUp;
|
||||
bool mGearDown;
|
||||
};
|
||||
|
||||
/**
|
||||
\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 PxVehicleDrive4WSmoothDigitalRawInputsAndSetAnalogInputs
|
||||
(const PxVehicleKeySmoothingData& keySmoothing, const PxFixedSizeLookupTable<8>& 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<PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS;i++)
|
||||
{
|
||||
mRawAnalogInputs[i]=0.0f;
|
||||
mRawDigitalInputs[i]=false;
|
||||
}
|
||||
|
||||
mGearUp=false;
|
||||
mGearDown=false;
|
||||
}
|
||||
|
||||
~PxVehicleDriveTankRawInputData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the drive model (eDRIVE_MODEL_SPECIAL or eDRIVE_MODEL_STANDARD)
|
||||
\return The chosen tank drive model.
|
||||
*/
|
||||
PxVehicleDriveTankControlModel::Enum getDriveModel() const
|
||||
{
|
||||
return mMode;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set if the accel button has been pressed on the keyboard
|
||||
\param[in] b is true if the digital accel button has been pressed, false otherwise.
|
||||
*/
|
||||
void setDigitalAccel(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=b;}
|
||||
|
||||
/**
|
||||
\brief Set if the left thrust button has been pressed on the keyboard
|
||||
\param[in] b is true if the digital left thrust button has been pressed, false otherwise.
|
||||
*/
|
||||
void setDigitalLeftThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=b;}
|
||||
|
||||
/**
|
||||
\brief Set if the right thrust button has been pressed on the keyboard
|
||||
\param[in] b is true if the digital right thrust button has been pressed, false otherwise.
|
||||
*/
|
||||
void setDigitalRightThrust(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=b;}
|
||||
|
||||
/**
|
||||
\brief Set if the left brake button has been pressed on the keyboard
|
||||
\param[in] b is true if the digital left brake button has been pressed, false otherwise.
|
||||
*/
|
||||
void setDigitalLeftBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=b;}
|
||||
|
||||
/**
|
||||
\brief Set if the right brake button has been pressed on the keyboard
|
||||
\param[in] b is true if the digital right brake button has been pressed, false otherwise.
|
||||
*/
|
||||
void setDigitalRightBrake(const bool b) {mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=b;}
|
||||
|
||||
/**
|
||||
\brief Return if the accel button has been pressed on the keyboard
|
||||
\return True if the accel button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalAccel() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];}
|
||||
|
||||
/**
|
||||
\brief Return if the left thrust button has been pressed on the keyboard
|
||||
\return True if the left thrust button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalLeftThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];}
|
||||
|
||||
/**
|
||||
\brief Return if the right thrust button has been pressed on the keyboard
|
||||
\return True if the right thrust button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalRightThrust() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];}
|
||||
|
||||
/**
|
||||
\brief Return if the left brake button has been pressed on the keyboard
|
||||
\return True if the left brake button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalLeftBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];}
|
||||
|
||||
/**
|
||||
\brief Return if the right brake button has been pressed on the keyboard
|
||||
\return True if the right brake button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getDigitalRightBrake() const {return mRawDigitalInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];}
|
||||
|
||||
|
||||
/**
|
||||
\brief Set the analog accel value from the gamepad
|
||||
\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.
|
||||
In range (0,1).
|
||||
*/
|
||||
void setAnalogAccel(const PxF32 accel)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(accel, 0.0f, 1.0f, "Tank analog accel must be in range (-1,1)");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL]=accel;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog left thrust value from the gamepad
|
||||
\param[in] leftThrust represents the state of the left stick.
|
||||
\note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
|
||||
*/
|
||||
void setAnalogLeftThrust(const PxF32 leftThrust)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
|
||||
{
|
||||
testValidAnalogValue(leftThrust, -1.0f, 1.0f, "Tank left thrust must be in range (-1,1) in eSPECIAL mode.");
|
||||
}
|
||||
else
|
||||
{
|
||||
testValidAnalogValue(leftThrust, 0.0f, 1.0f, "Tank left thrust must be in range (0,1) in eSTANDARD mode.");
|
||||
}
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT]=leftThrust;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog right thrust value from the gamepad
|
||||
\param[in] rightThrust represents the state of the right stick.
|
||||
\note In range (0,1) for standard mode (eSTANDARD), in range (-1,1) for special mode (eSPECIAL)
|
||||
*/
|
||||
void setAnalogRightThrust(const PxF32 rightThrust)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
if(mMode == PxVehicleDriveTankControlModel::eSPECIAL)
|
||||
{
|
||||
testValidAnalogValue(rightThrust, -1.0f, 1.0f, "Tank right thrust must be in range (-1,1) in eSPECIAL mode.");
|
||||
}
|
||||
else
|
||||
{
|
||||
testValidAnalogValue(rightThrust, 0.0f, 1.0f, "Tank right thrust must be in range (0,1) in eSTANDARD mode.");
|
||||
}
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT]=rightThrust;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog left brake value from the gamepad
|
||||
\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.
|
||||
\note In range (0,1).
|
||||
*/
|
||||
void setAnalogLeftBrake(const PxF32 leftBrake)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(leftBrake, 0.0f, 1.0f, "Tank left brake must be in range (0,1).");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT]=leftBrake;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the analog right brake value from the gamepad
|
||||
\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.
|
||||
\note In range (0,1).
|
||||
*/
|
||||
void setAnalogRightBrake(const PxF32 rightBrake)
|
||||
{
|
||||
#if PX_CHECKED
|
||||
testValidAnalogValue(rightBrake, 0.0f, 1.0f, "Tank right brake must be in range (0,1).");
|
||||
#endif
|
||||
mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT]=rightBrake;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog accel value from the gamepad
|
||||
\return The analog accel value.
|
||||
*/
|
||||
PxF32 getAnalogAccel() const
|
||||
{
|
||||
return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_ACCEL];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog left thrust value from the gamepad
|
||||
\return The analog left thrust value.
|
||||
*/
|
||||
PxF32 getAnalogLeftThrust() const
|
||||
{
|
||||
return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_LEFT];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog right thrust value from the gamepad
|
||||
\return The analog right thrust value.
|
||||
*/
|
||||
PxF32 getAnalogRightThrust() const
|
||||
{
|
||||
return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_THRUST_RIGHT];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog left brake value from the gamepad
|
||||
\return The analog left brake value.
|
||||
*/
|
||||
PxF32 getAnalogLeftBrake() const
|
||||
{
|
||||
return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_LEFT];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return the analog right brake value from the gamepad
|
||||
\return The analog right brake value.
|
||||
*/
|
||||
PxF32 getAnalogRightBrake() const
|
||||
{
|
||||
return mRawAnalogInputs[PxVehicleDriveTankControl::eANALOG_INPUT_BRAKE_RIGHT];
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Record if the gear-up button has been pressed on keyboard or gamepad
|
||||
\param[in] gearUp is true if the gear-up button has been pressed, false otherwise.
|
||||
*/
|
||||
void setGearUp(const bool gearUp) {mGearUp=gearUp;}
|
||||
|
||||
/**
|
||||
\brief Record if the gear-down button has been pressed on keyboard or gamepad
|
||||
\param[in] gearDown is true if the gear-down button has been pressed, false otherwise.
|
||||
*/
|
||||
void setGearDown(const bool gearDown) {mGearDown=gearDown;}
|
||||
|
||||
/**
|
||||
\brief Return if the gear-up button has been pressed on keyboard or gamepad
|
||||
\return True if the gear-up button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getGearUp() const {return mGearUp;}
|
||||
|
||||
/**
|
||||
\brief Return if the gear-down button has been pressed on keyboard or gamepad
|
||||
\return True if the gear-down button has been pressed, false otherwise.
|
||||
*/
|
||||
bool getGearDown() const {return mGearDown;}
|
||||
|
||||
private:
|
||||
|
||||
PxVehicleDriveTankControlModel::Enum mMode;
|
||||
|
||||
PxReal mRawAnalogInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
|
||||
bool mRawDigitalInputs[PxVehicleDriveTankControl::eMAX_NB_DRIVETANK_ANALOG_INPUTS];
|
||||
|
||||
bool mGearUp;
|
||||
bool mGearDown;
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Used to smooth and set analog tank control values 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] 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] focusVehicle is the vehicle that will be given analog and gearup/geardown control values arising from the digital inputs.
|
||||
*/
|
||||
void PxVehicleDriveTankSmoothDigitalRawInputsAndSetAnalogInputs
|
||||
(const PxVehicleKeySmoothingData& keySmoothing,
|
||||
const PxVehicleDriveTankRawInputData& rawInputData,
|
||||
const PxReal timestep,
|
||||
PxVehicleDriveTank& focusVehicle);
|
||||
|
||||
|
||||
/**
|
||||
\brief Used to smooth and set analog tank 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] 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] focusVehicle is the vehicle that will be given analog control values arising from the gamepad inputs.
|
||||
*/
|
||||
void PxVehicleDriveTankSmoothAnalogRawInputsAndSetAnalogInputs
|
||||
(const PxVehiclePadSmoothingData& padSmoothing,
|
||||
const PxVehicleDriveTankRawInputData& rawInputData,
|
||||
const PxReal timestep,
|
||||
PxVehicleDriveTank& focusVehicle);
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_CONTROL_H
|
||||
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// 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-2021 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_UTILSSETUP_H
|
||||
#define PX_VEHICLE_UTILSSETUP_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
#include "vehicle/PxVehicleSDK.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
class PxVehicleWheelsSimData;
|
||||
class PxVehicleWheelsDynData;
|
||||
class PxVehicleDriveSimData4W;
|
||||
class PxVehicleWheels;
|
||||
|
||||
|
||||
/**
|
||||
\brief Reconfigure a PxVehicle4W instance as a three-wheeled car with tadpole config (2 front wheels, 1 rear wheel)
|
||||
|
||||
\note The rear-left wheel is removed and the rear-right wheel is positioned at the centre of the rear axle.
|
||||
The suspension of the rear-right wheel is modified to support the entire mass of the front car while preserving its natural frequency and damping ratio.
|
||||
|
||||
\param[in,out] wheelsSimData is the data describing the wheels/suspensions/tires of the vehicle.
|
||||
\param[in,out] wheelsDynData is the data describing the dynamic state of the wheels of the vehicle.
|
||||
\param[in,out] driveSimData is the data describing the drive model of the vehicle.
|
||||
*/
|
||||
void PxVehicle4WEnable3WTadpoleMode(PxVehicleWheelsSimData& wheelsSimData, PxVehicleWheelsDynData& wheelsDynData, PxVehicleDriveSimData4W& driveSimData);
|
||||
|
||||
/**
|
||||
\brief Reconfigure a PxVehicle4W instance as a three-wheeled car with delta config (1 front wheel, 2 rear wheels)
|
||||
|
||||
\note The front-left wheel is removed and the front-right wheel is positioned at the centre of the front axle.
|
||||
The suspension of the front-right wheel is modified to support the entire mass of the front car while preserving its natural frequency and damping ratio.
|
||||
|
||||
\param[in,out] wheelsSimData is the data describing the wheels/suspensions/tires of the vehicle.
|
||||
\param[in,out] wheelsDynData is the data describing the dynamic state of the wheels of the vehicle.
|
||||
\param[in,out] driveSimData is the data describing the drive model of the vehicle.
|
||||
*/
|
||||
void PxVehicle4WEnable3WDeltaMode(PxVehicleWheelsSimData& wheelsSimData, PxVehicleWheelsDynData& wheelsDynData, PxVehicleDriveSimData4W& driveSimData);
|
||||
|
||||
/**
|
||||
\brief Compute the sprung masses of the suspension springs given (i) the number of sprung masses,
|
||||
(ii) coordinates of the sprung masses, (iii) the center of mass offset of the rigid body, (iv) the
|
||||
total mass of the rigid body, and (v) the direction of gravity (0 for x-axis, 1 for y-axis, 2 for z-axis).
|
||||
|
||||
\param[in] nbSprungMasses is the number of sprung masses of the vehicle. This value corresponds to the number of wheels on the vehicle.
|
||||
\param[in] sprungMassCoordinates are the coordinates of the sprung masses relative to the actor. The array sprungMassCoordinates must be of
|
||||
length nbSprungMasses or greater.
|
||||
\param[in] centreOfMass is the coordinate of the center of mass of the rigid body relative to the actor. This value corresponds to
|
||||
the value set by PxRigidBody::setCMassLocalPose.
|
||||
\param[in] totalMass is the total mass of all the sprung masses. This value corresponds to the value set by PxRigidBody::setMass.
|
||||
\param[in] gravityDirection is an integer describing the direction of gravitational acceleration. A value of 0 corresponds to (-1,0,0),
|
||||
a value of 1 corresponds to (0,-1,0) and a value of 2 corresponds to (0,0,-1).
|
||||
\param[out] sprungMasses are the masses to set in the associated suspension data with PxVehicleSuspensionData::mSprungMass. The sprungMasses array must be of length
|
||||
nbSprungMasses or greater. Each element in the sprungMasses array corresponds to the suspension located at the same array element in sprungMassCoordinates.
|
||||
The center of mass of the masses in sprungMasses with the coordinates in sprungMassCoordinates satisfy the specified centerOfMass.
|
||||
*/
|
||||
void PxVehicleComputeSprungMasses(const PxU32 nbSprungMasses, const PxVec3* sprungMassCoordinates, const PxVec3& centreOfMass, const PxReal totalMass, const PxU32 gravityDirection, PxReal* sprungMasses);
|
||||
|
||||
|
||||
/**
|
||||
\brief Reconfigure the vehicle to reflect a new center of mass local pose that has been applied to the actor. The function requires
|
||||
(i) the center of mass local pose that was last used to configure the vehicle and the vehicle's actor, (ii) the new center of mass local pose that
|
||||
has been applied to the vehicle's actor and will now be applied to the vehicle, and (iii) the direction of gravity (0 for x-axis, 1 for y-axis, 2 for z-axis)
|
||||
|
||||
\param[in] oldCMassLocalPose is the center of mass local pose that was last used to configure the vehicle.
|
||||
\param[in] newCMassLocalPose is the center of mass local pose that will be used to configure the vehicle so that it matches the vehicle's actor.
|
||||
\param[in] gravityDirection is an integer describing the direction of gravitational acceleration. A value of 0 corresponds to (0,0,-1),
|
||||
a value of 1 corresponds to (0,-1,0) and a value of 2 corresponds to (0,0,-1).
|
||||
\param[in,out] vehicle is the vehicle to be updated with a new center of mass local pose.
|
||||
|
||||
\note This function does not update the center of mass of the vehicle actor. That needs to updated separately with PxRigidBody::setCMassLocalPose
|
||||
|
||||
\note The suspension sprung masses are updated so that the natural frequency and damping ratio of the springs are preserved. This involves altering the
|
||||
stiffness and damping rate of the suspension springs.
|
||||
*/
|
||||
void PxVehicleUpdateCMassLocalPose(const PxTransform& oldCMassLocalPose, const PxTransform& newCMassLocalPose, const PxU32 gravityDirection, PxVehicleWheels* vehicle);
|
||||
|
||||
/**
|
||||
\brief Used by PxVehicleCopyDynamicsData
|
||||
@see PxVehicleCopyDynamicsData
|
||||
*/
|
||||
class PxVehicleCopyDynamicsMap
|
||||
{
|
||||
public:
|
||||
|
||||
PxVehicleCopyDynamicsMap()
|
||||
{
|
||||
for(PxU32 i = 0; i < PX_MAX_NB_WHEELS; i++)
|
||||
{
|
||||
sourceWheelIds[i] = PX_MAX_U8;
|
||||
targetWheelIds[i] = PX_MAX_U8;
|
||||
}
|
||||
}
|
||||
|
||||
PxU8 sourceWheelIds[PX_MAX_NB_WHEELS];
|
||||
PxU8 targetWheelIds[PX_MAX_NB_WHEELS];
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Copy dynamics data from src to trg, including wheel rotation speed, wheel rotation angle, engine rotation speed etc.
|
||||
|
||||
\param[in] wheelMap - describes the mapping between the wheels in src and the wheels in trg.
|
||||
|
||||
\param[in] src - according to the wheel mapping stored in wheelMap, the dynamics data in src wheels are copied to the corresponding wheels in trg.
|
||||
|
||||
\param[out] trg - according to wheel mapping stored in wheelMap, the wheels in trg are given the dynamics data of the corresponding wheels in src.
|
||||
|
||||
\note wheelMap must specify a unique mapping between the wheels in src and the wheels in trg.
|
||||
|
||||
\note In the event that src has fewer wheels than trg, wheelMap must specify a unique mapping between each src wheel to a trg wheel.
|
||||
|
||||
\note In the event that src has more wheels than trg, wheelMap must specify a unique mapping to each trg wheel from a src wheel.
|
||||
|
||||
\note In the event that src has fewer wheels than trg, the trg wheels that are not mapped to a src wheel are given the average wheel rotation
|
||||
speed of all enabled src wheels.
|
||||
|
||||
\note src and trg must be the same vehicle type.
|
||||
*/
|
||||
void PxVehicleCopyDynamicsData(const PxVehicleCopyDynamicsMap& wheelMap, const PxVehicleWheels& src, PxVehicleWheels* trg);
|
||||
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_UTILSSETUP_H
|
||||
@@ -0,0 +1,418 @@
|
||||
//
|
||||
// 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-2021 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_UTILSTELEMETRY_H
|
||||
#define PX_VEHICLE_UTILSTELEMETRY_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "vehicle/PxVehicleSDK.h"
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
#include "foundation/PxVec3.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
#if PX_DEBUG_VEHICLE_ON
|
||||
|
||||
class PxVehicleGraphDesc
|
||||
{
|
||||
|
||||
friend class PxVehicleGraph;
|
||||
|
||||
PxVehicleGraphDesc();
|
||||
|
||||
/**
|
||||
\brief x-coord of graph centre.
|
||||
<b>Range:</b> (0,1)<br>
|
||||
*/
|
||||
PxReal mPosX;
|
||||
|
||||
/**
|
||||
\brief y-coord of graph centre.
|
||||
<b>Range:</b> (0,1)<br>
|
||||
*/
|
||||
PxReal mPosY;
|
||||
|
||||
/**
|
||||
\brief x-extents of graph (from mPosX-0.5f*mSizeX to mPosX+0.5f*mSizeX).
|
||||
<b>Range:</b> (0,1)<br>
|
||||
*/
|
||||
PxReal mSizeX;
|
||||
|
||||
/**
|
||||
\brief y-extents of graph (from mPosY-0.5f*mSizeY to mPosY+0.5f*mSizeY).
|
||||
<b>Range:</b> (0,1)<br>
|
||||
*/
|
||||
PxReal mSizeY;
|
||||
|
||||
/**
|
||||
\brief Background color of graph.
|
||||
*/
|
||||
PxVec3 mBackgroundColor;
|
||||
|
||||
/**
|
||||
\brief Alpha value of background color.
|
||||
*/
|
||||
PxReal mAlpha;
|
||||
|
||||
private:
|
||||
|
||||
bool isValid() const;
|
||||
};
|
||||
|
||||
struct PxVehicleGraphChannelDesc
|
||||
{
|
||||
public:
|
||||
|
||||
friend class PxVehicleGraph;
|
||||
|
||||
PxVehicleGraphChannelDesc();
|
||||
|
||||
/**
|
||||
\brief Data values less than mMinY will be clamped at mMinY.
|
||||
*/
|
||||
PxReal mMinY;
|
||||
|
||||
/**
|
||||
\brief Data values greater than mMaxY will be clamped at mMaxY.
|
||||
*/
|
||||
PxReal mMaxY;
|
||||
|
||||
/**
|
||||
\brief Data values greater than mMidY will be drawn with color mColorHigh.
|
||||
Data values less than mMidY will be drawn with color mColorLow.
|
||||
*/
|
||||
PxReal mMidY;
|
||||
|
||||
/**
|
||||
\brief Color used to render data values lower than mMidY.
|
||||
*/
|
||||
PxVec3 mColorLow;
|
||||
|
||||
/**
|
||||
\brief Color used to render data values greater than mMidY.
|
||||
*/
|
||||
PxVec3 mColorHigh;
|
||||
|
||||
/**
|
||||
\brief String to describe data channel.
|
||||
*/
|
||||
char* mTitle;
|
||||
|
||||
private:
|
||||
|
||||
bool isValid() const;
|
||||
};
|
||||
|
||||
struct PxVehicleWheelGraphChannel
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eJOUNCE=0,
|
||||
eSUSPFORCE,
|
||||
eTIRELOAD,
|
||||
eNORMALIZED_TIRELOAD,
|
||||
eWHEEL_OMEGA,
|
||||
eTIRE_FRICTION,
|
||||
eTIRE_LONG_SLIP,
|
||||
eNORM_TIRE_LONG_FORCE,
|
||||
eTIRE_LAT_SLIP,
|
||||
eNORM_TIRE_LAT_FORCE,
|
||||
eNORM_TIRE_ALIGNING_MOMENT,
|
||||
eMAX_NB_WHEEL_CHANNELS
|
||||
};
|
||||
};
|
||||
|
||||
struct PxVehicleDriveGraphChannel
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eENGINE_REVS=0,
|
||||
eENGINE_DRIVE_TORQUE,
|
||||
eCLUTCH_SLIP,
|
||||
eACCEL_CONTROL, //TANK_ACCEL
|
||||
eBRAKE_CONTROL, //TANK_BRAKE_LEFT
|
||||
eHANDBRAKE_CONTROL, //TANK_BRAKE_RIGHT
|
||||
eSTEER_LEFT_CONTROL, //TANK_THRUST_LEFT
|
||||
eSTEER_RIGHT_CONTROL, //TANK_THRUST_RIGHT
|
||||
eGEAR_RATIO,
|
||||
eMAX_NB_DRIVE_CHANNELS
|
||||
};
|
||||
};
|
||||
|
||||
struct PxVehicleGraphType
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
eWHEEL=0,
|
||||
eDRIVE
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
class PxVehicleGraph
|
||||
{
|
||||
public:
|
||||
|
||||
friend class PxVehicleTelemetryData;
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
enum
|
||||
{
|
||||
eMAX_NB_SAMPLES=256
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
eMAX_NB_TITLE_CHARS=256
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
eMAX_NB_CHANNELS=12
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Setup a graph from a descriptor.
|
||||
*/
|
||||
void setup(const PxVehicleGraphDesc& desc, const PxVehicleGraphType::Enum graphType);
|
||||
|
||||
/**
|
||||
\brief Clear all data recorded in a graph.
|
||||
*/
|
||||
void clearRecordedChannelData();
|
||||
|
||||
/**
|
||||
\brief Get the color of the graph background. Used for rendering a graph.
|
||||
*/
|
||||
const PxVec3& getBackgroundColor() const {return mBackgroundColor;}
|
||||
|
||||
/**
|
||||
\brief Get the alpha transparency of the color of the graph background. Used for rendering a graph.
|
||||
*/
|
||||
PxReal getBackgroundAlpha() const {return mBackgroundAlpha;}
|
||||
|
||||
/**
|
||||
\brief Get the coordinates of the graph background. Used for rendering a graph
|
||||
|
||||
\param[out] xMin is the x-coord of the lower-left corner
|
||||
\param[out] yMin is the y-coord of the lower-left corner
|
||||
\param[out] xMax is the x-coord of the upper-right corner
|
||||
\param[out] yMax is the y-coord of the upper-right corner
|
||||
*/
|
||||
void getBackgroundCoords(PxReal& xMin, PxReal& yMin, PxReal& xMax, PxReal& yMax) const {xMin = mBackgroundMinX;xMax = mBackgroundMaxX;yMin = mBackgroundMinY;yMax = mBackgroundMaxY;}
|
||||
|
||||
/**
|
||||
\brief Compute the coordinates of the graph data of a specific graph channel.
|
||||
|
||||
\param[out] xy is an array of graph sample coordinates stored in order x0,y0,x1,y1,x2,y2...xn,yn.
|
||||
\param[out] colors stores the color of each point on the graph.
|
||||
\param[out] title is the title of the graph.
|
||||
*/
|
||||
void computeGraphChannel(const PxU32 channel, PxReal* xy, PxVec3* colors, char* title) const;
|
||||
|
||||
/**
|
||||
\brief Return the latest value stored in the specified graph channel
|
||||
*/
|
||||
PxF32 getLatestValue(const PxU32 channel) const ;
|
||||
|
||||
/**
|
||||
\brief Get the raw data of a specific graph channel.
|
||||
|
||||
\param[in] channel is the ID of the graph channel to get data from.
|
||||
\param[out] values is the buffer to write the data to. Minimum required size is eMAX_NB_SAMPLES.
|
||||
*/
|
||||
void getRawData(const PxU32 channel, PxReal* values) const;
|
||||
|
||||
private:
|
||||
|
||||
//Min and max of each sample.
|
||||
PxReal mChannelMinY[eMAX_NB_CHANNELS];
|
||||
PxReal mChannelMaxY[eMAX_NB_CHANNELS];
|
||||
//Discriminate between high and low values with different colors.
|
||||
PxReal mChannelMidY[eMAX_NB_CHANNELS];
|
||||
//Different colors for values than midY and less than midY.
|
||||
PxVec3 mChannelColorLow[eMAX_NB_CHANNELS];
|
||||
PxVec3 mChannelColorHigh[eMAX_NB_CHANNELS];
|
||||
//Title of graph
|
||||
char mChannelTitle[eMAX_NB_CHANNELS][eMAX_NB_TITLE_CHARS];
|
||||
//Graph data.
|
||||
PxReal mChannelSamples[eMAX_NB_CHANNELS][eMAX_NB_SAMPLES];
|
||||
|
||||
//Background color,alpha,coords
|
||||
PxVec3 mBackgroundColor;
|
||||
PxReal mBackgroundAlpha;
|
||||
PxReal mBackgroundMinX;
|
||||
PxReal mBackgroundMaxX;
|
||||
PxReal mBackgroundMinY;
|
||||
PxReal mBackgroundMaxY;
|
||||
|
||||
PxU32 mSampleTide;
|
||||
|
||||
PxU32 mNbChannels;
|
||||
|
||||
PxU32 mPad[2];
|
||||
|
||||
|
||||
void setup
|
||||
(const PxF32 graphSizeX, const PxF32 graphSizeY,
|
||||
const PxF32 engineGraphPosX, const PxF32 engineGraphPosY,
|
||||
const PxF32* const wheelGraphPosX, const PxF32* const wheelGraphPosY,
|
||||
const PxVec3& backgroundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow);
|
||||
|
||||
void updateTimeSlice(const PxReal* const samples);
|
||||
|
||||
void setChannel(PxVehicleGraphChannelDesc& desc, const PxU32 channel);
|
||||
|
||||
void setupEngineGraph
|
||||
(const PxF32 sizeX, const PxF32 sizeY, const PxF32 posX, const PxF32 posY,
|
||||
const PxVec3& backgoundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow);
|
||||
|
||||
void setupWheelGraph
|
||||
(const PxF32 sizeX, const PxF32 sizeY, const PxF32 posX, const PxF32 posY,
|
||||
const PxVec3& backgoundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow);
|
||||
|
||||
PxVehicleGraph();
|
||||
~PxVehicleGraph();
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(PxU32(PxVehicleGraph::eMAX_NB_CHANNELS) >= PxU32(PxVehicleWheelGraphChannel::eMAX_NB_WHEEL_CHANNELS) && PxU32(PxVehicleGraph::eMAX_NB_CHANNELS) >= PxU32(PxVehicleDriveGraphChannel::eMAX_NB_DRIVE_CHANNELS));
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleGraph) & 15));
|
||||
|
||||
class PxVehicleTelemetryData
|
||||
{
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleNWTelemetryData instance for a vehicle with nbWheels
|
||||
@see PxVehicleNWTelemetryDataFree
|
||||
*/
|
||||
static PxVehicleTelemetryData* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Free a PxVehicleNWTelemetryData instance for a vehicle.
|
||||
@see PxVehicleNWTelemetryDataAllocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Set up all the graphs so that they are ready to record data.
|
||||
*/
|
||||
void setup
|
||||
(const PxReal graphSizeX, const PxReal graphSizeY,
|
||||
const PxReal engineGraphPosX, const PxReal engineGraphPosY,
|
||||
const PxReal* const wheelGraphPosX, const PxReal* const wheelGraphPosY,
|
||||
const PxVec3& backGroundColor, const PxVec3& lineColorHigh, const PxVec3& lineColorLow);
|
||||
|
||||
/**
|
||||
\brief Clear the graphs of recorded data.
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/**
|
||||
\brief Get the graph data for the engine
|
||||
*/
|
||||
const PxVehicleGraph& getEngineGraph() const {return *mEngineGraph;}
|
||||
|
||||
/**
|
||||
\brief Get the number of wheel graphs
|
||||
*/
|
||||
PxU32 getNbWheelGraphs() const {return mNbActiveWheels;}
|
||||
|
||||
/**
|
||||
\brief Get the graph data for the kth wheel
|
||||
*/
|
||||
const PxVehicleGraph& getWheelGraph(const PxU32 k) const {return mWheelGraphs[k];}
|
||||
|
||||
/**
|
||||
\brief Get the array of tire force application points so they can be rendered
|
||||
*/
|
||||
const PxVec3* getTireforceAppPoints() const {return mTireforceAppPoints;}
|
||||
|
||||
/**
|
||||
\brief Get the array of susp force application points so they can be rendered
|
||||
*/
|
||||
const PxVec3* getSuspforceAppPoints() const {return mSuspforceAppPoints;}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Graph data for engine.
|
||||
Used for storing single timeslices of debug data for engine graph.
|
||||
@see PxVehicleGraph
|
||||
*/
|
||||
PxVehicleGraph* mEngineGraph;
|
||||
|
||||
/**
|
||||
\brief Graph data for each wheel.
|
||||
Used for storing single timeslices of debug data for wheel graphs.
|
||||
@see PxVehicleGraph
|
||||
*/
|
||||
PxVehicleGraph* mWheelGraphs;
|
||||
|
||||
/**
|
||||
\brief Application point of tire forces.
|
||||
*/
|
||||
PxVec3* mTireforceAppPoints;
|
||||
|
||||
/**
|
||||
\brief Application point of susp forces.
|
||||
*/
|
||||
PxVec3* mSuspforceAppPoints;
|
||||
|
||||
/**
|
||||
\brief Total number of active wheels
|
||||
*/
|
||||
PxU32 mNbActiveWheels;
|
||||
|
||||
PxU32 mPad[3];
|
||||
|
||||
private:
|
||||
|
||||
PxVehicleTelemetryData(){}
|
||||
~PxVehicleTelemetryData(){}
|
||||
};
|
||||
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleTelemetryData) & 15));
|
||||
|
||||
#endif //PX_DEBUG_VEHICLE_ON
|
||||
|
||||
//#endif // PX_DEBUG_VEHICLE_ON
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_UTILSTELEMETRY_H
|
||||
@@ -0,0 +1,931 @@
|
||||
//
|
||||
// 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-2021 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_WHEELS_H
|
||||
#define PX_VEHICLE_WHEELS_H
|
||||
/** \addtogroup vehicle
|
||||
@{
|
||||
*/
|
||||
|
||||
#include "foundation/PxSimpleTypes.h"
|
||||
#include "vehicle/PxVehicleShaders.h"
|
||||
#include "vehicle/PxVehicleComponents.h"
|
||||
#include "common/PxBase.h"
|
||||
#include "PxRigidDynamic.h"
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
namespace physx
|
||||
{
|
||||
#endif
|
||||
|
||||
class PxVehicleWheels4SimData;
|
||||
class PxVehicleWheels4DynData;
|
||||
class PxVehicleTireForceCalculator;
|
||||
class PxShape;
|
||||
class PxPhysics;
|
||||
class PxMaterial;
|
||||
|
||||
/**
|
||||
\brief Flags to configure the vehicle wheel simulation.
|
||||
|
||||
@see PxVehicleWheelsSimData::setFlags(), PxVehicleWheelsSimData::getFlags()
|
||||
*/
|
||||
struct PxVehicleWheelsSimFlag
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
/**
|
||||
\brief Limit the suspension expansion velocity.
|
||||
|
||||
For extreme damping ratios, large damping forces might result in the vehicle sticking to the ground where
|
||||
one would rather expect to see the vehicle lift off. While it is highly recommended to use somewhat realistic
|
||||
damping ratios, this flag can be used to limit the velocity of the suspension. In more detail, the simulation
|
||||
will check whether the suspension can extend to the target length in the given simulation time step. If that
|
||||
is the case, the suspension force will be computed as usual, else the force will be set to zero. Enabling
|
||||
this feature gives a slightly more realisitic behavior at the potential cost of more easily losing control
|
||||
when steering the vehicle.
|
||||
*/
|
||||
eLIMIT_SUSPENSION_EXPANSION_VELOCITY = (1 << 0),
|
||||
|
||||
/**
|
||||
\brief Disable internal cylinder-plane intersection test.
|
||||
|
||||
By default the internal code runs a post-process on sweep results, approximating the wheel shape with a
|
||||
cylinder and tweaking the sweep hit results accordingly. This can produce artefacts in certain cases, in
|
||||
particular when the swept shape is very different from a cylinder - e.g. with swept spheres. This flag
|
||||
tells the system to disable this internal test, and reuse the direct user-provided sweep results.
|
||||
|
||||
The default code refines the sweep results in each substep. Enabling this flag makes the system partially
|
||||
reuse the same sweep results over each substep, which could potentially create other artefacts.
|
||||
*/
|
||||
eDISABLE_INTERNAL_CYLINDER_PLANE_INTERSECTION_TEST = (1 << 1),
|
||||
|
||||
/**
|
||||
\brief Disable suspension force projection.
|
||||
|
||||
By default the internal code modulates the suspension force with the contact normal, i.e. the more the contact
|
||||
normal is aligned with the suspension direction, the bigger the force. This can create issues when using a
|
||||
single blocking hit, whose unique contact normal sometimes does not accurately capture the reality of the
|
||||
surrounding geometry. For example it can weaken the suspension force too much, which visually makes the wheel
|
||||
move up and down against e.g. a kerb. Enabling this flag tells the system to disable the modulation of the
|
||||
suspension force by the contact normal.
|
||||
|
||||
The rationale is that a real tire has a deformed contact patch containing multiple normals, and even if some
|
||||
of these normals are bent when colliding against a kerb, there would still be a large area of the contact patch
|
||||
touching the ground, and getting normals aligned with the suspension. This is difficult to capture with simple
|
||||
sweep results, especially with a single sweep hit whose normal is computed by a less than accurate algorithm
|
||||
like GJK. Using this flag shortcuts these issues, which can improves the behavior when driving over kerbs or
|
||||
small obstacles.
|
||||
*/
|
||||
eDISABLE_SUSPENSION_FORCE_PROJECTION = (1 << 2)
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Collection of set bits defined in #PxVehicleWheelsSimFlag.
|
||||
|
||||
@see PxVehicleWheelsSimFlag
|
||||
*/
|
||||
typedef PxFlags<PxVehicleWheelsSimFlag::Enum, PxU32> PxVehicleWheelsSimFlags;
|
||||
PX_FLAGS_OPERATORS(PxVehicleWheelsSimFlag::Enum, PxU32)
|
||||
|
||||
/**
|
||||
\brief Data structure describing configuration data of a vehicle with up to 20 wheels.
|
||||
*/
|
||||
|
||||
class PxVehicleWheelsSimData
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleWheels;
|
||||
friend class PxVehicleNoDrive;
|
||||
friend class PxVehicleDrive4W;
|
||||
friend class PxVehicleDriveTank;
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
/**
|
||||
\brief Allocate a PxVehicleWheelsSimData instance for with nbWheels.
|
||||
@see free
|
||||
*/
|
||||
static PxVehicleWheelsSimData* allocate(const PxU32 nbWheels);
|
||||
|
||||
/**
|
||||
\brief Setup with mass information that can be applied to the default values of the suspensions, wheels, and tires
|
||||
set in their respective constructors.
|
||||
|
||||
\param chassisMass is the mass of the chassis.
|
||||
|
||||
\note This function assumes that the suspensions equally share the load of the chassis mass. It also
|
||||
assumes that the suspension will have a particular natural frequency and damping ratio that is typical
|
||||
of a standard car. If either of these assumptions is broken then each suspension will need to
|
||||
be individually configured with custom strength, damping rate, and sprung mass.
|
||||
|
||||
@see allocate
|
||||
*/
|
||||
void setChassisMass(const PxF32 chassisMass);
|
||||
|
||||
/**
|
||||
\brief Free a PxVehicleWheelsSimData instance
|
||||
@see allocate
|
||||
*/
|
||||
void free();
|
||||
|
||||
/**
|
||||
\brief Copy wheel simulation data.
|
||||
\note The number of wheels on both instances of PxVehicleWheelsSimData must match.
|
||||
*/
|
||||
PxVehicleWheelsSimData& operator=(const PxVehicleWheelsSimData& src);
|
||||
|
||||
/**
|
||||
\brief Copy the data of a single wheel unit (wheel, suspension, tire) from srcWheel of src to trgWheel.
|
||||
\param[in] src is the data to be copied.
|
||||
\param[in] srcWheel is the wheel whose data will be copied from src.
|
||||
\param[in] trgWheel is the wheel that will be assigned the copied data.
|
||||
*/
|
||||
void copy(const PxVehicleWheelsSimData& src, const PxU32 srcWheel, const PxU32 trgWheel);
|
||||
|
||||
/**
|
||||
\brief Return the number of wheels
|
||||
@see allocate
|
||||
*/
|
||||
PxU32 getNbWheels() const {return mNbActiveWheels;}
|
||||
|
||||
/**
|
||||
\brief Return the suspension data of the idth wheel
|
||||
*/
|
||||
const PxVehicleSuspensionData& getSuspensionData(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the wheel data of the idth wheel
|
||||
*/
|
||||
const PxVehicleWheelData& getWheelData(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the tire data of the idth wheel
|
||||
*/
|
||||
const PxVehicleTireData& getTireData(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the direction of travel of the suspension of the idth wheel
|
||||
*/
|
||||
const PxVec3& getSuspTravelDirection(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the application point of the suspension force of the suspension of the idth wheel as an offset from the rigid body center of mass.
|
||||
\note Specified relative to the center of mass of the rigid body
|
||||
*/
|
||||
const PxVec3& getSuspForceAppPointOffset(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the application point of the tire force of the tire of the idth wheel as an offset from the rigid body center of mass.
|
||||
\note Specified relative to the centre of mass of the rigid body
|
||||
*/
|
||||
const PxVec3& getTireForceAppPointOffset(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the offset from the rigid body centre of mass to the centre of the idth wheel.
|
||||
*/
|
||||
const PxVec3& getWheelCentreOffset(const PxU32 id) const;
|
||||
|
||||
/**
|
||||
\brief Return the wheel mapping for the ith wheel.
|
||||
|
||||
\note The return value is the element in the array of
|
||||
shapes of the vehicle's PxRigidDynamic that corresponds to the ith wheel. A return value of -1 means
|
||||
that the wheel is not mapped to a PxShape.
|
||||
|
||||
@see PxRigidActor.getShapes
|
||||
*/
|
||||
PxI32 getWheelShapeMapping(const PxU32 wheelId) const;
|
||||
|
||||
/**
|
||||
\brief Return the scene query filter data used by the specified suspension line
|
||||
*/
|
||||
const PxFilterData& getSceneQueryFilterData(const PxU32 suspId) const;
|
||||
|
||||
/**
|
||||
\brief Return the number of unique anti-roll bars that have been added with addAntiRollBarData
|
||||
@see PxVehicleWheelsSimData::addAntiRollBarData
|
||||
*/
|
||||
PxU32 getNbAntiRollBars() const
|
||||
{
|
||||
return mNbActiveAntiRollBars;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Return a specific anti-roll bar.
|
||||
\param antiRollId is the unique id of the anti-roll bar
|
||||
\note The return value of addAntiRollBarData is a unique id for that specific anti-roll bar
|
||||
and can be used as input parameter for getAntiRollBarData in order to query the same anti-roll bar.
|
||||
Alternatively, it is possible to iterate over all anti-roll bars by choosing antiRollId
|
||||
in range (0, getNbAntiRollBars()).
|
||||
*/
|
||||
const PxVehicleAntiRollBarData& getAntiRollBarData(const PxU32 antiRollId) const;
|
||||
|
||||
/**
|
||||
\brief Return the data that describes the filtering of the tire load to produce smoother handling at large time-steps.
|
||||
*/
|
||||
PX_FORCE_INLINE const PxVehicleTireLoadFilterData& getTireLoadFilterData() const
|
||||
{
|
||||
return mNormalisedLoadFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Set the suspension data of the idth wheel
|
||||
\param[in] id is the wheel index.
|
||||
\param[in] susp is the suspension data to be applied.
|
||||
*/
|
||||
void setSuspensionData(const PxU32 id, const PxVehicleSuspensionData& susp);
|
||||
|
||||
/**
|
||||
\brief Set the wheel data of the idth wheel
|
||||
\param[in] id is the wheel index.
|
||||
\param[in] wheel is the wheel data to be applied.
|
||||
*/
|
||||
void setWheelData(const PxU32 id, const PxVehicleWheelData& wheel);
|
||||
|
||||
/**
|
||||
\brief Set the tire data of the idth wheel
|
||||
\param[in] id is the wheel index.
|
||||
\param[in] tire is the tire data to be applied.
|
||||
*/
|
||||
void setTireData(const PxU32 id, const PxVehicleTireData& tire);
|
||||
|
||||
/**
|
||||
\brief Set the direction of travel of the suspension of the idth wheel
|
||||
\param[in] id is the wheel index
|
||||
\param[in] dir is the suspension travel direction to be applied.
|
||||
*/
|
||||
void setSuspTravelDirection(const PxU32 id, const PxVec3& dir);
|
||||
|
||||
/**
|
||||
\brief Set the application point of the suspension force of the suspension of the idth wheel.
|
||||
\param[in] id is the wheel index
|
||||
\param[in] offset is the offset from the rigid body center of mass to the application point of the suspension force.
|
||||
\note Specified relative to the centre of mass of the rigid body
|
||||
*/
|
||||
void setSuspForceAppPointOffset(const PxU32 id, const PxVec3& offset);
|
||||
|
||||
/**
|
||||
\brief Set the application point of the tire force of the tire of the idth wheel.
|
||||
\param[in] id is the wheel index
|
||||
\param[in] offset is the offset from the rigid body center of mass to the application point of the tire force.
|
||||
\note Specified relative to the centre of mass of the rigid body
|
||||
*/
|
||||
void setTireForceAppPointOffset(const PxU32 id, const PxVec3& offset);
|
||||
|
||||
/**
|
||||
\brief Set the offset from the rigid body centre of mass to the centre of the idth wheel.
|
||||
\param[in] id is the wheel index
|
||||
\param[in] offset is the offset from the rigid body center of mass to the center of the wheel at rest.
|
||||
\note Specified relative to the centre of mass of the rigid body
|
||||
*/
|
||||
void setWheelCentreOffset(const PxU32 id, const PxVec3& offset);
|
||||
|
||||
/**
|
||||
\brief Set mapping between wheel id and position of corresponding wheel shape in the list of actor shapes.
|
||||
|
||||
\note This mapping is used to pose the correct wheel shapes with the latest wheel rotation angle, steer angle, and suspension travel
|
||||
while allowing arbitrary ordering of the wheel shapes in the actor's list of shapes.
|
||||
|
||||
\note Use setWheelShapeMapping(i,-1) to register that there is no wheel shape corresponding to the ith wheel
|
||||
|
||||
\note Set setWheelShapeMapping(i,k) to register that the ith wheel corresponds to the kth shape in the actor's list of shapes.
|
||||
|
||||
\note The default values correspond to setWheelShapeMapping(i,i) for all wheels.
|
||||
|
||||
\note Calling this function will also pose the relevant PxShape at the rest position of the wheel.
|
||||
|
||||
\param wheelId is the wheel index
|
||||
|
||||
\param shapeId is the shape index.
|
||||
|
||||
@see PxVehicleUpdates, PxVehicleDrive4W::setup, PxVehicleDriveTank::setup, PxVehicleNoDrive::setup, setSceneQueryFilterData, PxRigidActor::getShapes
|
||||
*/
|
||||
void setWheelShapeMapping(const PxU32 wheelId, const PxI32 shapeId);
|
||||
|
||||
/**
|
||||
\brief Set the scene query filter data that will be used for raycasts along the travel
|
||||
direction of the specified suspension. The default value is PxFilterData(0,0,0,0)
|
||||
\param suspId is the wheel index
|
||||
\param sqFilterData is the raycast filter data for the suspension raycast.
|
||||
@see setWheelShapeMapping
|
||||
*/
|
||||
void setSceneQueryFilterData(const PxU32 suspId, const PxFilterData& sqFilterData);
|
||||
|
||||
/**
|
||||
\brief Set the data that describes the filtering of the tire load to produce smoother handling at large timesteps.
|
||||
\param tireLoadFilter is the smoothing function data.
|
||||
*/
|
||||
void setTireLoadFilterData(const PxVehicleTireLoadFilterData& tireLoadFilter);
|
||||
|
||||
/**
|
||||
\brief Set the anti-roll suspension for a pair of wheels.
|
||||
|
||||
\param antiRoll is the anti-roll suspension.
|
||||
|
||||
\note If an anti-roll bar has already been set for the same logical wheel pair
|
||||
(independent of wheel index order specified by PxVehicleAntiRollBar.mWheel0 and PxVehicleAntiRollBar.mWheel0)
|
||||
then the existing anti-roll bar is updated with a new stiffness parameter antiRoll.mStiffness.
|
||||
|
||||
\note If the wheel pair specified by antiRoll does not yet have an anti-roll bar then antiRoll is added to
|
||||
a list of anti-roll bars for the vehicle.
|
||||
|
||||
\return If antiRoll represents a new wheel pair then a unique id is assigned to the anti-roll bar and returned.
|
||||
If antiRoll represents an existing wheel pair then the unique id of the existing anti-roll bar is returned.
|
||||
The return value is always in range (0, getNbAntiRollBars()).
|
||||
|
||||
\note The return value can be used to query the anti-roll bar with getAntiRollBarData(id).
|
||||
|
||||
\note The number of possible anti-roll bars is limited to half the wheel count.
|
||||
|
||||
\note An existing anti-roll bar can be disabled by calling antiRoll.mStiffness to zero.
|
||||
|
||||
@see PxVehicleWheelsSimData::getAntiRollBarData, PxVehicleAntiRollBarData
|
||||
*/
|
||||
PxU32 addAntiRollBarData(const PxVehicleAntiRollBarData& antiRoll);
|
||||
|
||||
/**
|
||||
\brief Disable a wheel so that zero suspension forces and zero tire forces are applied to the rigid body from this wheel.
|
||||
|
||||
\note If the vehicle has a differential (PxVehicleNW/PxVehicle4W) then the differential (PxVehicleDifferentialNWData/PxVehicleDifferential4WData)
|
||||
needs to be configured so that no drive torque is delivered to the disabled wheel.
|
||||
|
||||
\note If the vehicle is of type PxVehicleNoDrive then zero drive torque must be applied to the disabled wheel.
|
||||
|
||||
\note For tanks (PxVehicleDriveTank) any drive torque that could be delivered to the wheel through the tank differential will be
|
||||
re-directed to the remaining enabled wheels.
|
||||
|
||||
@see enableWheel
|
||||
@see PxVehicleDifferentialNWData::setDrivenWheel
|
||||
@see PxVehicleDifferential4WData::mFrontLeftRightSplit, PxVehicleDifferential4WData::mRearLeftRightSplit, PxVehicleDifferential4WData::mType
|
||||
@see PxVehicleNoDrive::setDriveTorque
|
||||
@see PxVehicle4WEnable3WTadpoleMode, PxVehicle4WEnable3WDeltaMode
|
||||
|
||||
\note If a PxShape is associated with the disabled wheel then the association must be broken by calling setWheelShapeMapping(wheelId, -1).
|
||||
@see setWheelShapeMapping
|
||||
|
||||
\note A wheel that is disabled must also simultaneously be given zero wheel rotation speed.
|
||||
@see PxVehicleWheelsDynData::setWheelRotationSpeed
|
||||
|
||||
\note Care must be taken with the sprung mass supported by the remaining enabled wheels. Depending on the desired effect, the mass of the rigid body
|
||||
might need to be distributed among the remaining enabled wheels and suspensions.
|
||||
|
||||
\param[in] wheel is the wheel index.
|
||||
*/
|
||||
void disableWheel(const PxU32 wheel);
|
||||
|
||||
/**
|
||||
\brief Enable a wheel so that suspension forces and tire forces are applied to the rigid body.
|
||||
All wheels are enabled by default and remain enabled until they are disabled.
|
||||
\param[in] wheel is the wheel index.
|
||||
@see disableWheel
|
||||
*/
|
||||
void enableWheel(const PxU32 wheel);
|
||||
|
||||
/**
|
||||
\brief Test if a wheel has been disabled.
|
||||
\param[in] wheel is the wheel index.
|
||||
*/
|
||||
bool getIsWheelDisabled(const PxU32 wheel) const;
|
||||
|
||||
/**
|
||||
\brief Set the number of vehicle sub-steps that will be performed when the vehicle's longitudinal
|
||||
speed is below and above a threshold longitudinal speed.
|
||||
|
||||
\note More sub-steps provides better stability but with greater computational cost.
|
||||
|
||||
\note Typically, vehicles require more sub-steps at very low forward speeds.
|
||||
|
||||
\note The threshold longitudinal speed has a default value that is the equivalent of 5 metres per second after accounting for
|
||||
the length scale set in PxTolerancesScale.
|
||||
|
||||
\note The sub-step count below the threshold longitudinal speed has a default of 3.
|
||||
|
||||
\note The sub-step count above the threshold longitudinal speed has a default of 1.
|
||||
|
||||
\note Each sub-step has time advancement equal to the time-step passed to PxVehicleUpdates divided by the number of required sub-steps.
|
||||
|
||||
\note The contact planes of the most recent suspension line raycast are reused across all sub-steps.
|
||||
|
||||
\note Each sub-step computes tire and suspension forces and then advances a velocity, angular velocity and transform.
|
||||
|
||||
\note At the end of all sub-steps the vehicle actor is given the velocity and angular velocity that would move the actor from its start transform prior
|
||||
to the first sub-step to the transform computed at the end of the last substep, assuming it doesn't collide with anything along the way in the next PhysX SDK update.
|
||||
|
||||
\note The global pose of the actor is left unchanged throughout the sub-steps.
|
||||
|
||||
\param[in] thresholdLongitudinalSpeed is a threshold speed that is used to categorize vehicle speed as low speed or high speed.
|
||||
\param[in] lowForwardSpeedSubStepCount is the number of sub-steps performed in PxVehicleUpates for vehicles that have longitudinal speed lower than thresholdLongitudinalSpeed.
|
||||
\param[in] highForwardSpeedSubStepCount is the number of sub-steps performed in PxVehicleUpdates for vehicles that have longitudinal speed graeter than thresholdLongitudinalSpeed.
|
||||
*/
|
||||
void setSubStepCount(const PxReal thresholdLongitudinalSpeed, const PxU32 lowForwardSpeedSubStepCount, const PxU32 highForwardSpeedSubStepCount);
|
||||
|
||||
/**
|
||||
\brief Set the minimum denominator used in the longitudinal slip calculation.
|
||||
|
||||
\note The longitudinal slip has a theoretical value of (w*r - vz)/|vz|, where w is the angular speed of the wheel; r is the radius of the wheel;
|
||||
and vz is the component of rigid body velocity (computed at the wheel base) that lies along the longitudinal wheel direction. The term |vz|
|
||||
normalizes the slip, while preserving the sign of the longitudinal tire slip. The difficulty here is that when |vz| approaches zero the
|
||||
longitudinal slip approaches infinity. A solution to this problem is to replace the denominator (|vz|) with a value that never falls below a chosen threshold.
|
||||
The longitudinal slip is then calculated with (w*r - vz)/PxMax(|vz|, minLongSlipDenominator).
|
||||
|
||||
\note The default value is the equivalent of 4 metres per second after accounting for the length scale set in PxTolerancesScale.
|
||||
|
||||
\note Adjust this value upwards if a vehicle has difficulty coming to rest.
|
||||
|
||||
\note Decreasing the timestep (or increasing the number of sub-steps at low longitudinal speed with setSubStepCount) should allow stable stable
|
||||
behavior with smaller values of minLongSlipDenominator.
|
||||
*/
|
||||
void setMinLongSlipDenominator(const PxReal minLongSlipDenominator);
|
||||
|
||||
/**
|
||||
\brief Set the vehicle wheel simulation flags.
|
||||
|
||||
\param[in] flags The flags to set (see #PxVehicleWheelsSimFlags).
|
||||
|
||||
<b>Default:</b> no flag set
|
||||
|
||||
@see PxVehicleWheelsSimFlag
|
||||
*/
|
||||
void setFlags(PxVehicleWheelsSimFlags flags);
|
||||
|
||||
/**
|
||||
\brief Return the vehicle wheel simulation flags.
|
||||
|
||||
\return The values of the flags.
|
||||
|
||||
@see PxVehicleWheelsSimFlag
|
||||
*/
|
||||
PxVehicleWheelsSimFlags getFlags() const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Graph to filter normalised load
|
||||
@see setTireLoadFilterData, getTireLoadFilterData
|
||||
*/
|
||||
PxVehicleTireLoadFilterData mNormalisedLoadFilter;
|
||||
|
||||
/**
|
||||
\brief Wheels data organised in blocks of 4 wheels.
|
||||
*/
|
||||
PxVehicleWheels4SimData* mWheels4SimData;
|
||||
|
||||
/**
|
||||
\brief Number of blocks of 4 wheels.
|
||||
*/
|
||||
PxU32 mNbWheels4;
|
||||
|
||||
/**
|
||||
\brief Number of actual wheels (<=(mNbWheels4*4))
|
||||
*/
|
||||
PxU32 mNbActiveWheels;
|
||||
|
||||
/**
|
||||
\brief Anti-roll bars
|
||||
*/
|
||||
PxVehicleAntiRollBarData* mAntiRollBars;
|
||||
|
||||
/**
|
||||
\brief 2 anti-rollbars allocated for each block of 4 wheels.
|
||||
*/
|
||||
PxU32 mNbAntiRollBars4;
|
||||
|
||||
/**
|
||||
\brief Number of active anti-roll bars.
|
||||
*/
|
||||
PxU32 mNbActiveAntiRollBars;
|
||||
|
||||
/**
|
||||
\brief Which of the mNbActiveWheels are active or disabled?
|
||||
The default is that all mNbActiveWheels wheels are active.
|
||||
*/
|
||||
PxU32 mActiveWheelsBitmapBuffer[((PX_MAX_NB_WHEELS + 31) & ~31) >> 5];
|
||||
|
||||
/**
|
||||
\brief Threshold longitudinal speed used to decide whether to use
|
||||
mLowForwardSpeedSubStepCount or mHighForwardSpeedSubStepCount as the
|
||||
number of sub-steps that will be peformed.
|
||||
*/
|
||||
PxF32 mThresholdLongitudinalSpeed;
|
||||
|
||||
/**
|
||||
\brief Number of sub-steps that will be performed if the longitudinal speed
|
||||
of the vehicle is smaller than mThresholdLongitudinalSpeed.
|
||||
*/
|
||||
PxU32 mLowForwardSpeedSubStepCount;
|
||||
|
||||
/**
|
||||
\brief Number of sub-steps that will be performed if the longitudinal speed
|
||||
of the vehicle is greater than or equal to mThresholdLongitudinalSpeed.
|
||||
*/
|
||||
PxU32 mHighForwardSpeedSubStepCount;
|
||||
|
||||
/**
|
||||
\brief Minimum long slip denominator
|
||||
*/
|
||||
PxF32 mMinLongSlipDenominator;
|
||||
|
||||
/**
|
||||
\brief The vehicle wheel simulation flags.
|
||||
|
||||
@see PxVehicleWheelsSimFlags
|
||||
*/
|
||||
PxU32 mFlags;
|
||||
|
||||
#if PX_P64_FAMILY
|
||||
PxU32 mPad[1];
|
||||
#endif
|
||||
|
||||
/**
|
||||
\brief Test if wheel simulation data has been setup with legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
\brief see PxVehicleWheels::allocate
|
||||
*/
|
||||
static PxU32 computeByteSize(const PxU32 numWheels);
|
||||
static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsSimData* simData, PxU8* ptrIn);
|
||||
PxVehicleWheelsSimData(const PxU32 numWheels);
|
||||
|
||||
//serialization
|
||||
public:
|
||||
PxVehicleWheelsSimData(const PxEMPTY) : mNormalisedLoadFilter(PxEmpty) {}
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
PxU32 getNbWheels4() const { return mNbWheels4; }
|
||||
PxU32 getNbSuspensionData() const { return mNbActiveWheels; }
|
||||
PxU32 getNbWheelData() const { return mNbActiveWheels; }
|
||||
PxU32 getNbSuspTravelDirection() const { return mNbActiveWheels; }
|
||||
PxU32 getNbTireData() const { return mNbActiveWheels; }
|
||||
PxU32 getNbSuspForceAppPointOffset() const { return mNbActiveWheels; }
|
||||
PxU32 getNbTireForceAppPointOffset() const { return mNbActiveWheels; }
|
||||
PxU32 getNbWheelCentreOffset() const { return mNbActiveWheels; }
|
||||
PxU32 getNbWheelShapeMapping() const { return mNbActiveWheels; }
|
||||
PxU32 getNbSceneQueryFilterData() const { return mNbActiveWheels; }
|
||||
PxF32 getMinLongSlipDenominator() const {return mMinLongSlipDenominator;}
|
||||
void setThresholdLongSpeed(const PxF32 f) {mThresholdLongitudinalSpeed = f;}
|
||||
PxF32 getThresholdLongSpeed() const {return mThresholdLongitudinalSpeed;}
|
||||
void setLowForwardSpeedSubStepCount(const PxU32 f) {mLowForwardSpeedSubStepCount = f;}
|
||||
PxU32 getLowForwardSpeedSubStepCount() const {return mLowForwardSpeedSubStepCount;}
|
||||
void setHighForwardSpeedSubStepCount(const PxU32 f) {mHighForwardSpeedSubStepCount = f;}
|
||||
PxU32 getHighForwardSpeedSubStepCount() const {return mHighForwardSpeedSubStepCount;}
|
||||
void setWheelEnabledState(const PxU32 wheel, const bool state) {if(state) {enableWheel(wheel);} else {disableWheel(wheel);}}
|
||||
bool getWheelEnabledState(const PxU32 wheel) const {return !getIsWheelDisabled(wheel);}
|
||||
PxU32 getNbWheelEnabledState() const {return mNbActiveWheels;}
|
||||
PxU32 getNbAntiRollBars4() const { return mNbAntiRollBars4; }
|
||||
PxU32 getNbAntiRollBarData() const {return mNbActiveAntiRollBars;}
|
||||
void setAntiRollBarData(const PxU32 id, const PxVehicleAntiRollBarData& antiRoll);
|
||||
PxVehicleWheelsSimData(){}
|
||||
~PxVehicleWheelsSimData(){}
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsSimData) & 15));
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data for wheels
|
||||
*/
|
||||
class PxVehicleWheelsDynData
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleWheels;
|
||||
friend class PxVehicleDrive4W;
|
||||
friend class PxVehicleDriveTank;
|
||||
friend class PxVehicleUpdate;
|
||||
|
||||
PxVehicleWheelsDynData(){}
|
||||
~PxVehicleWheelsDynData(){}
|
||||
|
||||
/**
|
||||
\brief Set all wheels to their rest state.
|
||||
@see setup
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Set the tire force shader function
|
||||
\param[in] tireForceShaderFn is the shader function that will be used to compute tire forces.
|
||||
*/
|
||||
void setTireForceShaderFunction(PxVehicleComputeTireForce tireForceShaderFn);
|
||||
|
||||
/**
|
||||
\brief Set the tire force shader data for a specific tire
|
||||
\param[in] tireId is the wheel index
|
||||
\param[in] tireForceShaderData is the data describing the tire.
|
||||
*/
|
||||
void setTireForceShaderData(const PxU32 tireId, const void* tireForceShaderData);
|
||||
|
||||
/**
|
||||
\brief Get the tire force shader data for a specific tire
|
||||
*/
|
||||
const void* getTireForceShaderData(const PxU32 tireId) const;
|
||||
|
||||
/**
|
||||
\brief Set the wheel rotation speed (radians per second) about the rolling axis for the specified wheel.
|
||||
\param[in] wheelIdx is the wheel index
|
||||
\param[in] speed is the rotation speed to be applied to the wheel.
|
||||
*/
|
||||
void setWheelRotationSpeed(const PxU32 wheelIdx, const PxReal speed);
|
||||
|
||||
/**
|
||||
\brief Return the rotation speed about the rolling axis of a specified wheel .
|
||||
*/
|
||||
PxReal getWheelRotationSpeed(const PxU32 wheelIdx) const;
|
||||
|
||||
/**
|
||||
\brief Set the wheel rotation angle (radians) about the rolling axis of the specified wheel.
|
||||
\param[in] wheelIdx is the wheel index
|
||||
\param[in] angle is the rotation angle to be applied to the wheel.
|
||||
*/
|
||||
void setWheelRotationAngle(const PxU32 wheelIdx, const PxReal angle);
|
||||
|
||||
/**
|
||||
\brief Return the rotation angle about the rolling axis for the specified wheel.
|
||||
*/
|
||||
PxReal getWheelRotationAngle(const PxU32 wheelIdx) const;
|
||||
|
||||
/**
|
||||
\brief Set the user data pointer for the specified wheel
|
||||
It has a default value of NULL.
|
||||
\param[in] tireIdx is the wheel index
|
||||
\param[in] userData is the data to be associated with the wheel.
|
||||
*/
|
||||
void setUserData(const PxU32 tireIdx, void* userData);
|
||||
|
||||
/**
|
||||
\brief Get the user data pointer that was set for the specified wheel
|
||||
*/
|
||||
void* getUserData(const PxU32 tireIdx) const;
|
||||
|
||||
/**
|
||||
\brief Copy the dynamics data of a single wheel unit (wheel, suspension, tire) from srcWheel of src to trgWheel.
|
||||
\param[in] src is the data to be copied.
|
||||
\param[in] srcWheel is the wheel whose data will be copied from src.
|
||||
\param[in] trgWheel is the wheel that will be assigned the copied data.
|
||||
*/
|
||||
void copy(const PxVehicleWheelsDynData& src, const PxU32 srcWheel, const PxU32 trgWheel);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Dynamics data arranged in blocks of 4 wheels.
|
||||
*/
|
||||
PxVehicleWheels4DynData* mWheels4DynData;
|
||||
|
||||
/**
|
||||
\brief Test if wheel dynamics data have legal values.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
\brief Shader data and function for tire force calculations.
|
||||
*/
|
||||
PxVehicleTireForceCalculator* mTireForceCalculators;
|
||||
|
||||
/**
|
||||
\brief A userData pointer can be stored for each wheel.
|
||||
@see setUserData, getUserData
|
||||
*/
|
||||
void** mUserDatas;
|
||||
|
||||
/**
|
||||
\brief Number of blocks of 4 wheels.
|
||||
*/
|
||||
PxU32 mNbWheels4;
|
||||
|
||||
/**
|
||||
\brief Number of wheels (mNbActiveWheels <= (mNbWheels4*4))
|
||||
*/
|
||||
PxU32 mNbActiveWheels;
|
||||
|
||||
PxU32 mPad[3];
|
||||
|
||||
/**
|
||||
\brief see PxVehicleWheels::allocate
|
||||
*/
|
||||
static PxU32 computeByteSize(const PxU32 numWheels);
|
||||
static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsDynData* dynData, PxU8* ptr);
|
||||
PxVehicleWheelsDynData(const PxU32 numWheels);
|
||||
|
||||
//serialization
|
||||
public:
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
PxU32 getNbWheelRotationSpeed() const { return mNbActiveWheels; }
|
||||
PxU32 getNbWheelRotationAngle() const { return mNbActiveWheels; }
|
||||
PxVehicleWheels4DynData* getWheel4DynData() const { return mWheels4DynData; }
|
||||
//~serialization
|
||||
|
||||
/**
|
||||
\brief Retrieve the number of PxConstraint objects associated with the vehicle.
|
||||
|
||||
You can use #getConstraints() to retrieve the constraint pointers.
|
||||
|
||||
\return Number of constraints associated with this vehicle.
|
||||
|
||||
@see PxConstraint getConstraints()
|
||||
*/
|
||||
PxU32 getNbConstraints() const { return mNbWheels4; }
|
||||
|
||||
/**
|
||||
\brief Retrieve all the PxConstraint objects associated with the vehicle.
|
||||
|
||||
There is one PxConstraint per block of 4 wheels. The count can be extracted through #getNbConstraints()
|
||||
|
||||
\param[out] userBuffer The buffer to store the constraint pointers.
|
||||
\param[in] bufferSize Size of provided user buffer.
|
||||
\param[in] startIndex Index of first constraint pointer to be retrieved
|
||||
\return Number of constraint pointers written to the buffer.
|
||||
|
||||
@see PxConstraint getNbConstraints()
|
||||
*/
|
||||
PxU32 getConstraints(PxConstraint** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const;
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsDynData) & 15));
|
||||
|
||||
/**
|
||||
\brief Data structure with instanced dynamics data and configuration data of a vehicle with just wheels
|
||||
@see PxVehicleDrive, PxVehicleDrive4W, PxVehicleDriveTank
|
||||
*/
|
||||
class PxVehicleWheels : public PxBase
|
||||
{
|
||||
//= ATTENTION! =====================================================================================
|
||||
// Changing the data layout of this class breaks the binary serialization format. See comments for
|
||||
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
|
||||
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
|
||||
// accordingly.
|
||||
//==================================================================================================
|
||||
public:
|
||||
|
||||
friend class PxVehicleUpdate;
|
||||
friend class PxVehicleConstraintShader;
|
||||
|
||||
/**
|
||||
\brief Return the type of vehicle
|
||||
@see PxVehicleTypes
|
||||
*/
|
||||
PX_FORCE_INLINE PxU32 getVehicleType() const {return mType;}
|
||||
|
||||
/**
|
||||
\brief Get non-const ptr to PxRigidDynamic instance that is the vehicle's physx representation
|
||||
*/
|
||||
PX_FORCE_INLINE PxRigidDynamic* getRigidDynamicActor() {return mActor;}
|
||||
|
||||
/**
|
||||
\brief Get const ptr to PxRigidDynamic instance that is the vehicle's physx representation
|
||||
*/
|
||||
PX_FORCE_INLINE const PxRigidDynamic* getRigidDynamicActor() const {return mActor;}
|
||||
|
||||
/**
|
||||
\brief Compute the rigid body velocity component along the forward vector of the rigid body transform.
|
||||
@see PxVehicleSetBasisVectors
|
||||
*/
|
||||
PxReal computeForwardSpeed() const;
|
||||
|
||||
/**
|
||||
\brief Compute the rigid body velocity component along the right vector of the rigid body transform.
|
||||
@see PxVehicleSetBasisVectors
|
||||
*/
|
||||
PxReal computeSidewaysSpeed() const;
|
||||
|
||||
/**
|
||||
\brief Data describing the setup of all the wheels/suspensions/tires.
|
||||
*/
|
||||
PxVehicleWheelsSimData mWheelsSimData;
|
||||
|
||||
/**
|
||||
\brief Data describing the dynamic state of all wheels/suspension/tires.
|
||||
*/
|
||||
PxVehicleWheelsDynData mWheelsDynData;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
\brief Set all wheels to their rest state
|
||||
*/
|
||||
void setToRestState();
|
||||
|
||||
/**
|
||||
\brief Test that all configuration and instanced dynamics data is valid.
|
||||
*/
|
||||
bool isValid() const;
|
||||
|
||||
/**
|
||||
@see PxVehicleDrive4W::allocate, PxVehicleDriveTank::allocate
|
||||
*/
|
||||
static PxU32 computeByteSize(const PxU32 nbWheels);
|
||||
static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleWheels* vehWheels, PxU8* ptr);
|
||||
virtual void init(const PxU32 numWheels);
|
||||
|
||||
/**
|
||||
\brief Deallocate a PxVehicleWheels instance.
|
||||
@see PxVehicleDrive4W::free, PxVehicleDriveTank::free
|
||||
*/
|
||||
void free();
|
||||
|
||||
/*
|
||||
\brief Deferred deletion.
|
||||
*/
|
||||
void onConstraintRelease();
|
||||
|
||||
/**
|
||||
@see PxVehicleDrive4W::setup, PxVehicleDriveTank::setup
|
||||
*/
|
||||
void setup
|
||||
(PxPhysics* physics, PxRigidDynamic* vehActor,
|
||||
const PxVehicleWheelsSimData& wheelsData,
|
||||
const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
|
||||
|
||||
/**
|
||||
\brief The rigid body actor that represents the vehicle in the PhysX SDK.
|
||||
*/
|
||||
PxRigidDynamic* mActor;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
\brief Count the number of constraint connectors that have hit their callback when deleting a vehicle.
|
||||
Can only delete the vehicle's memory when all constraint connectors have hit their callback.
|
||||
*/
|
||||
PxU32 mNbNonDrivenWheels;
|
||||
|
||||
PxU8 mOnConstraintReleaseCounter;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
\brief Vehicle type (eVehicleDriveTypes)
|
||||
*/
|
||||
PxU8 mType;
|
||||
|
||||
#if PX_P64_FAMILY
|
||||
PxU8 mPad0[14];
|
||||
#else
|
||||
PxU8 mPad0[14];
|
||||
#endif
|
||||
|
||||
//serialization
|
||||
public:
|
||||
virtual void requiresObjects(PxProcessPxBaseCallback& c);
|
||||
virtual const char* getConcreteTypeName() const { return "PxVehicleWheels"; }
|
||||
virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleWheels", name) || PxBase::isKindOf(name); }
|
||||
virtual void preExportDataReset() {}
|
||||
virtual void exportExtraData(PxSerializationContext&);
|
||||
void importExtraData(PxDeserializationContext&);
|
||||
void resolveReferences(PxDeserializationContext&);
|
||||
static void getBinaryMetaData(PxOutputStream& stream);
|
||||
PX_FORCE_INLINE PxU32 getNbNonDrivenWheels() const { return mNbNonDrivenWheels; }
|
||||
PxVehicleWheels(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
|
||||
PxVehicleWheels(PxBaseFlags baseFlags) : PxBase(baseFlags), mWheelsSimData(PxEmpty) {}
|
||||
virtual ~PxVehicleWheels() {}
|
||||
virtual void release() { free(); }
|
||||
//~serialization
|
||||
};
|
||||
PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheels) & 15));
|
||||
|
||||
#if !PX_DOXYGEN
|
||||
} // namespace physx
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
#endif //PX_VEHICLE_WHEELS_H
|
||||
Reference in new issue
Block a user