RavEngine
Loading...
Searching...
No Matches
PxVehicleWheels.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_WHEELS_H
30#define PX_VEHICLE_WHEELS_H
31
32#include "foundation/PxSimpleTypes.h"
33#include "vehicle/PxVehicleShaders.h"
34#include "vehicle/PxVehicleComponents.h"
35#include "common/PxBase.h"
36#include "PxRigidDynamic.h"
37
38#if !PX_DOXYGEN
39namespace physx
40{
41#endif
42
43class PxVehicleWheels4SimData;
44class PxVehicleWheels4DynData;
45class PxVehicleTireForceCalculator;
46class PxShape;
47class PxPhysics;
48class PxMaterial;
49
56{
57 enum Enum
58 {
70 eLIMIT_SUSPENSION_EXPANSION_VELOCITY = (1 << 0),
71
83 eDISABLE_INTERNAL_CYLINDER_PLANE_INTERSECTION_TEST = (1 << 1),
84
102 eDISABLE_SUSPENSION_FORCE_PROJECTION = (1 << 2),
103
112 eDISABLE_SPRUNG_MASS_SUM_CHECK = (1 << 3)
113 };
114};
115
122PX_FLAGS_OPERATORS(PxVehicleWheelsSimFlag::Enum, PxU32)
123
124
129{
130//= ATTENTION! =====================================================================================
131// Changing the data layout of this class breaks the binary serialization format. See comments for
132// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
133// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
134// accordingly.
135//==================================================================================================
136public:
137
138 friend class PxVehicleWheels;
139 friend class PxVehicleNoDrive;
140 friend class PxVehicleDrive4W;
141 friend class PxVehicleDriveTank;
142 friend class PxVehicleUpdate;
143
148 static PxVehicleWheelsSimData* allocate(const PxU32 nbWheels);
149
163 void setChassisMass(const PxF32 chassisMass);
164
169 void free();
170
175 PxVehicleWheelsSimData& operator=(const PxVehicleWheelsSimData& src);
176
183 void copy(const PxVehicleWheelsSimData& src, const PxU32 srcWheel, const PxU32 trgWheel);
184
189 PxU32 getNbWheels() const {return mNbActiveWheels;}
190
194 const PxVehicleSuspensionData& getSuspensionData(const PxU32 id) const;
195
199 const PxVehicleWheelData& getWheelData(const PxU32 id) const;
200
204 const PxVehicleTireData& getTireData(const PxU32 id) const;
205
209 const PxVec3& getSuspTravelDirection(const PxU32 id) const;
210
215 const PxVec3& getSuspForceAppPointOffset(const PxU32 id) const;
216
221 const PxVec3& getTireForceAppPointOffset(const PxU32 id) const;
222
226 const PxVec3& getWheelCentreOffset(const PxU32 id) const;
227
237 PxI32 getWheelShapeMapping(const PxU32 wheelId) const;
238
242 const PxFilterData& getSceneQueryFilterData(const PxU32 suspId) const;
243
248 PxU32 getNbAntiRollBars() const
249 {
250 return mNbActiveAntiRollBars;
251 }
252
261 const PxVehicleAntiRollBarData& getAntiRollBarData(const PxU32 antiRollId) const;
262
267 {
268 return mNormalisedLoadFilter;
269 }
270
276 void setSuspensionData(const PxU32 id, const PxVehicleSuspensionData& susp);
277
283 void setWheelData(const PxU32 id, const PxVehicleWheelData& wheel);
284
290 void setTireData(const PxU32 id, const PxVehicleTireData& tire);
291
297 void setSuspTravelDirection(const PxU32 id, const PxVec3& dir);
298
305 void setSuspForceAppPointOffset(const PxU32 id, const PxVec3& offset);
306
313 void setTireForceAppPointOffset(const PxU32 id, const PxVec3& offset);
314
321 void setWheelCentreOffset(const PxU32 id, const PxVec3& offset);
322
343 void setWheelShapeMapping(const PxU32 wheelId, const PxI32 shapeId);
344
352 void setSceneQueryFilterData(const PxU32 suspId, const PxFilterData& sqFilterData);
353
358 void setTireLoadFilterData(const PxVehicleTireLoadFilterData& tireLoadFilter);
359
384 PxU32 addAntiRollBarData(const PxVehicleAntiRollBarData& antiRoll);
385
414 void disableWheel(const PxU32 wheel);
415
422 void enableWheel(const PxU32 wheel);
423
428 bool getIsWheelDisabled(const PxU32 wheel) const;
429
460 void setSubStepCount(const PxReal thresholdLongitudinalSpeed, const PxU32 lowForwardSpeedSubStepCount, const PxU32 highForwardSpeedSubStepCount);
461
478 void setMinLongSlipDenominator(const PxReal minLongSlipDenominator);
479
489 void setFlags(PxVehicleWheelsSimFlags flags);
490
498 PxVehicleWheelsSimFlags getFlags() const;
499
500private:
501
506 PxVehicleTireLoadFilterData mNormalisedLoadFilter;
507
511 PxVehicleWheels4SimData* mWheels4SimData;
512
516 PxU32 mNbWheels4;
517
521 PxU32 mNbActiveWheels;
522
526 PxVehicleAntiRollBarData* mAntiRollBars;
527
531 PxU32 mNbAntiRollBars4;
532
536 PxU32 mNbActiveAntiRollBars;
537
542 PxU32 mActiveWheelsBitmapBuffer[((PX_MAX_NB_WHEELS + 31) & ~31) >> 5];
543
549 PxF32 mThresholdLongitudinalSpeed;
550
555 PxU32 mLowForwardSpeedSubStepCount;
556
561 PxU32 mHighForwardSpeedSubStepCount;
562
566 PxF32 mMinLongSlipDenominator;
567
573 PxU32 mFlags;
574
575#if PX_P64_FAMILY
576 PxU32 mPad[1];
577#endif
578
582 bool isValid() const;
583
587 static PxU32 computeByteSize(const PxU32 numWheels);
588 static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsSimData* simData, PxU8* ptrIn);
589 PxVehicleWheelsSimData(const PxU32 numWheels);
590
591//serialization
592public:
593 PxVehicleWheelsSimData(const PxEMPTY) : mNormalisedLoadFilter(PxEmpty) {}
594 static void getBinaryMetaData(PxOutputStream& stream);
595 PxU32 getNbWheels4() const { return mNbWheels4; }
596 PxU32 getNbSuspensionData() const { return mNbActiveWheels; }
597 PxU32 getNbWheelData() const { return mNbActiveWheels; }
598 PxU32 getNbSuspTravelDirection() const { return mNbActiveWheels; }
599 PxU32 getNbTireData() const { return mNbActiveWheels; }
600 PxU32 getNbSuspForceAppPointOffset() const { return mNbActiveWheels; }
601 PxU32 getNbTireForceAppPointOffset() const { return mNbActiveWheels; }
602 PxU32 getNbWheelCentreOffset() const { return mNbActiveWheels; }
603 PxU32 getNbWheelShapeMapping() const { return mNbActiveWheels; }
604 PxU32 getNbSceneQueryFilterData() const { return mNbActiveWheels; }
605 PxF32 getMinLongSlipDenominator() const {return mMinLongSlipDenominator;}
606 void setThresholdLongSpeed(const PxF32 f) {mThresholdLongitudinalSpeed = f;}
607 PxF32 getThresholdLongSpeed() const {return mThresholdLongitudinalSpeed;}
608 void setLowForwardSpeedSubStepCount(const PxU32 f) {mLowForwardSpeedSubStepCount = f;}
609 PxU32 getLowForwardSpeedSubStepCount() const {return mLowForwardSpeedSubStepCount;}
610 void setHighForwardSpeedSubStepCount(const PxU32 f) {mHighForwardSpeedSubStepCount = f;}
611 PxU32 getHighForwardSpeedSubStepCount() const {return mHighForwardSpeedSubStepCount;}
612 void setWheelEnabledState(const PxU32 wheel, const bool state) {if(state) {enableWheel(wheel);} else {disableWheel(wheel);}}
613 bool getWheelEnabledState(const PxU32 wheel) const {return !getIsWheelDisabled(wheel);}
614 PxU32 getNbWheelEnabledState() const {return mNbActiveWheels;}
615 PxU32 getNbAntiRollBars4() const { return mNbAntiRollBars4; }
616 PxU32 getNbAntiRollBarData() const {return mNbActiveAntiRollBars;}
617 void setAntiRollBarData(const PxU32 id, const PxVehicleAntiRollBarData& antiRoll);
618 PxVehicleWheelsSimData(){}
619 ~PxVehicleWheelsSimData(){}
620//~serialization
621};
622PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsSimData) & 15));
623
624
629{
630 enum Enum
631 {
632 eRAY = 0,
633 eCYLINDER
634 };
635};
636
641{
642//= ATTENTION! =====================================================================================
643// Changing the data layout of this class breaks the binary serialization format. See comments for
644// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
645// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
646// accordingly.
647//==================================================================================================
648public:
649
650 friend class PxVehicleWheels;
651 friend class PxVehicleDrive4W;
652 friend class PxVehicleDriveTank;
653 friend class PxVehicleUpdate;
654
657
662 void setToRestState();
663
668 void setTireForceShaderFunction(PxVehicleComputeTireForce tireForceShaderFn);
669
675 void setTireForceShaderData(const PxU32 tireId, const void* tireForceShaderData);
676
680 const void* getTireForceShaderData(const PxU32 tireId) const;
681
687 void setWheelRotationSpeed(const PxU32 wheelIdx, const PxReal speed);
688
692 PxReal getWheelRotationSpeed(const PxU32 wheelIdx) const;
693
699 void setWheelRotationAngle(const PxU32 wheelIdx, const PxReal angle);
700
704 PxReal getWheelRotationAngle(const PxU32 wheelIdx) const;
705
712 void setUserData(const PxU32 tireIdx, void* userData);
713
717 void* getUserData(const PxU32 tireIdx) const;
718
725 void copy(const PxVehicleWheelsDynData& src, const PxU32 srcWheel, const PxU32 trgWheel);
726
743 void setTireContacts(const PxU32* nbHits, const PxPlane* contactPlanes, const PxReal* contactFrictions, const PxTireContactIntersectionMethod::Enum* intersectionMethods, const PxU32 nbWheels);
744
745private:
746
750 PxVehicleWheels4DynData* mWheels4DynData;
751
755 bool isValid() const;
756
760 PxVehicleTireForceCalculator* mTireForceCalculators;
761
766 void** mUserDatas;
767
771 PxU32 mNbWheels4;
772
776 PxU32 mNbActiveWheels;
777
778 PxU32 mPad[3];
779
783 static PxU32 computeByteSize(const PxU32 numWheels);
784 static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsDynData* dynData, PxU8* ptr);
785 PxVehicleWheelsDynData(const PxU32 numWheels);
786
787//serialization
788public:
789 static void getBinaryMetaData(PxOutputStream& stream);
790 PxU32 getNbWheelRotationSpeed() const { return mNbActiveWheels; }
791 PxU32 getNbWheelRotationAngle() const { return mNbActiveWheels; }
792 PxVehicleWheels4DynData* getWheel4DynData() const { return mWheels4DynData; }
793//~serialization
794
804 PxU32 getNbConstraints() const { return mNbWheels4; }
805
818 PxU32 getConstraints(PxConstraint** userBuffer, PxU32 bufferSize, PxU32 startIndex = 0) const;
819};
820PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsDynData) & 15));
821
827{
828//= ATTENTION! =====================================================================================
829// Changing the data layout of this class breaks the binary serialization format. See comments for
830// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
831// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
832// accordingly.
833//==================================================================================================
834public:
835
836 friend class PxVehicleUpdate;
837 friend class PxVehicleConstraintShader;
838
843 PX_FORCE_INLINE PxU32 getVehicleType() const {return mType;}
844
849
854
862 PxReal computeForwardSpeed(const PxVec3& forwardAxis = PxVehicleGetDefaultContext().forwardAxis) const;
863
871 PxReal computeSidewaysSpeed(const PxVec3& sideAxis = PxVehicleGetDefaultContext().sideAxis) const;
872
877
882
883protected:
884
888 void setToRestState();
889
893 bool isValid() const;
894
898 static PxU32 computeByteSize(const PxU32 nbWheels);
899 static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleWheels* vehWheels, PxU8* ptr);
900 virtual void init(const PxU32 numWheels);
901
906 void free();
907
908 /*
909 \brief Deferred deletion.
910 */
911 void onConstraintRelease();
912
916 void setup
917 (PxPhysics* physics, PxRigidDynamic* vehActor,
918 const PxVehicleWheelsSimData& wheelsData,
919 const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
920
925
926private:
927
932 PxU32 mNbNonDrivenWheels;
933
934 PxU8 mOnConstraintReleaseCounter;
935
936protected:
937
941 PxU8 mType;
942
943#if PX_P64_FAMILY
944 PxU8 mPad0[14];
945#else
946 PxU8 mPad0[8];
947#endif
948
949//serialization
950public:
951 virtual void requiresObjects(PxProcessPxBaseCallback& c);
952 virtual const char* getConcreteTypeName() const { return "PxVehicleWheels"; }
953 virtual bool isKindOf(const char* name) const { return !::strcmp("PxVehicleWheels", name) || PxBase::isKindOf(name); }
954 virtual void preExportDataReset() {}
955 virtual void exportExtraData(PxSerializationContext&);
956 void importExtraData(PxDeserializationContext&);
957 void resolveReferences(PxDeserializationContext&);
958 static void getBinaryMetaData(PxOutputStream& stream);
959 PX_FORCE_INLINE PxU32 getNbNonDrivenWheels() const { return mNbNonDrivenWheels; }
960 PxVehicleWheels(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
961 PxVehicleWheels(PxBaseFlags baseFlags) : PxBase(baseFlags), mWheelsSimData(PxEmpty) {}
962 virtual ~PxVehicleWheels() {}
963 virtual void release() { free(); }
964//~serialization
965};
966PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheels) & 15));
967
968#if !PX_DOXYGEN
969} // namespace physx
970#endif
971
972#endif
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
A plugin class for implementing constraints.
Definition PxConstraint.h:100
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
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
Representation of a plane.
Definition PxPlane.h:49
Callback class used to process PxBase objects.
Definition PxSerialFramework.h:81
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition PxRigidDynamic.h:82
3 Element vector class.
Definition PxVec3.h:50
Definition PxVehicleComponents.h:1136
Definition PxVehicleSuspLimitConstraintShader.h:47
Data structure with instanced dynamics data and configuration data of a vehicle with up to 4 driven w...
Definition PxVehicleDrive4W.h:173
Data structure with instanced dynamics data and configuration data of a tank.
Definition PxVehicleDriveTank.h:147
Data structure with instanced dynamics data and configuration data of a vehicle with no drive model.
Definition PxVehicleNoDrive.h:53
Definition PxVehicleComponents.h:957
Definition PxVehicleComponents.h:1176
Structure containing shader data for each tire of a vehicle and a shader function that computes indiv...
Definition PxVehicleSuspLimitConstraintShader.h:278
Tire load variation can be strongly dependent on the time-step so it is a good idea to filter it to g...
Definition PxVehicleComponents.h:759
Definition PxVehicleUpdate.cpp:4519
Definition PxVehicleComponents.h:815
Definition PxVehicleSuspWheelTire4.h:167
Definition PxVehicleSuspWheelTire4.h:54
Data structure with instanced dynamics data for wheels.
Definition PxVehicleWheels.h:641
PxU32 getNbConstraints() const
Retrieve the number of PxConstraint objects associated with the vehicle.
Definition PxVehicleWheels.h:804
Data structure describing configuration data of a vehicle with up to 20 wheels.
Definition PxVehicleWheels.h:129
PxU32 getNbWheels() const
Return the number of wheels.
Definition PxVehicleWheels.h:189
PxU32 getNbAntiRollBars() const
Return the number of unique anti-roll bars that have been added with addAntiRollBarData.
Definition PxVehicleWheels.h:248
PX_FORCE_INLINE const PxVehicleTireLoadFilterData & getTireLoadFilterData() const
Return the data that describes the filtering of the tire load to produce smoother handling at large t...
Definition PxVehicleWheels.h:266
Data structure with instanced dynamics data and configuration data of a vehicle with just wheels.
Definition PxVehicleWheels.h:827
PX_FORCE_INLINE const PxRigidDynamic * getRigidDynamicActor() const
Get const ptr to PxRigidDynamic instance that is the vehicle's physx representation.
Definition PxVehicleWheels.h:853
PX_FORCE_INLINE PxRigidDynamic * getRigidDynamicActor()
Get non-const ptr to PxRigidDynamic instance that is the vehicle's physx representation.
Definition PxVehicleWheels.h:848
virtual void release()
Releases the PxBase instance, please check documentation of release in derived class.
Definition PxVehicleWheels.h:963
PxVehicleWheelsDynData mWheelsDynData
Data describing the dynamic state of all wheels/suspension/tires.
Definition PxVehicleWheels.h:881
virtual bool isKindOf(const char *name) const
Returns whether a given type name matches with the type of this instance.
Definition PxVehicleWheels.h:953
PX_FORCE_INLINE PxU32 getVehicleType() const
Return the type of vehicle.
Definition PxVehicleWheels.h:843
PxU8 mType
Vehicle type (eVehicleDriveTypes)
Definition PxVehicleWheels.h:941
PxVehicleWheelsSimData mWheelsSimData
Data describing the setup of all the wheels/suspensions/tires.
Definition PxVehicleWheels.h:876
virtual const char * getConcreteTypeName() const
Returns string name of dynamic type.
Definition PxVehicleWheels.h:952
PxRigidDynamic * mActor
The rigid body actor that represents the vehicle in the PhysX SDK.
Definition PxVehicleWheels.h:924
#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
PX_DEPRECATED typedef void(* PxVehicleComputeTireForce)(const void *shaderData, const PxF32 tireFriction, const PxF32 longSlip, const PxF32 latSlip, const PxF32 camber, const PxF32 wheelOmega, const PxF32 wheelRadius, const PxF32 recipWheelRadius, const PxF32 restTireLoad, const PxF32 normalisedTireLoad, const PxF32 tireLoad, const PxF32 gravity, const PxF32 recipGravity, PxF32 &wheelTorque, PxF32 &tireLongForceMag, PxF32 &tireLatForceMag, PxF32 &tireAlignMoment)
Prototype of shader function that is used to compute wheel torque and tire forces.
Definition PxVehicleShaders.h:61
PX_DEPRECATED const PxVehicleContext & PxVehicleGetDefaultContext()
Get the default vehicle context.
Definition PxVehicleUpdate.cpp:120
PxEMPTY
Definition Px.h:87
PxFlags< PxVehicleWheelsSimFlag::Enum, PxU32 > PxVehicleWheelsSimFlags
Collection of set bits defined in #PxVehicleWheelsSimFlag.
Definition PxVehicleWheels.h:121
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition PxFiltering.h:365
Description of the per wheel intersection method to be used by PxVehicleWheelsDynData::setTireContact...
Definition PxVehicleWheels.h:629
Flags to configure the vehicle wheel simulation.
Definition PxVehicleWheels.h:56
Enum
Definition PxVehicleWheels.h:58