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_DRIVE_TANK_H
14#define PX_VEHICLE_DRIVE_TANK_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 The ordering of the wheels of a PxVehicleDriveTank.
40
41@see PxVehicleWheelsSimData, PxVehicleWheelsDynData
42*/
43struct PxVehicleDriveTankWheelOrder
44{
45 enum Enum
46 {
47 eFRONT_LEFT=0,
48 eFRONT_RIGHT,
49 e1ST_FROM_FRONT_LEFT,
50 e1ST_FROM_FRONT_RIGHT,
51 e2ND_FROM_FRONT_LEFT,
52 e2ND_FROM_FRONT_RIGHT,
53 e3RD_FROM_FRONT_LEFT,
54 e3RD_FROM_FRONT_RIGHT,
55 e4TH_FROM_FRONT_LEFT,
56 e4TH_FROM_FRONT_RIGHT,
57 e5TH_FROM_FRONT_LEFT,
58 e5TH_FROM_FRONT_RIGHT,
59 e6TH_FROM_FRONT_LEFT,
60 e6TH_FROM_FRONT_RIGHT,
61 e7TH_FROM_FRONT_LEFT,
62 e7TH_FROM_FRONT_RIGHT,
63 e8TH_FROM_FRONT_LEFT,
64 e8TH_FROM_FRONT_RIGHT,
65 e9TH_FROM_FRONT_LEFT,
66 e9TH_FROM_FRONT_RIGHT
67 };
68};
69
70
71/**
72\brief The control inputs for a PxVehicleDriveTank.
73
74\note The values of eANALOG_INPUT_THRUST_LEFT and eANALOG_INPUT_THRUST_RIGHT determine how much
75of the total available drive torque is diverted to the left and right wheels. These entries in the
76enumerated list represent the state of the left and right control sticks of a tank. The total available
77drive torque available is controlled by eANALOG_INPUT_ACCEL, which represents the state of the acceleration
78pedal and controls how much torque will be applied to the engine.
79
80\note To accelerate forwards eANALOG_INPUT_ACCEL must be greater than zero so that torque is applied to drive the
81engine, while eANALOG_INPUT_THRUST_LEFT and eANALOG_INPUT_THRUST_RIGHT must also be greater than zero
82to divert the available drive torque to the left and wheels. If eANALOG_INPUT_THRUST_LEFT > eANALOG_INPUT_THRUST_RIGHT
83the tank will turn to the right. If eANALOG_INPUT_THRUST_RIGHT > eANALOG_INPUT_THRUST_LEFT
84the tank will turn to the left.
85
86@see PxVehicleDriveDynData::setAnalogInput, PxVehicleDriveDynData::getAnalogInput
87*/
88
89struct PxVehicleDriveTankControl
90{
91 enum Enum
92 {
93 eANALOG_INPUT_ACCEL=0,
94 eANALOG_INPUT_BRAKE_LEFT,
95 eANALOG_INPUT_BRAKE_RIGHT,
96 eANALOG_INPUT_THRUST_LEFT,
97 eANALOG_INPUT_THRUST_RIGHT,
98 eMAX_NB_DRIVETANK_ANALOG_INPUTS
99 };
100};
101
102/**
103\brief Two driving models are supported.
104
105\note If eSTANDARD is chosen the left and right wheels are always driven in the same direction. If the tank is in
106a forward gear the left and right wheels will all be driven forwards, while in reverse gear the left and right wheels
107will all be driven backwards. With eSTANDARD the legal range of left and right thrust is (0,1).
108
109\note If eSPECIAL is chosen it is possible to drive the left and right wheels in different directions.
110With eSPECIAL the legal range of left and right thrust is (-1,1). In forward(reverse) gear negative thrust values drive the wheels
111backwards(forwards), while positive thrust values drives the wheels forwards(backwards).
112
113\note A sharp left turn can be achieved in eSTANDARD mode by braking with the left wheels and thrusting forward with the
114right wheels. A smaller turning circle can theoretically be achieved in eSPECIAL mode by applying negative thrust to the left wheels and positive
115thrust to the right wheels.
116
117\note In both modes the legal ranges of acceleration and left/right brake are all (0,1).
118
119@see PxVehicleDriveTank::setDriveModel
120*/
121struct PxVehicleDriveTankControlModel
122{
123 enum Enum
124 {
125 eSTANDARD=0,
126 eSPECIAL
127 };
128};
129
130
131/**
132\brief Data structure with instanced dynamics data and configuration data of a tank.
133*/
134class PxVehicleDriveTank : 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//==================================================================================================
142public:
143
144 friend class PxVehicleUpdate;
145
146
147 /**
148 \brief Allocate a PxVehicleTankDrive instance for a tank with nbWheels
149
150 \param[in] nbWheels is the number of wheels on the vehicle.
151
152 \note It is assumed that all wheels are driven wheels.
153
154 \return The instantiated vehicle.
155
156 @see free, setup
157 */
158 static PxVehicleDriveTank* allocate(const PxU32 nbWheels);
159
160 /**
161 \brief Deallocate a PxVehicleDriveTank instance.
162 @see allocate
163 */
164 void free();
165
166 /**
167 \brief Set up a tank using simulation data for the wheels and drive model.
168 \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the vehicle.
169 \param[in] vehActor is a PxRigidDynamic instance that is used to represent the tank in the PhysX SDK.
170 \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the tank. The tank instance takes a copy of this data.
171 \param[in] driveData describes the properties of the tank's drive model (gears/engine/clutch/autobox). The tank instance takes a copy of this data.
172 \param[in] nbDrivenWheels is the number of wheels on the tank.
173 \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.
174 @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
175 \note nbDrivenWheels must be an even number
176 \note The wheels must be arranged according to PxVehicleDriveTankWheelOrder; that is,
177 the even wheels are on the left side of the tank and the odd wheels are on the right side of the tank.
178 */
179 void setup
180 (PxPhysics* physics, PxRigidDynamic* vehActor,
181 const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData& driveData,
182 const PxU32 nbDrivenWheels);
183
184 /**
185 \brief Allocate and set up a tank using simulation data for the wheels and drive model.
186 \param[in] physics is a PxPhysics instance that is needed to create special vehicle constraints that are maintained by the tank.
187 \param[in] vehActor is a PxRigidDynamic instance that is used to represent the tank in the PhysX SDK.
188 \param[in] wheelsData describes the configuration of all suspension/tires/wheels of the tank. The tank instance takes a copy of this data.
189 \param[in] driveData describes the properties of the tank's drive model (gears/engine/clutch/differential/autobox). The tank instance takes a copy of this data.
190 \param[in] nbDrivenWheels is the number of wheels on the tank.
191 \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.
192 \return The instantiated vehicle.
193 @see allocate, free, setToRestState, PxVehicleWheelsSimData::setWheelShapeMapping
194 */
195 static PxVehicleDriveTank* create
196 (PxPhysics* physics, PxRigidDynamic* vehActor,
197 const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData& driveData,
198 const PxU32 nbDrivenWheels);
199
200 /**
201 \brief Set the control model used by the tank.
202 \note eDRIVE_MODEL_STANDARD: turning achieved by braking on one side, accelerating on the other side.
203 \note eDRIVE_MODEL_SPECIAL: turning achieved by accelerating forwards on one side, accelerating backwards on the other side.
204 \note The default value is eDRIVE_MODEL_STANDARD
205 */
206 void setDriveModel(const PxVehicleDriveTankControlModel::Enum driveModel)
207 {
208 mDriveModel=driveModel;
209 }
210
211 /**
212 \brief Return the control model used by the tank.
213 */
214 PxVehicleDriveTankControlModel::Enum getDriveModel() const {return mDriveModel;}
215
216 /**
217 \brief Set a vehicle to its rest state. Aside from the rigid body transform, this will set the vehicle and rigid body
218 to the state they were in immediately after setup or create.
219 \note Calling setToRestState invalidates the cached raycast hit planes under each wheel meaning that suspension line
220 raycasts need to be performed at least once with PxVehicleSuspensionRaycasts before calling PxVehicleUpdates.
221 @see setup, create, PxVehicleSuspensionRaycasts, PxVehicleUpdates
222 */
223 void setToRestState();
224
225 /**
226 \brief Simulation data that models vehicle components
227 @see setup, create
228 */
229 PxVehicleDriveSimData mDriveSimData;
230
231private:
232 /**
233 \brief Test if the instanced dynamics and configuration data has legal values.
234 */
235 bool isValid() const;
236
237 /**
238 \brief Drive model
239 @see setDriveModel, getDriveModel, PxVehicleDriveTankControlModel
240 */
241 PxVehicleDriveTankControlModel::Enum mDriveModel;
242
243 PxU32 mPad[3];
244
245//serialization
246public:
247 PxVehicleDriveTank(PxBaseFlags baseFlags) : PxVehicleDrive(baseFlags) {}
248 static PxVehicleDriveTank* createObject(PxU8*& address, PxDeserializationContext& context);
249 static void getBinaryMetaData(PxOutputStream& stream);
250 virtual const char* getConcreteTypeName() const { return "PxVehicleDriveTank"; }
251 virtual bool isKindOf(const char* name) const { return !strcmp("PxVehicleDriveTank", name) || PxBase::isKindOf(name); }
252protected:
253 PxVehicleDriveTank();
254 ~PxVehicleDriveTank(){}
255//~serialization
256};
257PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveTank) & 15));
258
259#ifndef PX_DOXYGEN
260} // namespace physx
261#endif
262
263/** @} */
264#endif //PX_VEHICLE_DRIVE_TANK_H
265