RavEngine
Loading...
Searching...
No Matches
PxVehicleDrive.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_VEHICLE_DRIVE_H
30#define PX_VEHICLE_DRIVE_H
31
32#include "vehicle/PxVehicleWheels.h"
33#include "vehicle/PxVehicleComponents.h"
34
35#if !PX_DOXYGEN
36namespace physx
37{
38#endif
39
40struct PxFilterData;
41class PxGeometry;
42class PxPhysics;
43class PxVehicleDrivableSurfaceToTireFrictionPairs;
44class PxShape;
45class PxMaterial;
46class PxRigidDynamic;
47
53{
54//= ATTENTION! =====================================================================================
55// Changing the data layout of this class breaks the binary serialization format. See comments for
56// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
57// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
58// accordingly.
59//==================================================================================================
60public:
61
62 friend class PxVehicleDriveTank;
63
68 {
69 return mEngine;
70 }
71
76 void setEngineData(const PxVehicleEngineData& engine);
77
82 {
83 return mGears;
84 }
85
90 void setGearsData(const PxVehicleGearsData& gears);
91
96 {
97 return mClutch;
98 }
99
104 void setClutchData(const PxVehicleClutchData& clutch);
105
110 {
111 return mAutoBox;
112 }
113
118 void setAutoBoxData(const PxVehicleAutoBoxData& autobox);
119
120protected:
121 /*
122 \brief Engine simulation data
123 @see setEngineData, getEngineData
124 */
125 PxVehicleEngineData mEngine;
126
127 /*
128 \brief Gear simulation data
129 @see setGearsData, getGearsData
130 */
131 PxVehicleGearsData mGears;
132
133 /*
134 \brief Clutch simulation data
135 @see setClutchData, getClutchData
136 */
137 PxVehicleClutchData mClutch;
138
139 /*
140 \brief Autobox simulation data
141 @see setAutoboxData, getAutoboxData
142 */
143 PxVehicleAutoBoxData mAutoBox;
144
150 bool isValid() const;
151
152
153//serialization
154public:
156 PxVehicleDriveSimData(const PxEMPTY) : mEngine(PxEmpty), mGears(PxEmpty), mClutch(PxEmpty), mAutoBox(PxEmpty) {}
157 static void getBinaryMetaData(PxOutputStream& stream);
158//~serialization
159};
160PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveSimData) & 15));
161
162
168{
169public:
170
171 enum
172 {
173 eMAX_NB_ANALOG_INPUTS=16
174 };
175
176 friend class PxVehicleDrive;
177
181 void setToRestState();
182
189 void setAnalogInput(const PxU32 type, const PxReal analogVal);
190
196 PxReal getAnalogInput(const PxU32 type) const;
197
207 void setGearUp(const bool digitalVal)
208 {
209 mGearUpPressed = digitalVal;
210 }
211
221 void setGearDown(const bool digitalVal)
222 {
223 mGearDownPressed = digitalVal;
224 }
225
230 bool getGearUp() const
231 {
232 return mGearUpPressed;
233 }
234
239 bool getGearDown() const
240 {
241 return mGearDownPressed;
242 }
243
249 PX_FORCE_INLINE void setUseAutoGears(const bool useAutoGears)
250 {
251 mUseAutoGears=useAutoGears;
252 }
253
259 {
260 return mUseAutoGears;
261 }
262
268 {
269 mUseAutoGears = !mUseAutoGears;
270 }
271
283 PX_FORCE_INLINE void setCurrentGear(PxU32 currentGear)
284 {
285 mCurrentGear = currentGear;
286 }
287
296 {
297 return mCurrentGear;
298 }
299
311 PX_FORCE_INLINE void setTargetGear(PxU32 targetGear)
312 {
313 mTargetGear = targetGear;
314 }
315
324 {
325 return mTargetGear;
326 }
327
337 PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
338 {
339 mTargetGear=targetGear;
340 }
341
349 PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
350 {
351 mTargetGear=targetGear;
352 mCurrentGear=targetGear;
353 }
354
361 {
362 mEnginespeed = speed;
363 }
364
371 {
372 return mEnginespeed;
373 }
374
385 {
386 return mGearSwitchTime;
387 }
388
397 {
398 return mAutoBoxSwitchTime;
399 }
400
410 PxReal mControlAnalogVals[eMAX_NB_ANALOG_INPUTS];
411
417
426
435
441
447
453
459
465
466private:
467 PxU32 mPad[2];
468
473 bool isValid() const;
474
475//serialization
476public:
479 PxU32 getNbAnalogInput() const { return eMAX_NB_ANALOG_INPUTS; }
480 PX_FORCE_INLINE void setGearChange(const PxU32 gearChange) { mTargetGear= gearChange; }
481 PX_FORCE_INLINE PxU32 getGearChange() const { return mTargetGear; }
482 PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime) { mGearSwitchTime = switchTime; }
483 PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime) { mAutoBoxSwitchTime = autoBoxSwitchTime; }
484//~serialization
485};
486PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDriveDynData) & 15));
487
493{
494//= ATTENTION! =====================================================================================
495// Changing the data layout of this class breaks the binary serialization format. See comments for
496// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
497// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
498// accordingly.
499//==================================================================================================
500public:
501
502 friend class PxVehicleUpdate;
503
509
510protected:
511
515 bool isValid() const;
516
520 void setToRestState();
521
525 static PxU32 computeByteSize(const PxU32 numWheels);
526 static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleDrive* vehDrive, PxU8* ptr);
527 virtual void init(const PxU32 numWheels);
528
533 void free();
534
538 void setup
539 (PxPhysics* physics, PxRigidDynamic* vehActor,
540 const PxVehicleWheelsSimData& wheelsData,
541 const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
542
543//serialization
544public:
545 static void getBinaryMetaData(PxOutputStream& stream);
546 PxVehicleDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags), mDriveDynData(PxEmpty) {}
547 virtual const char* getConcreteTypeName() const { return "PxVehicleDrive"; }
548protected:
549 PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags) : PxVehicleWheels(concreteType, baseFlags) {}
550 ~PxVehicleDrive() {}
551 virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDrive", name) || PxBase::isKindOf(name); }
552//~serialization
553};
554PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive) & 15));
555
556#if !PX_DOXYGEN
557} // namespace physx
558#endif
559
560#endif
Output stream class for I/O.
Definition PxIO.h:114
Abstract singleton factory class used for instancing objects in the Physics SDK.
Definition PxPhysics.h:91
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition PxRigidDynamic.h:82
Definition PxVehicleComponents.h:344
Definition PxVehicleComponents.h:661
Data structure with instanced dynamics data for vehicle with engine, clutch, gears,...
Definition PxVehicleDrive.h:168
PX_FORCE_INLINE void setUseAutoGears(const bool useAutoGears)
Set the flag that will be used to select auto-gears If useAutoGears is true the auto-box will be acti...
Definition PxVehicleDrive.h:249
PxReal mGearSwitchTime
Reported time that has passed since gear change started.
Definition PxVehicleDrive.h:458
PX_FORCE_INLINE PxReal getGearSwitchTime() const
Return the time that has passed since the current gear change was initiated.
Definition PxVehicleDrive.h:384
PxReal mAutoBoxSwitchTime
Reported time that has passed since last autobox gearup/geardown decision.
Definition PxVehicleDrive.h:464
bool getGearDown() const
Check if the gear-down button has been pressed.
Definition PxVehicleDrive.h:239
PX_FORCE_INLINE PxU32 getCurrentGear() const
Get the current gear.
Definition PxVehicleDrive.h:295
PxU32 mTargetGear
Target gear (different from current gear if a gear change is underway)
Definition PxVehicleDrive.h:446
void setGearUp(const bool digitalVal)
Inform the vehicle that the gear-up button has been pressed.
Definition PxVehicleDrive.h:207
bool mUseAutoGears
Auto-gear flag used by vehicle simulation. Set true to enable the autobox, false to disable the autob...
Definition PxVehicleDrive.h:416
PX_FORCE_INLINE void setEngineRotationSpeed(const PxF32 speed)
Set the rotation speed of the engine (radians per second)
Definition PxVehicleDrive.h:360
PX_FORCE_INLINE void toggleAutoGears()
Toggle the auto-gears flag If useAutoGears is true the auto-box will be active.
Definition PxVehicleDrive.h:267
bool mGearUpPressed
Gear-up digital control value used by vehicle simulation.
Definition PxVehicleDrive.h:425
PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
Force an immediate gear change to a target gear.
Definition PxVehicleDrive.h:349
PX_FORCE_INLINE bool getUseAutoGears() const
Get the flag status that is used to select auto-gears.
Definition PxVehicleDrive.h:258
void setGearDown(const bool digitalVal)
Set that the gear-down button has been pressed.
Definition PxVehicleDrive.h:221
PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
Start a gear change to a target gear.
Definition PxVehicleDrive.h:337
PX_FORCE_INLINE PxU32 getTargetGear() const
Get the target gear.
Definition PxVehicleDrive.h:323
bool mGearDownPressed
Gear-down digital control value used by vehicle simulation.
Definition PxVehicleDrive.h:434
PX_FORCE_INLINE PxReal getEngineRotationSpeed() const
Return the rotation speed of the engine (radians per second)
Definition PxVehicleDrive.h:370
PX_FORCE_INLINE void setCurrentGear(PxU32 currentGear)
Set the current gear.
Definition PxVehicleDrive.h:283
PX_FORCE_INLINE void setTargetGear(PxU32 targetGear)
Set the target gear.
Definition PxVehicleDrive.h:311
PX_FORCE_INLINE PxReal getAutoBoxSwitchTime() const
Return the time that has passed since the autobox last initiated a gear change.
Definition PxVehicleDrive.h:396
bool getGearUp() const
Check if the gear-up button has been pressed.
Definition PxVehicleDrive.h:230
PxU32 mCurrentGear
Current gear.
Definition PxVehicleDrive.h:440
PxReal mEnginespeed
Rotation speed of engine.
Definition PxVehicleDrive.h:452
Data structure describing non-wheel configuration data of a vehicle that has engine,...
Definition PxVehicleDrive.h:53
PX_FORCE_INLINE const PxVehicleAutoBoxData & getAutoBoxData() const
Return the autobox data.
Definition PxVehicleDrive.h:109
PX_FORCE_INLINE const PxVehicleClutchData & getClutchData() const
Return the clutch data.
Definition PxVehicleDrive.h:95
PX_FORCE_INLINE const PxVehicleGearsData & getGearsData() const
Return the gears data.
Definition PxVehicleDrive.h:81
PX_FORCE_INLINE const PxVehicleEngineData & getEngineData() const
Return the engine data.
Definition PxVehicleDrive.h:67
Data structure with instanced dynamics data and configuration data of a tank.
Definition PxVehicleDriveTank.h:147
A complete vehicle with instance dynamics data and configuration data for wheels and engine,...
Definition PxVehicleDrive.h:493
virtual bool isKindOf(const char *name) const
Returns whether a given type name matches with the type of this instance.
Definition PxVehicleDrive.h:551
PxVehicleDriveDynData mDriveDynData
Dynamics data of vehicle instance.
Definition PxVehicleDrive.h:508
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition PxVehicleDrive.h:547
Definition PxVehicleComponents.h:86
Definition PxVehicleComponents.h:239
Definition PxVehicleUpdate.cpp:4519
Data structure describing configuration data of a vehicle with up to 20 wheels.
Definition PxVehicleWheels.h:129
Data structure with instanced dynamics data and configuration data of a vehicle with just wheels.
Definition PxVehicleWheels.h:827
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#define PX_DEPRECATED
Definition PxPreprocessor.h:418
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxEMPTY
Definition Px.h:87