PxVehicleDrive.h
Go to the documentation of this file.
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_H
31 #define PX_VEHICLE_DRIVE_H
32 
38 
39 #if !PX_DOXYGEN
40 namespace physx
41 {
42 #endif
43 
44 struct PxFilterData;
45 class PxGeometry;
46 class PxPhysics;
48 class PxShape;
49 class PxMaterial;
50 class PxRigidDynamic;
51 
57 {
58 //= ATTENTION! =====================================================================================
59 // Changing the data layout of this class breaks the binary serialization format. See comments for
60 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
61 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
62 // accordingly.
63 //==================================================================================================
64 public:
65 
66  friend class PxVehicleDriveTank;
67 
72  {
73  return mEngine;
74  }
75 
80  void setEngineData(const PxVehicleEngineData& engine);
81 
86  {
87  return mGears;
88  }
89 
94  void setGearsData(const PxVehicleGearsData& gears);
95 
100  {
101  return mClutch;
102  }
103 
108  void setClutchData(const PxVehicleClutchData& clutch);
109 
114  {
115  return mAutoBox;
116  }
117 
122  void setAutoBoxData(const PxVehicleAutoBoxData& autobox);
123 
124 protected:
125  /*
126  \brief Engine simulation data
127  @see setEngineData, getEngineData
128  */
130 
131  /*
132  \brief Gear simulation data
133  @see setGearsData, getGearsData
134  */
136 
137  /*
138  \brief Clutch simulation data
139  @see setClutchData, getClutchData
140  */
142 
143  /*
144  \brief Autobox simulation data
145  @see setAutoboxData, getAutoboxData
146  */
148 
154  bool isValid() const;
155 
156 
157 //serialization
158 public:
160  PxVehicleDriveSimData(const PxEMPTY) : mEngine(PxEmpty), mGears(PxEmpty), mClutch(PxEmpty), mAutoBox(PxEmpty) {}
161  static void getBinaryMetaData(PxOutputStream& stream);
162 //~serialization
163 };
165 
166 
172 {
173 public:
174 
175  enum
176  {
177  eMAX_NB_ANALOG_INPUTS=16
178  };
179 
180  friend class PxVehicleDrive;
181 
185  void setToRestState();
186 
193  void setAnalogInput(const PxU32 type, const PxReal analogVal);
194 
200  PxReal getAnalogInput(const PxU32 type) const;
201 
211  void setGearUp(const bool digitalVal)
212  {
213  mGearUpPressed = digitalVal;
214  }
215 
225  void setGearDown(const bool digitalVal)
226  {
227  mGearDownPressed = digitalVal;
228  }
229 
234  bool getGearUp() const
235  {
236  return mGearUpPressed;
237  }
238 
243  bool getGearDown() const
244  {
245  return mGearDownPressed;
246  }
247 
253  PX_FORCE_INLINE void setUseAutoGears(const bool useAutoGears)
254  {
255  mUseAutoGears=useAutoGears;
256  }
257 
263  {
264  return mUseAutoGears;
265  }
266 
272  {
273  mUseAutoGears = !mUseAutoGears;
274  }
275 
288  {
289  mCurrentGear = currentGear;
290  }
291 
300  {
301  return mCurrentGear;
302  }
303 
316  {
317  mTargetGear = targetGear;
318  }
319 
328  {
329  return mTargetGear;
330  }
331 
341  PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
342  {
343  mTargetGear=targetGear;
344  }
345 
353  PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
354  {
355  mTargetGear=targetGear;
356  mCurrentGear=targetGear;
357  }
358 
365  {
366  mEnginespeed = speed;
367  }
368 
375  {
376  return mEnginespeed;
377  }
378 
389  {
390  return mGearSwitchTime;
391  }
392 
401  {
402  return mAutoBoxSwitchTime;
403  }
404 
414  PxReal mControlAnalogVals[eMAX_NB_ANALOG_INPUTS];
415 
421 
430 
439 
445 
451 
457 
463 
469 
470 private:
471  PxU32 mPad[2];
472 
477  bool isValid() const;
478 
479 //serialization
480 public:
483  PxU32 getNbAnalogInput() const { return eMAX_NB_ANALOG_INPUTS; }
484  PX_FORCE_INLINE void setGearChange(const PxU32 gearChange) { mTargetGear= gearChange; }
485  PX_FORCE_INLINE PxU32 getGearChange() const { return mTargetGear; }
486  PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime) { mGearSwitchTime = switchTime; }
487  PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime) { mAutoBoxSwitchTime = autoBoxSwitchTime; }
488 //~serialization
489 };
491 
497 {
498 //= ATTENTION! =====================================================================================
499 // Changing the data layout of this class breaks the binary serialization format. See comments for
500 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
501 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
502 // accordingly.
503 //==================================================================================================
504 public:
505 
506  friend class PxVehicleUpdate;
507 
513 
514 protected:
515 
519  bool isValid() const;
520 
524  void setToRestState();
525 
529  static PxU32 computeByteSize(const PxU32 numWheels);
530  static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleDrive* vehDrive, PxU8* ptr);
531  virtual void init(const PxU32 numWheels);
532 
537  void free();
538 
542  void setup
543  (PxPhysics* physics, PxRigidDynamic* vehActor,
544  const PxVehicleWheelsSimData& wheelsData,
545  const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
546 
547 //serialization
548 public:
549  static void getBinaryMetaData(PxOutputStream& stream);
550  PxVehicleDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags), mDriveDynData(PxEmpty) {}
551  virtual const char* getConcreteTypeName() const { return "PxVehicleDrive"; }
552 protected:
553  PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags) : PxVehicleWheels(concreteType, baseFlags) {}
555  virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDrive", name) || PxBase::isKindOf(name); }
556 //~serialization
557 };
558 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive) & 15));
559 
560 #if !PX_DOXYGEN
561 } // namespace physx
562 #endif
563 
565 #endif //PX_VEHICLE_DRIVE_H
Definition: GuContactBuffer.h:37
bool mUseAutoGears
Auto-gear flag used by vehicle simulation. Set true to enable the autobox, false to disable the autob...
Definition: PxVehicleDrive.h:420
Friction for each combination of driving surface type and tire type.
Definition: PxVehicleTireFriction.h:62
PX_FORCE_INLINE PxReal getEngineRotationSpeed() const
Return the rotation speed of the engine (radians per second)
Definition: PxVehicleDrive.h:374
static void getBinaryMetaData(PxOutputStream &stream)
PX_FORCE_INLINE PxU32 getCurrentGear() const
Get the current gear.
Definition: PxVehicleDrive.h:299
PxVehicleGearsData mGears
Definition: PxVehicleDrive.h:135
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition: PxRigidDynamic.h:83
float PxF32
Definition: PxSimpleTypes.h:76
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition: PxFiltering.h:366
PX_FORCE_INLINE PxU32 getGearChange() const
Definition: PxVehicleDrive.h:485
Abstract class for collision shapes.
Definition: PxShape.h:142
Definition: PxVehicleComponents.h:664
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
float PxReal
Definition: PxSimpleTypes.h:78
virtual bool isKindOf(const char *superClass) const
Returns whether a given type name matches with the type of this instance.
Definition: PxBase.h:178
void setToRestState()
Set vehicle to rest.
PxU32 mCurrentGear
Current gear.
Definition: PxVehicleDrive.h:444
PxReal mGearSwitchTime
Reported time that has passed since gear change started.
Definition: PxVehicleDrive.h:462
void setGearUp(const bool digitalVal)
Inform the vehicle that the gear-up button has been pressed.
Definition: PxVehicleDrive.h:211
Data structure with instanced dynamics data for vehicle with engine, clutch, gears, autobox.
Definition: PxVehicleDrive.h:171
bool mGearUpPressed
Gear-up digital control value used by vehicle simulation.
Definition: PxVehicleDrive.h:429
A geometry object.
Definition: PxGeometry.h:75
PX_FORCE_INLINE PxReal getAutoBoxSwitchTime() const
Return the time that has passed since the autobox last initiated a gear change.
Definition: PxVehicleDrive.h:400
bool getGearDown() const
Check if the gear-down button has been pressed.
Definition: PxVehicleDrive.h:243
PxU16 PxType
Definition: PxBase.h:49
PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime)
Definition: PxVehicleDrive.h:486
PxReal mEnginespeed
Rotation speed of engine.
Definition: PxVehicleDrive.h:456
PxVehicleDriveDynData mDriveDynData
Dynamics data of vehicle instance.
Definition: PxVehicleDrive.h:512
Output stream class for I/O.
Definition: PxIO.h:114
PX_FORCE_INLINE const PxVehicleEngineData & getEngineData() const
Return the engine data.
Definition: PxVehicleDrive.h:71
PX_FORCE_INLINE void setTargetGear(PxU32 targetGear)
Set the target gear.
Definition: PxVehicleDrive.h:315
Data structure describing non-wheel configuration data of a vehicle that has engine, gears, clutch, and auto-box.
Definition: PxVehicleDrive.h:56
PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime)
Definition: PxVehicleDrive.h:487
PX_FORCE_INLINE void setGearChange(const PxU32 gearChange)
Definition: PxVehicleDrive.h:484
virtual bool isKindOf(const char *name) const
Returns whether a given type name matches with the type of this instance.
Definition: PxVehicleDrive.h:555
PX_FORCE_INLINE void toggleAutoGears()
Toggle the auto-gears flag If useAutoGears is true the auto-box will be active.
Definition: PxVehicleDrive.h:271
PX_FORCE_INLINE const PxVehicleAutoBoxData & getAutoBoxData() const
Return the autobox data.
Definition: PxVehicleDrive.h:113
Data structure describing configuration data of a vehicle with up to 20 wheels.
Definition: PxVehicleWheels.h:123
Definition: PxVehicleComponents.h:89
PX_FORCE_INLINE const PxVehicleClutchData & getClutchData() const
Return the clutch data.
Definition: PxVehicleDrive.h:99
A complete vehicle with instance dynamics data and configuration data for wheels and engine...
Definition: PxVehicleDrive.h:496
PX_FORCE_INLINE const PxVehicleGearsData & getGearsData() const
Return the gears data.
Definition: PxVehicleDrive.h:85
PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
Start a gear change to a target gear.
Definition: PxVehicleDrive.h:341
PxVehicleDriveSimData()
Definition: PxVehicleDrive.h:159
uint8_t PxU8
Definition: PxSimpleTypes.h:75
bool isValid() const
Test that all instanced dynamics data and configuration data have legal values.
PxVehicleAutoBoxData mAutoBox
Definition: PxVehicleDrive.h:147
PxU32 getNbAnalogInput() const
Definition: PxVehicleDrive.h:483
void setGearDown(const bool digitalVal)
Set that the gear-down button has been pressed.
Definition: PxVehicleDrive.h:225
PxVehicleDriveDynData(const PxEMPTY)
Definition: PxVehicleDrive.h:482
PX_FORCE_INLINE void setCurrentGear(PxU32 currentGear)
Set the current gear.
Definition: PxVehicleDrive.h:287
PxVehicleClutchData mClutch
Definition: PxVehicleDrive.h:141
PX_FORCE_INLINE PxU32 getTargetGear() const
Get the target gear.
Definition: PxVehicleDrive.h:327
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:434
PX_FORCE_INLINE bool getUseAutoGears() const
Get the flag status that is used to select auto-gears.
Definition: PxVehicleDrive.h:262
PxReal mAutoBoxSwitchTime
Reported time that has passed since last autobox gearup/geardown decision.
Definition: PxVehicleDrive.h:468
PX_FORCE_INLINE void setEngineRotationSpeed(const PxF32 speed)
Set the rotation speed of the engine (radians per second)
Definition: PxVehicleDrive.h:364
PxU32 mTargetGear
Target gear (different from current gear if a gear change is underway)
Definition: PxVehicleDrive.h:450
Data structure with instanced dynamics data and configuration data of a vehicle with just wheels...
Definition: PxVehicleWheels.h:790
PxEMPTY
Definition: Px.h:70
Definition: PxVehicleComponents.h:347
Material class to represent a set of surface properties.
Definition: PxMaterial.h:143
bool isValid() const
Test if the instanced dynamics and configuration data has legal values.
PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
Force an immediate gear change to a target gear.
Definition: PxVehicleDrive.h:353
Abstract singleton factory class used for instancing objects in the Physics SDK.
Definition: PxPhysics.h:71
bool getGearUp() const
Check if the gear-up button has been pressed.
Definition: PxVehicleDrive.h:234
Definition: PxVehicleComponents.h:242
~PxVehicleDrive()
Definition: PxVehicleDrive.h:554
PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags)
Definition: PxVehicleDrive.h:553
bool mGearDownPressed
Gear-down digital control value used by vehicle simulation.
Definition: PxVehicleDrive.h:438
uint32_t PxU32
Definition: Px.h:48
Data structure with instanced dynamics data and configuration data of a tank.
Definition: PxVehicleDriveTank.h:150
PX_FORCE_INLINE PxReal getGearSwitchTime() const
Return the time that has passed since the current gear change was initiated.
Definition: PxVehicleDrive.h:388
PxVehicleDriveSimData(const PxEMPTY)
Definition: PxVehicleDrive.h:160
PxVehicleEngineData mEngine
Definition: PxVehicleDrive.h:129
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition: PxVehicleDrive.h:551
PxVehicleDrive(PxBaseFlags baseFlags)
Definition: PxVehicleDrive.h:550
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:253
Definition: Px.h:72