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