| 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_4WDRIVE_H |
| 31 | #define PX_VEHICLE_4WDRIVE_H |
| 32 | /** \addtogroup vehicle |
| 33 | @{ |
| 34 | */ |
| 35 | |
| 36 | #include "vehicle/PxVehicleDrive.h" |
| 37 | #include "vehicle/PxVehicleWheels.h" |
| 38 | #include "vehicle/PxVehicleComponents.h" |
| 39 | |
| 40 | |
| 41 | #if !PX_DOXYGEN |
| 42 | namespace physx |
| 43 | { |
| 44 | #endif |
| 45 | |
| 46 | struct PxFilterData; |
| 47 | class PxGeometry; |
| 48 | class PxPhysics; |
| 49 | class PxVehicleDrivableSurfaceToTireFrictionPairs; |
| 50 | class PxShape; |
| 51 | class PxMaterial; |
| 52 | class PxRigidDynamic; |
| 53 | |
| 54 | /** |
| 55 | \brief Data structure describing the drive model components of a vehicle with up to 4 driven wheels and up to 16 un-driven wheels. |
| 56 | The drive model incorporates engine, clutch, gears, autobox, differential, and Ackermann steer correction. |
| 57 | @see PxVehicleDriveSimData |
| 58 | */ |
| 59 | class PxVehicleDriveSimData4W : public PxVehicleDriveSimData |
| 60 | { |
| 61 | //= ATTENTION! ===================================================================================== |
| 62 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
| 63 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
| 64 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
| 65 | // accordingly. |
| 66 | //================================================================================================== |
| 67 | public: |
| 68 | |
| 69 | friend class PxVehicleDrive4W; |
| 70 | |
| 71 | PxVehicleDriveSimData4W() |
| 72 | : PxVehicleDriveSimData() |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | \brief Return the data describing the differential. |
| 78 | @see PxVehicleDifferential4WData |
| 79 | */ |
| 80 | PX_FORCE_INLINE const PxVehicleDifferential4WData& getDiffData() const |
| 81 | { |
| 82 | return mDiff; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | \brief Return the data describing the Ackermann steer-correction. |
| 87 | @see PxVehicleAckermannGeometryData |
| 88 | */ |
| 89 | PX_FORCE_INLINE const PxVehicleAckermannGeometryData& getAckermannGeometryData() const |
| 90 | { |
| 91 | return mAckermannGeometry; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | \brief Set the data describing the differential. |
| 96 | @see PxVehicleDifferential4WData |
| 97 | */ |
| 98 | void setDiffData(const PxVehicleDifferential4WData& diff); |
| 99 | |
| 100 | /** |
| 101 | \brief Set the data describing the Ackermann steer-correction. |
| 102 | @see PxVehicleAckermannGeometryData |
| 103 | */ |
| 104 | void setAckermannGeometryData(const PxVehicleAckermannGeometryData& ackermannData); |
| 105 | |
| 106 | private: |
| 107 | |
| 108 | /** |
| 109 | \brief Differential simulation data |
| 110 | @see setDiffData, getDiffData |
| 111 | */ |
| 112 | PxVehicleDifferential4WData mDiff; |
| 113 | |
| 114 | /** |
| 115 | \brief Data for ackermann steer angle computation. |
| 116 | @see setAckermannGeometryData, getAckermannGeometryData |
| 117 | */ |
| 118 | PxVehicleAckermannGeometryData mAckermannGeometry; |
| 119 | |
| 120 | /** |
| 121 | \brief Test if the 4W-drive simulation data has been setup with legal data. |
| 122 | \note Call only after setting all components. |
| 123 | @see setEnginedata, setClutchData, setGearsData, setAutoboxData, setDiffData, setAckermannGeometryData |
| 124 | */ |
| 125 | bool isValid() const; |
| 126 | |
| 127 | //serialization |
| 128 | public: |
| 129 | PxVehicleDriveSimData4W(const PxEMPTY) : PxVehicleDriveSimData(PxEmpty), mDiff(PxEmpty), mAckermannGeometry(PxEmpty) {} |
| 130 | static void getBinaryMetaData(PxOutputStream& stream); |
| 131 | //~serialization |
| 132 | }; |
| 133 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimData4W) & 15)); |
| 134 | |
| 135 | |
| 136 | |
| 137 | /** |
| 138 | \brief The ordering of the driven and steered wheels of a PxVehicleDrive4W. |
| 139 | |
| 140 | @see PxVehicleWheelsSimData, PxVehicleWheelsDynData |
| 141 | */ |
| 142 | |
| 143 | struct PxVehicleDrive4WWheelOrder |
| 144 | { |
| 145 | enum Enum |
| 146 | { |
| 147 | eFRONT_LEFT=0, |
| 148 | eFRONT_RIGHT, |
| 149 | eREAR_LEFT, |
| 150 | eREAR_RIGHT |
| 151 | }; |
| 152 | }; |
| 153 | |
| 154 | /** |
| 155 | \brief The control inputs for a PxVehicleDrive4W. |
| 156 | |
| 157 | @see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput |
| 158 | */ |
| 159 | |
| 160 | struct PxVehicleDrive4WControl |
| 161 | { |
| 162 | enum Enum |
| 163 | { |
| 164 | eANALOG_INPUT_ACCEL=0, |
| 165 | eANALOG_INPUT_BRAKE, |
| 166 | eANALOG_INPUT_HANDBRAKE, |
| 167 | eANALOG_INPUT_STEER_LEFT, |
| 168 | eANALOG_INPUT_STEER_RIGHT, |
| 169 | eMAX_NB_DRIVE4W_ANALOG_INPUTS |
| 170 | }; |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | \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. |
| 175 | */ |
| 176 | class PxVehicleDrive4W : public PxVehicleDrive |
| 177 | { |
| 178 | //= ATTENTION! ===================================================================================== |
| 179 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
| 180 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
| 181 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
| 182 | // accordingly. |
| 183 | //================================================================================================== |
| 184 | public: |
| 185 | friend class PxVehicleUpdate; |
| 186 | |
| 187 | /** |
| 188 | \brief Allocate a PxVehicleDrive4W instance for a 4WDrive vehicle with nbWheels (= 4 + number of un-driven wheels) |
| 189 | |
| 190 | \param[in] nbWheels is the number of vehicle wheels (= 4 + number of un-driven wheels) |
| 191 | |
| 192 | \return The instantiated vehicle. |
| 193 | |
| 194 | @see free, setup |
| 195 | */ |
| 196 | static PxVehicleDrive4W* allocate(const PxU32 nbWheels); |
| 197 | |
| 198 | /** |
| 199 | \brief Deallocate a PxVehicleDrive4W instance. |
| 200 | @see allocate |
| 201 | */ |
| 202 | void free(); |
| 203 | |
| 204 | /** |
| 205 | \brief Set up a vehicle using simulation data for the wheels and drive model. |
| 206 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
| 207 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
| 208 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
| 209 | \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. |
| 210 | \param[in] nbNonDrivenWheels is the number of wheels on the vehicle that cannot be connected to the differential (= numWheels - 4). |
| 211 | \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. |
| 212 | \note wheelsData must contain data for at least 4 wheels. Unwanted wheels can be disabled with PxVehicleWheelsSimData::disableWheel after calling setup. |
| 213 | @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping |
| 214 | */ |
| 215 | void setup |
| 216 | (PxPhysics* physics, PxRigidDynamic* vehActor, |
| 217 | const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData4W& driveData, |
| 218 | const PxU32 nbNonDrivenWheels); |
| 219 | |
| 220 | /** |
| 221 | \brief Allocate and set up a vehicle using simulation data for the wheels and drive model. |
| 222 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
| 223 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
| 224 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
| 225 | \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. |
| 226 | \param[in] nbNonDrivenWheels is the number of wheels on the vehicle that cannot be connected to the differential (= numWheels - 4). |
| 227 | \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. |
| 228 | \note wheelsData must contain data for at least 4 wheels. Unwanted wheels can be disabled with PxVehicleWheelsSimData::disableWheel after calling setup. |
| 229 | \return The instantiated vehicle. |
| 230 | @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping |
| 231 | */ |
| 232 | static PxVehicleDrive4W* create |
| 233 | (PxPhysics* physics, PxRigidDynamic* vehActor, |
| 234 | const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData4W& driveData, |
| 235 | const PxU32 nbNonDrivenWheels); |
| 236 | |
| 237 | /** |
| 238 | \brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body |
| 239 | to the state they were in immediately after setup or create. |
| 240 | \note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line |
| 241 | raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates. |
| 242 | @see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates |
| 243 | */ |
| 244 | void setToRestState(); |
| 245 | |
| 246 | /** |
| 247 | \brief Simulation data that describes the configuration of the vehicle's drive model. |
| 248 | @see setup, create |
| 249 | */ |
| 250 | PxVehicleDriveSimData4W mDriveSimData; |
| 251 | |
| 252 | private: |
| 253 | |
| 254 | /** |
| 255 | \brief Test if the instanced dynamics and configuration data has legal values. |
| 256 | */ |
| 257 | bool isValid() const; |
| 258 | |
| 259 | //serialization |
| 260 | protected: |
| 261 | PxVehicleDrive4W(); |
| 262 | ~PxVehicleDrive4W(){} |
| 263 | virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxVehicleDrive4W" , s2: name) || PxBase::isKindOf(superClass: name); } |
| 264 | public: |
| 265 | static PxVehicleDrive4W* createObject(PxU8*& address, PxDeserializationContext& context); |
| 266 | static void getBinaryMetaData(PxOutputStream& stream); |
| 267 | PxVehicleDrive4W(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags), mDriveSimData(PxEmpty) {} |
| 268 | virtual const char* getConcreteTypeName() const { return "PxVehicleDrive4W" ; } |
| 269 | //~serialization |
| 270 | }; |
| 271 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive4W) & 15)); |
| 272 | |
| 273 | #if !PX_DOXYGEN |
| 274 | } // namespace physx |
| 275 | #endif |
| 276 | |
| 277 | /** @} */ |
| 278 | #endif //PX_VEHICLE_4WDRIVE_H |
| 279 | |