| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | #ifndef PX_VEHICLE_NO_DRIVE_H |
| 14 | #define PX_VEHICLE_NO_DRIVE_H |
| 15 | /** \addtogroup vehicle |
| 16 | @{ |
| 17 | */ |
| 18 | |
| 19 | #include "vehicle/PxVehicleWheels.h" |
| 20 | #include "vehicle/PxVehicleComponents.h" |
| 21 | |
| 22 | |
| 23 | #ifndef PX_DOXYGEN |
| 24 | namespace physx |
| 25 | { |
| 26 | #endif |
| 27 | |
| 28 | struct PxFilterData; |
| 29 | class PxGeometry; |
| 30 | class PxPhysics; |
| 31 | class PxBatchQuery; |
| 32 | class PxVehicleDrivableSurfaceToTireFrictionPairs; |
| 33 | class PxShape; |
| 34 | class PxMaterial; |
| 35 | class PxRigidDynamic; |
| 36 | |
| 37 | /** |
| 38 | \brief Data structure with instanced dynamics data and configuration data of a vehicle with no drive model. |
| 39 | */ |
| 40 | class PxVehicleNoDrive : public PxVehicleWheels |
| 41 | { |
| 42 | //= ATTENTION! ===================================================================================== |
| 43 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
| 44 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
| 45 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
| 46 | // accordingly. |
| 47 | //================================================================================================== |
| 48 | public: |
| 49 | |
| 50 | friend class PxVehicleUpdate; |
| 51 | |
| 52 | /** |
| 53 | \brief Allocate a PxVehicleNoDrive instance for a vehicle without drive model and with nbWheels |
| 54 | |
| 55 | \param[in] nbWheels is the number of wheels on the vehicle. |
| 56 | |
| 57 | \return The instantiated vehicle. |
| 58 | |
| 59 | @see free, setup |
| 60 | */ |
| 61 | static PxVehicleNoDrive* allocate(const PxU32 nbWheels); |
| 62 | |
| 63 | /** |
| 64 | \brief Deallocate a PxVehicleNoDrive instance. |
| 65 | @see allocate |
| 66 | */ |
| 67 | void free(); |
| 68 | |
| 69 | /** |
| 70 | \brief Set up a vehicle using simulation data for the wheels. |
| 71 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
| 72 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
| 73 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
| 74 | \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. |
| 75 | @see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping |
| 76 | */ |
| 77 | void setup |
| 78 | (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData); |
| 79 | |
| 80 | /** |
| 81 | \brief Allocate and set up a vehicle using simulation data for the wheels. |
| 82 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
| 83 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
| 84 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
| 85 | \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. |
| 86 | \return The instantiated vehicle. |
| 87 | @see allocate, free, setToRestState, PxVehicleWheels::setWheelShapeMapping |
| 88 | */ |
| 89 | static PxVehicleNoDrive* create |
| 90 | (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData); |
| 91 | |
| 92 | /** |
| 93 | \brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body |
| 94 | to the state they were in immediately after setup or create. |
| 95 | \note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line |
| 96 | raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates. |
| 97 | @see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates |
| 98 | */ |
| 99 | void setToRestState(); |
| 100 | |
| 101 | /** |
| 102 | \brief Set the brake torque to be applied to a specific wheel |
| 103 | |
| 104 | \note The applied brakeTorque persists until the next call to setBrakeTorque |
| 105 | |
| 106 | \note The brake torque is specified in Newton metres. |
| 107 | |
| 108 | \param[in] id is the wheel being given the brake torque |
| 109 | \param[in] brakeTorque is the value of the brake torque |
| 110 | */ |
| 111 | void setBrakeTorque(const PxU32 id, const PxReal brakeTorque); |
| 112 | |
| 113 | /** |
| 114 | \brief Set the drive torque to be applied to a specific wheel |
| 115 | |
| 116 | \note The applied driveTorque persists until the next call to setDriveTorque |
| 117 | |
| 118 | \note The brake torque is specified in Newton metres. |
| 119 | |
| 120 | \param[in] id is the wheel being given the brake torque |
| 121 | \param[in] driveTorque is the value of the brake torque |
| 122 | */ |
| 123 | void setDriveTorque(const PxU32 id, const PxReal driveTorque); |
| 124 | |
| 125 | /** |
| 126 | \brief Set the steer angle to be applied to a specific wheel |
| 127 | |
| 128 | \note The applied steerAngle persists until the next call to setSteerAngle |
| 129 | |
| 130 | \note The steer angle is specified in radians. |
| 131 | |
| 132 | \param[in] id is the wheel being given the steer angle |
| 133 | \param[in] steerAngle is the value of the steer angle in radians. |
| 134 | */ |
| 135 | void setSteerAngle(const PxU32 id, const PxReal steerAngle); |
| 136 | |
| 137 | /** |
| 138 | \brief Get the brake torque that has been applied to a specific wheel |
| 139 | \param[in] id is the wheel being queried for its brake torque |
| 140 | \return The brake torque applied to the queried wheel. |
| 141 | */ |
| 142 | PxReal getBrakeTorque(const PxU32 id) const; |
| 143 | |
| 144 | /** |
| 145 | \brief Get the drive torque that has been applied to a specific wheel |
| 146 | \param[in] id is the wheel being queried for its drive torque |
| 147 | \return The drive torque applied to the queried wheel. |
| 148 | */ |
| 149 | PxReal getDriveTorque(const PxU32 id) const; |
| 150 | |
| 151 | /** |
| 152 | \brief Get the steer angle that has been applied to a specific wheel |
| 153 | \param[in] id is the wheel being queried for its steer angle |
| 154 | \return The steer angle (in radians) applied to the queried wheel. |
| 155 | */ |
| 156 | PxReal getSteerAngle(const PxU32 id) const; |
| 157 | |
| 158 | private: |
| 159 | |
| 160 | PxReal* mSteerAngles; |
| 161 | PxReal* mDriveTorques; |
| 162 | PxReal* mBrakeTorques; |
| 163 | |
| 164 | #if defined(PX_P64) |
| 165 | PxU32 mPad[2]; |
| 166 | #else |
| 167 | PxU32 mPad[1]; |
| 168 | #endif |
| 169 | |
| 170 | /** |
| 171 | \brief Test if the instanced dynamics and configuration data has legal values. |
| 172 | */ |
| 173 | bool isValid() const; |
| 174 | |
| 175 | |
| 176 | //serialization |
| 177 | public: |
| 178 | PxVehicleNoDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags) {} |
| 179 | virtual void (PxSerializationContext&); |
| 180 | void (PxDeserializationContext&); |
| 181 | static PxVehicleNoDrive* createObject(PxU8*& address, PxDeserializationContext& context); |
| 182 | static void getBinaryMetaData(PxOutputStream& stream); |
| 183 | virtual const char* getConcreteTypeName() const { return "PxVehicleNoDrive" ; } |
| 184 | virtual bool isKindOf(const char* name) const { return !strcmp("PxVehicleNoDrive" , name) || PxBase::isKindOf(name); } |
| 185 | PxU32 getNbSteerAngle() const { return mWheelsSimData.getNbWheels(); } |
| 186 | PxU32 getNbDriveTorque() const { return mWheelsSimData.getNbWheels(); } |
| 187 | PxU32 getNbBrakeTorque() const { return mWheelsSimData.getNbWheels(); } |
| 188 | protected: |
| 189 | PxVehicleNoDrive(); |
| 190 | ~PxVehicleNoDrive() {} |
| 191 | //~serialization |
| 192 | }; |
| 193 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleNoDrive) & 15)); |
| 194 | |
| 195 | #ifndef PX_DOXYGEN |
| 196 | } // namespace physx |
| 197 | #endif |
| 198 | |
| 199 | /** @} */ |
| 200 | #endif //PX_VEHICLE_NO_DRIVE_H |
| 201 | |