| 1 | // |
| 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions |
| 4 | // are met: |
| 5 | // * Redistributions of source code must retain the above copyright |
| 6 | // notice, this list of conditions and the following disclaimer. |
| 7 | // * Redistributions in binary form must reproduce the above copyright |
| 8 | // notice, this list of conditions and the following disclaimer in the |
| 9 | // documentation and/or other materials provided with the distribution. |
| 10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
| 11 | // contributors may be used to endorse or promote products derived |
| 12 | // from this software without specific prior written permission. |
| 13 | // |
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
| 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | // |
| 26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
| 27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 29 | |
| 30 | #ifndef PX_VEHICLE_TIREFRICTION_H |
| 31 | #define PX_VEHICLE_TIREFRICTION_H |
| 32 | /** \addtogroup vehicle |
| 33 | @{ |
| 34 | */ |
| 35 | |
| 36 | #include "foundation/PxSimpleTypes.h" |
| 37 | |
| 38 | #if !PX_DOXYGEN |
| 39 | namespace physx |
| 40 | { |
| 41 | #endif |
| 42 | |
| 43 | class PxMaterial; |
| 44 | |
| 45 | /** |
| 46 | \brief Driving surface type. Each PxMaterial is associated with a corresponding PxVehicleDrivableSurfaceType. |
| 47 | @see PxMaterial, PxVehicleDrivableSurfaceToTireFrictionPairs |
| 48 | */ |
| 49 | struct PxVehicleDrivableSurfaceType |
| 50 | { |
| 51 | enum |
| 52 | { |
| 53 | eSURFACE_TYPE_UNKNOWN=0xffffffff |
| 54 | }; |
| 55 | PxU32 mType; |
| 56 | }; |
| 57 | |
| 58 | /** |
| 59 | \brief Friction for each combination of driving surface type and tire type. |
| 60 | @see PxVehicleDrivableSurfaceType, PxVehicleTireData::mType |
| 61 | */ |
| 62 | class PxVehicleDrivableSurfaceToTireFrictionPairs |
| 63 | { |
| 64 | public: |
| 65 | |
| 66 | friend class VehicleSurfaceTypeHashTable; |
| 67 | |
| 68 | enum |
| 69 | { |
| 70 | eMAX_NB_SURFACE_TYPES=256 |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | \brief Allocate the memory for a PxVehicleDrivableSurfaceToTireFrictionPairs instance |
| 75 | that can hold data for combinations of tire type and surface type with up to maxNbTireTypes types of tire and maxNbSurfaceTypes types of surface. |
| 76 | |
| 77 | \param[in] maxNbTireTypes is the maximum number of allowed tire types. |
| 78 | \param[in] maxNbSurfaceTypes is the maximum number of allowed surface types. Must be less than or equal to eMAX_NB_SURFACE_TYPES |
| 79 | |
| 80 | \return a PxVehicleDrivableSurfaceToTireFrictionPairs instance that can be reused later with new type and friction data. |
| 81 | |
| 82 | @see setup |
| 83 | */ |
| 84 | static PxVehicleDrivableSurfaceToTireFrictionPairs* allocate |
| 85 | (const PxU32 maxNbTireTypes, const PxU32 maxNbSurfaceTypes); |
| 86 | |
| 87 | /** |
| 88 | \brief Set up a PxVehicleDrivableSurfaceToTireFrictionPairs instance for combinations of nbTireTypes tire types and nbSurfaceTypes surface types. |
| 89 | |
| 90 | \param[in] nbTireTypes is the number of different types of tire. This value must be less than or equal to maxNbTireTypes specified in allocate(). |
| 91 | \param[in] nbSurfaceTypes is the number of different types of surface. This value must be less than or equal to maxNbSurfaceTypes specified in allocate(). |
| 92 | \param[in] drivableSurfaceMaterials is an array of PxMaterial pointers of length nbSurfaceTypes. |
| 93 | \param[in] drivableSurfaceTypes is an array of PxVehicleDrivableSurfaceType instances of length nbSurfaceTypes. |
| 94 | |
| 95 | \note If the pointer to the PxMaterial that touches the tire is found in drivableSurfaceMaterials[x] then the surface type is drivableSurfaceTypes[x].mType |
| 96 | and the friction is the value that is set with setTypePairFriction(drivableSurfaceTypes[x].mType, PxVehicleTireData::mType, frictionValue). |
| 97 | |
| 98 | \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. |
| 99 | @see release, setTypePairFriction, getTypePairFriction, PxVehicleTireData.mType |
| 100 | */ |
| 101 | void setup |
| 102 | (const PxU32 nbTireTypes, const PxU32 nbSurfaceTypes, |
| 103 | const PxMaterial** drivableSurfaceMaterials, const PxVehicleDrivableSurfaceType* drivableSurfaceTypes); |
| 104 | |
| 105 | /** |
| 106 | \brief Deallocate a PxVehicleDrivableSurfaceToTireFrictionPairs instance |
| 107 | */ |
| 108 | void release(); |
| 109 | |
| 110 | /** |
| 111 | \brief Set the friction for a specified pair of tire type and drivable surface type. |
| 112 | |
| 113 | \param[in] surfaceType describes the surface type |
| 114 | \param[in] tireType describes the tire type. |
| 115 | \param[in] value describes the friction coefficient for the combination of surface type and tire type. |
| 116 | */ |
| 117 | void setTypePairFriction(const PxU32 surfaceType, const PxU32 tireType, const PxReal value); |
| 118 | |
| 119 | /** |
| 120 | \brief Return the friction for a specified combination of surface type and tire type. |
| 121 | \return The friction for a specified combination of surface type and tire type. |
| 122 | \note The final friction value used by the tire model is the value returned by getTypePairFriction |
| 123 | multiplied by the value computed from PxVehicleTireData::mFrictionVsSlipGraph |
| 124 | @see PxVehicleTireData::mFrictionVsSlipGraph |
| 125 | */ |
| 126 | PxReal getTypePairFriction(const PxU32 surfaceType, const PxU32 tireType) const; |
| 127 | |
| 128 | /** |
| 129 | \brief Return the maximum number of surface types |
| 130 | \return The maximum number of surface types |
| 131 | @see allocate |
| 132 | */ |
| 133 | PxU32 getMaxNbSurfaceTypes() const {return mMaxNbSurfaceTypes;} |
| 134 | |
| 135 | /** |
| 136 | \brief Return the maximum number of tire types |
| 137 | \return The maximum number of tire types |
| 138 | @see allocate |
| 139 | */ |
| 140 | PxU32 getMaxNbTireTypes() const {return mMaxNbTireTypes;} |
| 141 | |
| 142 | private: |
| 143 | |
| 144 | /** |
| 145 | \brief Ptr to base address of a 2d PxReal array with dimensions [mNbSurfaceTypes][mNbTireTypes] |
| 146 | |
| 147 | \note Each element of the array describes the maximum friction provided by a surface type-tire type combination. |
| 148 | eg the friction corresponding to a combination of surface type x and tire type y is mPairs[x][y] |
| 149 | */ |
| 150 | PxReal* mPairs; |
| 151 | |
| 152 | /** |
| 153 | \brief Ptr to 1d array of material ptrs that is of length mNbSurfaceTypes. |
| 154 | |
| 155 | \note If the PxMaterial that touches the tire corresponds to mDrivableSurfaceMaterials[x] then the drivable surface |
| 156 | type is mDrivableSurfaceTypes[x].mType and the friction for that contact is mPairs[mDrivableSurfaceTypes[x].mType][y], |
| 157 | assuming a tire type y. |
| 158 | |
| 159 | \note If the PxMaterial that touches the tire is not found in mDrivableSurfaceMaterials then the friction is |
| 160 | mPairs[0][y], assuming a tire type y. |
| 161 | */ |
| 162 | const PxMaterial** mDrivableSurfaceMaterials; |
| 163 | |
| 164 | /** |
| 165 | \brief Ptr to 1d array of PxVehicleDrivableSurfaceType that is of length mNbSurfaceTypes. |
| 166 | |
| 167 | \note If the PxMaterial that touches the tire is found in mDrivableSurfaceMaterials[x] then the drivable surface |
| 168 | type is mDrivableSurfaceTypes[x].mType and the friction for that contact is mPairs[mDrivableSurfaceTypes[x].mType][y], |
| 169 | assuming a tire type y. |
| 170 | |
| 171 | \note If the PxMaterial that touches the tire is not found in mDrivableSurfaceMaterials then the friction is |
| 172 | mPairs[0][y], assuming a tire type y. |
| 173 | */ |
| 174 | PxVehicleDrivableSurfaceType* mDrivableSurfaceTypes; |
| 175 | |
| 176 | /** |
| 177 | \brief Number of different driving surface types. |
| 178 | |
| 179 | \note mDrivableSurfaceMaterials and mDrivableSurfaceTypes are both 1d arrays of length mMaxNbSurfaceTypes. |
| 180 | |
| 181 | \note mNbSurfaceTypes must be less than or equal to mMaxNbSurfaceTypes. |
| 182 | */ |
| 183 | PxU32 mNbSurfaceTypes; |
| 184 | |
| 185 | /** |
| 186 | \brief Maximum number of different driving surface types. |
| 187 | |
| 188 | \note mMaxNbSurfaceTypes must be less than or equal to eMAX_NB_SURFACE_TYPES. |
| 189 | */ |
| 190 | PxU32 mMaxNbSurfaceTypes; |
| 191 | |
| 192 | /** |
| 193 | \brief Number of different tire types. |
| 194 | |
| 195 | \note Tire types stored in PxVehicleTireData.mType |
| 196 | */ |
| 197 | PxU32 mNbTireTypes; |
| 198 | |
| 199 | /** |
| 200 | \brief Maximum number of different tire types. |
| 201 | |
| 202 | \note Tire types stored in PxVehicleTireData.mType |
| 203 | */ |
| 204 | PxU32 mMaxNbTireTypes; |
| 205 | |
| 206 | |
| 207 | #if !PX_P64_FAMILY |
| 208 | PxU32 mPad[1]; |
| 209 | #else |
| 210 | PxU32 mPad[2]; |
| 211 | #endif |
| 212 | |
| 213 | PxVehicleDrivableSurfaceToTireFrictionPairs(){} |
| 214 | ~PxVehicleDrivableSurfaceToTireFrictionPairs(){} |
| 215 | }; |
| 216 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrivableSurfaceToTireFrictionPairs) & 15)); |
| 217 | |
| 218 | #if !PX_DOXYGEN |
| 219 | } // namespace physx |
| 220 | #endif |
| 221 | |
| 222 | /** @} */ |
| 223 | #endif //PX_VEHICLE_TIREFRICTION_H |
| 224 | |