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

source code of qtquick3dphysics/src/3rdparty/PhysX/include/vehicle/PxVehicleDriveTank.h