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_NWDRIVE_H |
14 | #define PX_VEHICLE_NWDRIVE_H |
15 | /** \addtogroup vehicle |
16 | @{ |
17 | */ |
18 | |
19 | #include "vehicle/PxVehicleDrive.h" |
20 | #include "vehicle/PxVehicleWheels.h" |
21 | #include "vehicle/PxVehicleComponents.h" |
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 describing configuration data of a vehicle with up to PX_MAX_NB_WHEELS driven equally through the differential. The vehicle has an |
39 | engine, clutch, gears, autobox, differential. |
40 | @see PxVehicleDriveSimData |
41 | */ |
42 | class PxVehicleDriveSimDataNW : public PxVehicleDriveSimData |
43 | { |
44 | //= ATTENTION! ===================================================================================== |
45 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
46 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
47 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
48 | // accordingly. |
49 | //================================================================================================== |
50 | public: |
51 | |
52 | friend class PxVehicleDriveNW; |
53 | |
54 | PxVehicleDriveSimDataNW() |
55 | : PxVehicleDriveSimData() |
56 | { |
57 | } |
58 | |
59 | /** |
60 | \brief Return the data describing the differential of a vehicle with up to PX_MAX_NB_WHEELS driven wheels. |
61 | */ |
62 | const PxVehicleDifferentialNWData& getDiffData() const |
63 | { |
64 | return mDiff; |
65 | } |
66 | |
67 | /** |
68 | \brief Set the data describing the differential of a vehicle with up to PX_MAX_NB_WHEELS driven wheels. |
69 | The differential data describes the set of wheels that are driven by the differential. |
70 | */ |
71 | void setDiffData(const PxVehicleDifferentialNWData& diff); |
72 | |
73 | private: |
74 | |
75 | /** |
76 | \brief Differential simulation data |
77 | @see setDiffData, getDiffData |
78 | */ |
79 | PxVehicleDifferentialNWData mDiff; |
80 | |
81 | /** |
82 | \brief Test if the NW-drive simulation data has been setup with legal data. |
83 | Call only after setting all components. |
84 | @see setEngineData, setClutchData, setGearsData, setAutoboxData, setDiffData, setAckermannGeometryData |
85 | */ |
86 | bool isValid() const; |
87 | |
88 | //serialization |
89 | public: |
90 | PxVehicleDriveSimDataNW(const PxEMPTY&) : PxVehicleDriveSimData(PxEmpty), mDiff(PxEmpty) {} |
91 | static void getBinaryMetaData(PxOutputStream& stream); |
92 | //~serialization |
93 | }; |
94 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimDataNW) & 15)); |
95 | |
96 | |
97 | /** |
98 | \brief The control inputs for a PxVehicleDriveNW. |
99 | |
100 | @see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput |
101 | */ |
102 | struct PxVehicleDriveNWControl |
103 | { |
104 | enum Enum |
105 | { |
106 | eANALOG_INPUT_ACCEL=0, |
107 | eANALOG_INPUT_BRAKE, |
108 | eANALOG_INPUT_HANDBRAKE, |
109 | eANALOG_INPUT_STEER_LEFT, |
110 | eANALOG_INPUT_STEER_RIGHT, |
111 | eMAX_NB_DRIVENW_ANALOG_INPUTS |
112 | }; |
113 | }; |
114 | |
115 | /** |
116 | \brief Data structure with instanced dynamics data and configuration data of a vehicle with up to PX_MAX_NB_WHEELS driven wheels. |
117 | */ |
118 | class PxVehicleDriveNW : public PxVehicleDrive |
119 | { |
120 | //= ATTENTION! ===================================================================================== |
121 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
122 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
123 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
124 | // accordingly. |
125 | //================================================================================================== |
126 | public: |
127 | |
128 | friend class PxVehicleUpdate; |
129 | |
130 | /** |
131 | \brief Allocate a PxVehicleDriveNW instance for a NWDrive vehicle with nbWheels |
132 | |
133 | \param[in] nbWheels is the number of wheels on the vehicle. |
134 | |
135 | \return The instantiated vehicle. |
136 | |
137 | @see free, setup |
138 | */ |
139 | static PxVehicleDriveNW* allocate(const PxU32 nbWheels); |
140 | |
141 | /** |
142 | \brief Deallocate a PxVehicleDriveNW instance. |
143 | @see allocate |
144 | */ |
145 | void free(); |
146 | |
147 | /** |
148 | \brief Set up a vehicle using simulation data for the wheels and drive model. |
149 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
150 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
151 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
152 | \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. |
153 | \param[in] nbWheels is the number of wheels on the vehicle. |
154 | \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. |
155 | @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping |
156 | */ |
157 | void setup |
158 | (PxPhysics* physics, PxRigidDynamic* vehActor, |
159 | const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimDataNW& driveData, |
160 | const PxU32 nbWheels); |
161 | |
162 | /** |
163 | \brief Allocate and set up a vehicle using simulation data for the wheels and drive model. |
164 | \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle. |
165 | \param[in] vehActor is a PxRigidDynamic instance that is used to represent the vehicle in the PhysX SDK. |
166 | \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the vehicle. The vehicle instance takes a copy of this data. |
167 | \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. |
168 | \param[in] nbWheels is the number of wheels on the vehicle. |
169 | \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. |
170 | \return The instantiated vehicle. |
171 | @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping |
172 | */ |
173 | static PxVehicleDriveNW* create |
174 | (PxPhysics* physics, PxRigidDynamic* vehActor, |
175 | const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimDataNW& driveData, |
176 | const PxU32 nbWheels); |
177 | |
178 | /** |
179 | \brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body |
180 | to the state they were in immediately after setup or create. |
181 | \note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line |
182 | raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates. |
183 | @see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates |
184 | */ |
185 | void setToRestState(); |
186 | |
187 | /** |
188 | \brief Simulation data that describes the configuration of the vehicle's drive model. |
189 | @see setup, create |
190 | */ |
191 | PxVehicleDriveSimDataNW mDriveSimData; |
192 | |
193 | private: |
194 | |
195 | /** |
196 | \brief Test if the instanced dynamics and configuration data has legal values. |
197 | */ |
198 | bool isValid() const; |
199 | |
200 | //serialization |
201 | public: |
202 | PxVehicleDriveNW(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags), mDriveSimData(PxEmpty) {} |
203 | PxVehicleDriveNW(); |
204 | ~PxVehicleDriveNW(){} |
205 | static PxVehicleDriveNW* createObject(PxU8*& address, PxDeserializationContext& context); |
206 | static void getBinaryMetaData(PxOutputStream& stream); |
207 | virtual const char* getConcreteTypeName() const { return "PxVehicleDriveNW" ; } |
208 | virtual bool isKindOf(const char* name) const { return !strcmp("PxVehicleDriveNW" , name) || PxBase::isKindOf(name); } |
209 | //~serialization |
210 | }; |
211 | PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveNW) & 15)); |
212 | |
213 | |
214 | |
215 | #ifndef PX_DOXYGEN |
216 | } // namespace physx |
217 | #endif |
218 | |
219 | /** @} */ |
220 | #endif //PX_VEHICLE_NWDRIVE_H |
221 | |