PxVehicleWheels.h
Go to the documentation of this file.
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 
14 #ifndef PX_VEHICLE_WHEELS_H
15 #define PX_VEHICLE_WHEELS_H
16 
20 #include "PxFiltering.h"
24 #include "common/PxBase.h"
25 #include "PxRigidDynamic.h"
26 
27 #ifndef PX_DOXYGEN
28 namespace physx
29 {
30 #endif
31 
32 class PxVehicleWheels4SimData;
33 class PxVehicleWheels4DynData;
34 class PxVehicleTireForceCalculator;
35 class PxShape;
36 class PxPhysics;
37 class PxMaterial;
38 
44 {
45 //= ATTENTION! =====================================================================================
46 // Changing the data layout of this class breaks the binary serialization format. See comments for
47 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
48 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
49 // accordingly.
50 //==================================================================================================
51 public:
52 
53  friend class PxVehicleWheels;
54  friend class PxVehicleNoDrive;
55  friend class PxVehicleDrive4W;
56  friend class PxVehicleDriveTank;
57  friend class PxVehicleUpdate;
58 
63  static PxVehicleWheelsSimData* allocate(const PxU32 nbWheels);
64 
78  void setChassisMass(const PxF32 chassisMass);
79 
84  void free();
85 
90  PxVehicleWheelsSimData& operator=(const PxVehicleWheelsSimData& src);
91 
98  void copy(const PxVehicleWheelsSimData& src, const PxU32 srcWheel, const PxU32 trgWheel);
99 
104  PxU32 getNbWheels() const {return mNbActiveWheels;}
105 
109  const PxVehicleSuspensionData& getSuspensionData(const PxU32 id) const;
110 
114  const PxVehicleWheelData& getWheelData(const PxU32 id) const;
115 
119  const PxVehicleTireData& getTireData(const PxU32 id) const;
120 
124  const PxVec3& getSuspTravelDirection(const PxU32 id) const;
125 
130  const PxVec3& getSuspForceAppPointOffset(const PxU32 id) const;
131 
136  const PxVec3& getTireForceAppPointOffset(const PxU32 id) const;
137 
141  const PxVec3& getWheelCentreOffset(const PxU32 id) const;
142 
152  PxI32 getWheelShapeMapping(const PxU32 wheelId) const;
153 
157  const PxFilterData& getSceneQueryFilterData(const PxU32 suspId) const;
158 
162  PX_FORCE_INLINE const PxVehicleTireLoadFilterData& getTireLoadFilterData() const
163  {
164  return mNormalisedLoadFilter;
165  }
166 
172  void setSuspensionData(const PxU32 id, const PxVehicleSuspensionData& susp);
173 
179  void setWheelData(const PxU32 id, const PxVehicleWheelData& wheel);
180 
186  void setTireData(const PxU32 id, const PxVehicleTireData& tire);
187 
193  void setSuspTravelDirection(const PxU32 id, const PxVec3& dir);
194 
201  void setSuspForceAppPointOffset(const PxU32 id, const PxVec3& offset);
202 
209  void setTireForceAppPointOffset(const PxU32 id, const PxVec3& offset);
210 
217  void setWheelCentreOffset(const PxU32 id, const PxVec3& offset);
218 
239  void setWheelShapeMapping(const PxU32 wheelId, const PxI32 shapeId);
240 
248  void setSceneQueryFilterData(const PxU32 suspId, const PxFilterData& sqFilterData);
249 
254  void setTireLoadFilterData(const PxVehicleTireLoadFilterData& tireLoadFilter);
255 
284  void disableWheel(const PxU32 wheel);
285 
292  void enableWheel(const PxU32 wheel);
293 
298  bool getIsWheelDisabled(const PxU32 wheel) const;
299 
330  void setSubStepCount(const PxReal thresholdLongitudinalSpeed, const PxU32 lowForwardSpeedSubStepCount, const PxU32 highForwardSpeedSubStepCount);
331 
349  void setMinLongSlipDenominator(const PxReal minLongSlipDenominator);
350 
351 private:
352 
358 
362  PxVehicleWheels4SimData* mWheels4SimData;
363 
368 
373 
378  PxU32 mActiveWheelsBitmapBuffer[((PX_MAX_NB_WHEELS + 31) & ~31) >> 5];
379 
386 
392 
398 
403 
404 #if defined(PX_P64)
405  PxU32 mPad[3];
406 #endif
407 
408 
412  bool isValid() const;
413 
414 
415 //serialization
416 public:
417  PxVehicleWheelsSimData(const PxEMPTY&) : mNormalisedLoadFilter(PxEmpty) {}
418  static void getBinaryMetaData(PxOutputStream& stream);
419  PxU32 getNbWheels4() const { return mNbWheels4; }
420  PxU32 getNbSuspensionData() const { return mNbActiveWheels; }
421  PxU32 getNbWheelData() const { return mNbActiveWheels; }
422  PxU32 getNbSuspTravelDirection() const { return mNbActiveWheels; }
423  PxU32 getNbTireData() const { return mNbActiveWheels; }
424  PxU32 getNbSuspForceAppPointOffset() const { return mNbActiveWheels; }
425  PxU32 getNbTireForceAppPointOffset() const { return mNbActiveWheels; }
426  PxU32 getNbWheelCentreOffset() const { return mNbActiveWheels; }
427  PxU32 getNbWheelShapeMapping() const { return mNbActiveWheels; }
428  PxU32 getNbSceneQueryFilterData() const { return mNbActiveWheels; }
429  PxF32 getMinLongSlipDenominator() const {return mMinLongSlipDenominator;}
430  void setThresholdLongSpeed(const PxF32 f) {mThresholdLongitudinalSpeed = f;}
431  PxF32 getThresholdLongSpeed() const {return mThresholdLongitudinalSpeed;}
432  void setLowForwardSpeedSubStepCount(const PxU32 f) {mLowForwardSpeedSubStepCount = f;}
433  PxU32 getLowForwardSpeedSubStepCount() const {return mLowForwardSpeedSubStepCount;}
434  void setHighForwardSpeedSubStepCount(const PxU32 f) {mHighForwardSpeedSubStepCount = f;}
435  PxU32 getHighForwardSpeedSubStepCount() const {return mHighForwardSpeedSubStepCount;}
436  void setWheelEnabledState(const PxU32 wheel, const bool state) {if(state) {enableWheel(wheel);} else {disableWheel(wheel);}}
437  bool getWheelEnabledState(const PxU32 wheel) const {return !getIsWheelDisabled(wheel);}
438  PxU32 getNbWheelEnabledState() const {return mNbActiveWheels;}
441 //~serialization
442 };
444 
449 {
450 //= ATTENTION! =====================================================================================
451 // Changing the data layout of this class breaks the binary serialization format. See comments for
452 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
453 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
454 // accordingly.
455 //==================================================================================================
456 public:
457 
458  friend class PxVehicleWheels;
459  friend class PxVehicleDrive4W;
460  friend class PxVehicleDriveTank;
461  friend class PxVehicleUpdate;
462 
465 
470  void setToRestState();
471 
476  void setTireForceShaderFunction(PxVehicleComputeTireForce tireForceShaderFn);
477 
483  void setTireForceShaderData(const PxU32 tireId, const void* tireForceShaderData);
484 
488  const void* getTireForceShaderData(const PxU32 tireId) const;
489 
495  void setWheelRotationSpeed(const PxU32 wheelIdx, const PxReal speed);
496 
500  PxReal getWheelRotationSpeed(const PxU32 wheelIdx) const;
501 
507  void setWheelRotationAngle(const PxU32 wheelIdx, const PxReal angle);
508 
512  PxReal getWheelRotationAngle(const PxU32 wheelIdx) const;
513 
520  void setUserData(const PxU32 tireIdx, void* userData);
521 
525  void* getUserData(const PxU32 tireIdx) const;
526 
533  void copy(const PxVehicleWheelsDynData& src, const PxU32 srcWheel, const PxU32 trgWheel);
534 
535 private:
536 
540  PxVehicleWheels4DynData* mWheels4DynData;
541 
545  bool isValid() const;
546 
550  PxVehicleTireForceCalculator* mTireForceCalculators;
551 
556  void** mUserDatas;
557 
562 
567 
568  PxU32 mPad[3];
569 
570 
571 //serialization
572 public:
573  static void getBinaryMetaData(PxOutputStream& stream);
574  PxU32 getNbWheelRotationSpeed() const { return mNbActiveWheels; }
575  PxU32 getNbWheelRotationAngle() const { return mNbActiveWheels; }
576  PxVehicleWheels4DynData* getWheel4DynData() const { return mWheels4DynData; }
577 //~serialization
578 };
580 
585 class PxVehicleWheels : public PxBase
586 {
587 //= ATTENTION! =====================================================================================
588 // Changing the data layout of this class breaks the binary serialization format. See comments for
589 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
590 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
591 // accordingly.
592 //==================================================================================================
593 public:
594 
595  friend class PxVehicleUpdate;
596  friend class PxVehicleConstraintShader;
597 
602  PX_FORCE_INLINE PxU32 getVehicleType() const {return mType;}
603 
608 
612  PX_FORCE_INLINE const PxRigidDynamic* getRigidDynamicActor() const {return mActor;}
613 
618  PxReal computeForwardSpeed() const;
619 
624  PxReal computeSidewaysSpeed() const;
625 
630 
635 
636 protected:
637 
641  void setToRestState();
642 
646  bool isValid() const;
647 
651  static PxU32 computeByteSize(const PxU32 nbWheels4);
652 
656  static PxU8* patchupPointers(PxVehicleWheels* veh, PxU8* ptr, const PxU32 nbWheels4, const PxU32 nbWheels, bool renew = true);
657 
662  void free();
663 
667  void setup
668  (PxPhysics* physics, PxRigidDynamic* vehActor,
669  const PxVehicleWheelsSimData& wheelsData,
670  const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
671 
676 
677 private:
678 
684 
686 
687 protected:
688 
693 
694 #if defined(PX_P64)
695  PxU8 mPad[14];
696 #else
697  PxU8 mPad[14];
698 #endif
699 
700 //serialization
701 public:
702  virtual void requires(PxProcessPxBaseCallback& c);
703  virtual const char* getConcreteTypeName() const { return "PxVehicleWheels"; }
704  virtual bool isKindOf(const char* name) const { return !strcmp("PxVehicleWheels", name) || PxBase::isKindOf(name); }
705  virtual void exportExtraData(PxSerializationContext&);
706  void importExtraData(PxDeserializationContext&);
707  void resolveReferences(PxDeserializationContext&);
708  static void getBinaryMetaData(PxOutputStream& stream);
709  PX_FORCE_INLINE PxU32 getNbNonDrivenWheels() const { return mNbNonDrivenWheels; }
710  PxVehicleWheels(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
711  PxVehicleWheels(PxBaseFlags baseFlags) : PxBase(baseFlags), mWheelsSimData(PxEmpty) {}
712  virtual ~PxVehicleWheels() {}
713  virtual void release() { free(); }
714 //~serialization
715 };
716 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheels) & 15));
717 
718 #ifndef PX_DOXYGEN
719 } // namespace physx
720 #endif
721 
723 #endif //PX_VEHICLE_WHEELS_H


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com