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