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-2018 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;
47 class PxBatchQuery;
49 class PxShape;
50 class PxMaterial;
51 class PxRigidDynamic;
52 
58 {
59 //= ATTENTION! =====================================================================================
60 // Changing the data layout of this class breaks the binary serialization format. See comments for
61 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
62 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
63 // accordingly.
64 //==================================================================================================
65 public:
66 
67  friend class PxVehicleDriveTank;
68 
73  {
74  return mEngine;
75  }
76 
81  void setEngineData(const PxVehicleEngineData& engine);
82 
87  {
88  return mGears;
89  }
90 
95  void setGearsData(const PxVehicleGearsData& gears);
96 
101  {
102  return mClutch;
103  }
104 
109  void setClutchData(const PxVehicleClutchData& clutch);
110 
115  {
116  return mAutoBox;
117  }
118 
123  void setAutoBoxData(const PxVehicleAutoBoxData& autobox);
124 
125 protected:
126  /*
127  \brief Engine simulation data
128  @see setEngineData, getEngineData
129  */
131 
132  /*
133  \brief Gear simulation data
134  @see setGearsData, getGearsData
135  */
137 
138  /*
139  \brief Clutch simulation data
140  @see setClutchData, getClutchData
141  */
143 
144  /*
145  \brief Autobox simulation data
146  @see setAutoboxData, getAutoboxData
147  */
149 
155  bool isValid() const;
156 
157 
158 //serialization
159 public:
161  PxVehicleDriveSimData(const PxEMPTY) : mEngine(PxEmpty), mGears(PxEmpty), mClutch(PxEmpty), mAutoBox(PxEmpty) {}
162  static void getBinaryMetaData(PxOutputStream& stream);
163 //~serialization
164 };
166 
167 
173 {
174 public:
175 
176  enum
177  {
178  eMAX_NB_ANALOG_INPUTS=16
179  };
180 
181  friend class PxVehicleDrive;
182 
186  void setToRestState();
187 
194  void setAnalogInput(const PxU32 type, const PxReal analogVal);
195 
201  PxReal getAnalogInput(const PxU32 type) const;
202 
212  void setGearUp(const bool digitalVal)
213  {
214  mGearUpPressed = digitalVal;
215  }
216 
226  void setGearDown(const bool digitalVal)
227  {
228  mGearDownPressed = digitalVal;
229  }
230 
235  bool getGearUp() const
236  {
237  return mGearUpPressed;
238  }
239 
244  bool getGearDown() const
245  {
246  return mGearDownPressed;
247  }
248 
254  PX_FORCE_INLINE void setUseAutoGears(const bool useAutoGears)
255  {
256  mUseAutoGears=useAutoGears;
257  }
258 
264  {
265  return mUseAutoGears;
266  }
267 
273  {
274  mUseAutoGears = !mUseAutoGears;
275  }
276 
289  {
290  mCurrentGear = currentGear;
291  }
292 
301  {
302  return mCurrentGear;
303  }
304 
317  {
318  mTargetGear = targetGear;
319  }
320 
329  {
330  return mTargetGear;
331  }
332 
342  PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
343  {
344  mTargetGear=targetGear;
345  }
346 
354  PX_FORCE_INLINE void forceGearChange(const PxU32 targetGear)
355  {
356  mTargetGear=targetGear;
357  mCurrentGear=targetGear;
358  }
359 
366  {
367  mEnginespeed = speed;
368  }
369 
376  {
377  return mEnginespeed;
378  }
379 
390  {
391  return mGearSwitchTime;
392  }
393 
402  {
403  return mAutoBoxSwitchTime;
404  }
405 
415  PxReal mControlAnalogVals[eMAX_NB_ANALOG_INPUTS];
416 
422 
431 
440 
446 
452 
458 
464 
470 
471 private:
472  PxU32 mPad[2];
473 
478  bool isValid() const;
479 
480 //serialization
481 public:
484  PxU32 getNbAnalogInput() const { return eMAX_NB_ANALOG_INPUTS; }
485  PX_FORCE_INLINE void setGearChange(const PxU32 gearChange) { mTargetGear= gearChange; }
486  PX_FORCE_INLINE PxU32 getGearChange() const { return mTargetGear; }
487  PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime) { mGearSwitchTime = switchTime; }
488  PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime) { mAutoBoxSwitchTime = autoBoxSwitchTime; }
489 //~serialization
490 };
492 
498 {
499 //= ATTENTION! =====================================================================================
500 // Changing the data layout of this class breaks the binary serialization format. See comments for
501 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
502 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
503 // accordingly.
504 //==================================================================================================
505 public:
506 
507  friend class PxVehicleUpdate;
508 
514 
515 protected:
516 
520  bool isValid() const;
521 
525  void setToRestState();
526 
530  static PxU32 computeByteSize(const PxU32 numWheels);
531  static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleDrive* vehDrive, PxU8* ptr);
532  virtual void init(const PxU32 numWheels);
533 
538  void free();
539 
543  void setup
544  (PxPhysics* physics, PxRigidDynamic* vehActor,
545  const PxVehicleWheelsSimData& wheelsData,
546  const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
547 
548 //serialization
549 public:
550  static void getBinaryMetaData(PxOutputStream& stream);
551  PxVehicleDrive(PxBaseFlags baseFlags) : PxVehicleWheels(baseFlags), mDriveDynData(PxEmpty) {}
552  virtual const char* getConcreteTypeName() const { return "PxVehicleDrive"; }
553 protected:
554  PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags) : PxVehicleWheels(concreteType, baseFlags) {}
556  virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleDrive", name) || PxBase::isKindOf(name); }
557 //~serialization
558 };
559 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleDrive) & 15));
560 
561 #if !PX_DOXYGEN
562 } // namespace physx
563 #endif
564 
566 #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:421
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:375
static void getBinaryMetaData(PxOutputStream &stream)
PX_FORCE_INLINE PxU32 getCurrentGear() const
Get the current gear.
Definition: PxVehicleDrive.h:300
PxVehicleGearsData mGears
Definition: PxVehicleDrive.h:136
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:486
Abstract class for collision shapes.
Definition: PxShape.h:142
Definition: PxVehicleComponents.h:664
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:364
Batched queries object. This is used to perform several queries at the same time. ...
Definition: PxBatchQuery.h:57
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:445
PxReal mGearSwitchTime
Reported time that has passed since gear change started.
Definition: PxVehicleDrive.h:463
void setGearUp(const bool digitalVal)
Inform the vehicle that the gear-up button has been pressed.
Definition: PxVehicleDrive.h:212
Data structure with instanced dynamics data for vehicle with engine, clutch, gears, autobox.
Definition: PxVehicleDrive.h:172
bool mGearUpPressed
Gear-up digital control value used by vehicle simulation.
Definition: PxVehicleDrive.h:430
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:401
bool getGearDown() const
Check if the gear-down button has been pressed.
Definition: PxVehicleDrive.h:244
PxU16 PxType
Definition: PxBase.h:49
PX_FORCE_INLINE void setGearSwitchTime(const PxReal switchTime)
Definition: PxVehicleDrive.h:487
PxReal mEnginespeed
Rotation speed of engine.
Definition: PxVehicleDrive.h:457
PxVehicleDriveDynData mDriveDynData
Dynamics data of vehicle instance.
Definition: PxVehicleDrive.h:513
Output stream class for I/O.
Definition: PxIO.h:114
PX_FORCE_INLINE const PxVehicleEngineData & getEngineData() const
Return the engine data.
Definition: PxVehicleDrive.h:72
PX_FORCE_INLINE void setTargetGear(PxU32 targetGear)
Set the target gear.
Definition: PxVehicleDrive.h:316
Data structure describing non-wheel configuration data of a vehicle that has engine, gears, clutch, and auto-box.
Definition: PxVehicleDrive.h:57
PX_FORCE_INLINE void setAutoBoxSwitchTime(const PxReal autoBoxSwitchTime)
Definition: PxVehicleDrive.h:488
PX_FORCE_INLINE void setGearChange(const PxU32 gearChange)
Definition: PxVehicleDrive.h:485
virtual bool isKindOf(const char *name) const
Returns whether a given type name matches with the type of this instance.
Definition: PxVehicleDrive.h:556
PX_FORCE_INLINE void toggleAutoGears()
Toggle the auto-gears flag If useAutoGears is true the auto-box will be active.
Definition: PxVehicleDrive.h:272
PX_FORCE_INLINE const PxVehicleAutoBoxData & getAutoBoxData() const
Return the autobox data.
Definition: PxVehicleDrive.h:114
Data structure describing configuration data of a vehicle with up to 20 wheels.
Definition: PxVehicleWheels.h:59
Definition: PxVehicleComponents.h:89
PX_FORCE_INLINE const PxVehicleClutchData & getClutchData() const
Return the clutch data.
Definition: PxVehicleDrive.h:100
A complete vehicle with instance dynamics data and configuration data for wheels and engine...
Definition: PxVehicleDrive.h:497
PX_FORCE_INLINE const PxVehicleGearsData & getGearsData() const
Return the gears data.
Definition: PxVehicleDrive.h:86
PX_FORCE_INLINE void startGearChange(const PxU32 targetGear)
Start a gear change to a target gear.
Definition: PxVehicleDrive.h:342
PxVehicleDriveSimData()
Definition: PxVehicleDrive.h:160
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:148
PxU32 getNbAnalogInput() const
Definition: PxVehicleDrive.h:484
void setGearDown(const bool digitalVal)
Set that the gear-down button has been pressed.
Definition: PxVehicleDrive.h:226
PxVehicleDriveDynData(const PxEMPTY)
Definition: PxVehicleDrive.h:483
PX_FORCE_INLINE void setCurrentGear(PxU32 currentGear)
Set the current gear.
Definition: PxVehicleDrive.h:288
PxVehicleClutchData mClutch
Definition: PxVehicleDrive.h:142
PX_FORCE_INLINE PxU32 getTargetGear() const
Get the target gear.
Definition: PxVehicleDrive.h:328
#define PX_COMPILE_TIME_ASSERT(exp)
Definition: PxPreprocessor.h:447
PX_FORCE_INLINE bool getUseAutoGears() const
Get the flag status that is used to select auto-gears.
Definition: PxVehicleDrive.h:263
PxReal mAutoBoxSwitchTime
Reported time that has passed since last autobox gearup/geardown decision.
Definition: PxVehicleDrive.h:469
PX_FORCE_INLINE void setEngineRotationSpeed(const PxF32 speed)
Set the rotation speed of the engine (radians per second)
Definition: PxVehicleDrive.h:365
PxU32 mTargetGear
Target gear (different from current gear if a gear change is underway)
Definition: PxVehicleDrive.h:451
Data structure with instanced dynamics data and configuration data of a vehicle with just wheels...
Definition: PxVehicleWheels.h:676
PxEMPTY
Definition: Px.h:70
Definition: PxVehicleComponents.h:347
Material class to represent a set of surface properties.
Definition: PxMaterial.h:130
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:354
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:235
Definition: PxVehicleComponents.h:242
~PxVehicleDrive()
Definition: PxVehicleDrive.h:555
PxVehicleDrive(PxType concreteType, PxBaseFlags baseFlags)
Definition: PxVehicleDrive.h:554
bool mGearDownPressed
Gear-down digital control value used by vehicle simulation.
Definition: PxVehicleDrive.h:439
uint32_t PxU32
Definition: Px.h:48
Data structure with instanced dynamics data and configuration data of a tank.
Definition: PxVehicleDriveTank.h:151
PX_FORCE_INLINE PxReal getGearSwitchTime() const
Return the time that has passed since the current gear change was initiated.
Definition: PxVehicleDrive.h:389
PxVehicleDriveSimData(const PxEMPTY)
Definition: PxVehicleDrive.h:161
PxVehicleEngineData mEngine
Definition: PxVehicleDrive.h:130
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition: PxVehicleDrive.h:552
PxVehicleDrive(PxBaseFlags baseFlags)
Definition: PxVehicleDrive.h:551
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:254
Definition: Px.h:72