PxVehicleWheels.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_VEHICLE_WHEELS_H
00032 #define PX_VEHICLE_WHEELS_H
00033 
00037 #include "foundation/PxSimpleTypes.h"
00038 #include "vehicle/PxVehicleShaders.h"
00039 #include "vehicle/PxVehicleComponents.h"
00040 #include "common/PxBase.h"
00041 #include "PxRigidDynamic.h"
00042 
00043 #if !PX_DOXYGEN
00044 namespace physx
00045 {
00046 #endif
00047 
00048 class PxVehicleWheels4SimData;
00049 class PxVehicleWheels4DynData;
00050 class PxVehicleTireForceCalculator;
00051 class PxShape;
00052 class PxPhysics;
00053 class PxMaterial;
00054 
00059 class PxVehicleWheelsSimData
00060 {
00061 //= ATTENTION! =====================================================================================
00062 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00063 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00064 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00065 // accordingly.
00066 //==================================================================================================
00067 public:
00068 
00069     friend class PxVehicleWheels;
00070     friend class PxVehicleNoDrive;
00071     friend class PxVehicleDrive4W;
00072     friend class PxVehicleDriveTank;
00073     friend class PxVehicleUpdate;
00074 
00079     static PxVehicleWheelsSimData* allocate(const PxU32 nbWheels);
00080 
00094     void setChassisMass(const PxF32 chassisMass);
00095 
00100     void free();
00101 
00106     PxVehicleWheelsSimData& operator=(const PxVehicleWheelsSimData& src);
00107 
00114     void copy(const PxVehicleWheelsSimData& src, const PxU32 srcWheel, const PxU32 trgWheel);
00115 
00120     PxU32 getNbWheels() const {return mNbActiveWheels;}
00121 
00125     const PxVehicleSuspensionData& getSuspensionData(const PxU32 id) const;
00126         
00130     const PxVehicleWheelData& getWheelData(const PxU32 id) const;
00131 
00135     const PxVehicleTireData& getTireData(const PxU32 id) const;
00136     
00140     const PxVec3& getSuspTravelDirection(const PxU32 id) const;
00141 
00146     const PxVec3& getSuspForceAppPointOffset(const PxU32 id) const;
00147 
00152     const PxVec3& getTireForceAppPointOffset(const PxU32 id) const;
00153         
00157     const PxVec3& getWheelCentreOffset(const PxU32 id) const;   
00158 
00168     PxI32 getWheelShapeMapping(const PxU32 wheelId) const;
00169 
00173     const PxFilterData& getSceneQueryFilterData(const PxU32 suspId) const;
00174 
00179     PxU32 getNbAntiRollBars() const 
00180     {
00181         return mNbActiveAntiRollBars;
00182     }
00183 
00192     const PxVehicleAntiRollBarData& getAntiRollBarData(const PxU32 antiRollId) const;
00193     
00197     PX_FORCE_INLINE const PxVehicleTireLoadFilterData& getTireLoadFilterData() const 
00198     {
00199         return mNormalisedLoadFilter;
00200     }
00201 
00207     void setSuspensionData(const PxU32 id, const PxVehicleSuspensionData& susp);
00208 
00214     void setWheelData(const PxU32 id, const PxVehicleWheelData& wheel);
00215 
00221     void setTireData(const PxU32 id, const PxVehicleTireData& tire);
00222 
00228     void setSuspTravelDirection(const PxU32 id, const PxVec3& dir);
00229     
00236     void setSuspForceAppPointOffset(const PxU32 id, const PxVec3& offset);                                  
00237     
00244     void setTireForceAppPointOffset(const PxU32 id, const PxVec3& offset);
00245 
00252     void setWheelCentreOffset(const PxU32 id, const PxVec3& offset);    
00253 
00274     void setWheelShapeMapping(const PxU32 wheelId, const PxI32 shapeId);
00275 
00283     void setSceneQueryFilterData(const PxU32 suspId, const PxFilterData& sqFilterData);
00284 
00289     void setTireLoadFilterData(const PxVehicleTireLoadFilterData& tireLoadFilter);
00290 
00315     PxU32 addAntiRollBarData(const PxVehicleAntiRollBarData& antiRoll);
00316 
00345     void disableWheel(const PxU32 wheel);
00346 
00353     void enableWheel(const PxU32 wheel);
00354 
00359     bool getIsWheelDisabled(const PxU32 wheel) const;
00360 
00391     void setSubStepCount(const PxReal thresholdLongitudinalSpeed, const PxU32 lowForwardSpeedSubStepCount, const PxU32 highForwardSpeedSubStepCount);
00392 
00409     void setMinLongSlipDenominator(const PxReal minLongSlipDenominator);
00410 
00411 private:
00412 
00417     PxVehicleTireLoadFilterData mNormalisedLoadFilter;
00418 
00422     PxVehicleWheels4SimData* mWheels4SimData;
00423 
00427     PxU32 mNbWheels4;
00428 
00432     PxU32 mNbActiveWheels;
00433 
00437     PxVehicleAntiRollBarData* mAntiRollBars;
00438 
00442     PxU32 mNbAntiRollBars4;
00443 
00447     PxU32 mNbActiveAntiRollBars;
00448 
00453     PxU32 mActiveWheelsBitmapBuffer[((PX_MAX_NB_WHEELS + 31) & ~31) >> 5];
00454 
00460     PxF32 mThresholdLongitudinalSpeed;
00461 
00466     PxU32 mLowForwardSpeedSubStepCount;
00467 
00472     PxU32 mHighForwardSpeedSubStepCount;
00473 
00477     PxF32 mMinLongSlipDenominator;
00478 
00479 #if PX_P64_FAMILY
00480     PxU32 mPad[2];
00481 #else 
00482     PxU32 mPad[1];
00483 #endif
00484 
00488     bool isValid() const;
00489 
00493     static PxU32 computeByteSize(const PxU32 numWheels);
00494     static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsSimData* simData, PxU8* ptrIn);
00495     PxVehicleWheelsSimData(const PxU32 numWheels);
00496 
00497 //serialization
00498 public:
00499     PxVehicleWheelsSimData(const PxEMPTY) : mNormalisedLoadFilter(PxEmpty) {}
00500     static void getBinaryMetaData(PxOutputStream& stream);
00501     PxU32 getNbWheels4() const { return mNbWheels4; }   
00502     PxU32 getNbSuspensionData() const { return mNbActiveWheels; }
00503     PxU32 getNbWheelData() const {  return mNbActiveWheels; }   
00504     PxU32 getNbSuspTravelDirection() const  { return mNbActiveWheels; }
00505     PxU32 getNbTireData() const { return mNbActiveWheels;   }   
00506     PxU32 getNbSuspForceAppPointOffset() const  { return mNbActiveWheels;   }
00507     PxU32 getNbTireForceAppPointOffset() const  { return mNbActiveWheels;   }
00508     PxU32 getNbWheelCentreOffset() const { return mNbActiveWheels;  }
00509     PxU32 getNbWheelShapeMapping() const { return mNbActiveWheels; }
00510     PxU32 getNbSceneQueryFilterData() const { return mNbActiveWheels; }
00511     PxF32 getMinLongSlipDenominator() const {return mMinLongSlipDenominator;}
00512     void setThresholdLongSpeed(const PxF32 f) {mThresholdLongitudinalSpeed = f;}
00513     PxF32 getThresholdLongSpeed() const {return mThresholdLongitudinalSpeed;}
00514     void setLowForwardSpeedSubStepCount(const PxU32 f) {mLowForwardSpeedSubStepCount = f;}
00515     PxU32 getLowForwardSpeedSubStepCount() const {return mLowForwardSpeedSubStepCount;}
00516     void setHighForwardSpeedSubStepCount(const PxU32 f) {mHighForwardSpeedSubStepCount = f;}
00517     PxU32 getHighForwardSpeedSubStepCount() const {return mHighForwardSpeedSubStepCount;}
00518     void setWheelEnabledState(const PxU32 wheel, const bool state) {if(state) {enableWheel(wheel);} else {disableWheel(wheel);}}
00519     bool getWheelEnabledState(const PxU32 wheel) const {return !getIsWheelDisabled(wheel);}
00520     PxU32 getNbWheelEnabledState() const {return mNbActiveWheels;}
00521     PxU32 getNbAntiRollBars4() const { return mNbAntiRollBars4; }   
00522     PxU32 getNbAntiRollBarData() const {return mNbActiveAntiRollBars;}
00523     void setAntiRollBarData(const PxU32 id, const PxVehicleAntiRollBarData& antiRoll);
00524     PxVehicleWheelsSimData(){}
00525     ~PxVehicleWheelsSimData(){}
00526 //~serialization
00527 };
00528 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsSimData) & 15));
00529 
00533 class PxVehicleWheelsDynData
00534 {
00535 //= ATTENTION! =====================================================================================
00536 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00537 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00538 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00539 // accordingly.
00540 //==================================================================================================
00541 public:
00542 
00543     friend class PxVehicleWheels;
00544     friend class PxVehicleDrive4W;
00545     friend class PxVehicleDriveTank;
00546     friend class PxVehicleUpdate;
00547 
00548     PxVehicleWheelsDynData(){}
00549     ~PxVehicleWheelsDynData(){}
00550 
00555     void setToRestState();
00556 
00561     void setTireForceShaderFunction(PxVehicleComputeTireForce tireForceShaderFn);
00562 
00568     void setTireForceShaderData(const PxU32 tireId, const void* tireForceShaderData);
00569 
00573     const void* getTireForceShaderData(const PxU32 tireId) const;
00574 
00580     void setWheelRotationSpeed(const PxU32 wheelIdx, const PxReal speed);
00581 
00585     PxReal getWheelRotationSpeed(const PxU32 wheelIdx) const;
00586     
00592     void setWheelRotationAngle(const PxU32 wheelIdx, const PxReal angle);
00593 
00597     PxReal getWheelRotationAngle(const PxU32 wheelIdx) const;
00598 
00605     void setUserData(const PxU32 tireIdx, void* userData);
00606 
00610     void* getUserData(const PxU32 tireIdx) const;
00611 
00618     void copy(const PxVehicleWheelsDynData& src, const PxU32 srcWheel, const PxU32 trgWheel);
00619 
00620 private:
00621 
00625     PxVehicleWheels4DynData* mWheels4DynData;
00626 
00630     bool isValid() const;
00631 
00635     PxVehicleTireForceCalculator* mTireForceCalculators;
00636     
00641     void** mUserDatas;
00642 
00646     PxU32 mNbWheels4;
00647 
00651     PxU32 mNbActiveWheels;
00652 
00653     PxU32 mPad[3];
00654 
00658     static PxU32 computeByteSize(const PxU32 numWheels);
00659     static PxU8* patchUpPointers(const PxU32 numWheels, PxVehicleWheelsDynData* dynData, PxU8* ptr);
00660     PxVehicleWheelsDynData(const PxU32 numWheels);
00661 
00662 //serialization
00663 public:
00664     static void getBinaryMetaData(PxOutputStream& stream);  
00665     PxU32 getNbWheelRotationSpeed() const { return mNbActiveWheels; }
00666     PxU32 getNbWheelRotationAngle() const { return mNbActiveWheels; }   
00667     PxVehicleWheels4DynData* getWheel4DynData() const { return mWheels4DynData; }
00668 //~serialization
00669 };
00670 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheelsDynData) & 15));
00671 
00676 class PxVehicleWheels : public PxBase
00677 {
00678 //= ATTENTION! =====================================================================================
00679 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00680 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00681 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00682 // accordingly.
00683 //==================================================================================================
00684 public:
00685 
00686     friend class PxVehicleUpdate;
00687     friend class PxVehicleConstraintShader;
00688 
00693     PX_FORCE_INLINE PxU32 getVehicleType() const {return mType;}
00694 
00698     PX_FORCE_INLINE PxRigidDynamic* getRigidDynamicActor() {return mActor;}
00699 
00703     PX_FORCE_INLINE const PxRigidDynamic* getRigidDynamicActor() const {return mActor;}
00704     
00709     PxReal computeForwardSpeed() const;
00710 
00715     PxReal computeSidewaysSpeed() const;
00716 
00720     PxVehicleWheelsSimData mWheelsSimData;
00721 
00725     PxVehicleWheelsDynData mWheelsDynData;  
00726 
00727 protected:
00728 
00732     void setToRestState();
00733 
00737     bool isValid() const;
00738 
00742     static PxU32 computeByteSize(const PxU32 nbWheels);
00743     static PxU8* patchupPointers(const PxU32 nbWheels, PxVehicleWheels* vehWheels, PxU8* ptr);
00744     virtual void init(const PxU32 numWheels);
00745 
00750     void free();
00751 
00755     void setup
00756         (PxPhysics* physics, PxRigidDynamic* vehActor, 
00757          const PxVehicleWheelsSimData& wheelsData,
00758          const PxU32 nbDrivenWheels, const PxU32 nbNonDrivenWheels);
00759     
00763     PxRigidDynamic* mActor;
00764 
00765 private:
00766 
00771     PxU32 mNbNonDrivenWheels;
00772     
00773     PxU8 mOnConstraintReleaseCounter;
00774 
00775 protected:
00776 
00780     PxU8 mType;
00781         
00782 #if PX_P64_FAMILY
00783     PxU8 mPad0[14];
00784 #else
00785     PxU8 mPad0[14];
00786 #endif
00787 
00788 //serialization
00789 public:
00790     virtual     void            requiresObjects(PxProcessPxBaseCallback& c);
00791     virtual     const char*     getConcreteTypeName() const             {   return "PxVehicleWheels"; }
00792     virtual     bool            isKindOf(const char* name)  const       {   return !::strcmp("PxVehicleWheels", name) || PxBase::isKindOf(name); }
00793     virtual     void            exportExtraData(PxSerializationContext&);   
00794                 void            importExtraData(PxDeserializationContext&);
00795                 void            resolveReferences(PxDeserializationContext&);
00796     static      void            getBinaryMetaData(PxOutputStream& stream);
00797     PX_FORCE_INLINE PxU32 getNbNonDrivenWheels() const { return mNbNonDrivenWheels; }
00798     PxVehicleWheels(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {}
00799     PxVehicleWheels(PxBaseFlags baseFlags) : PxBase(baseFlags), mWheelsSimData(PxEmpty) {}
00800     virtual ~PxVehicleWheels() {}
00801     virtual void release() { free(); }
00802 //~serialization
00803 };
00804 PX_COMPILE_TIME_ASSERT(0==(sizeof(PxVehicleWheels) & 15));
00805 
00806 #if !PX_DOXYGEN
00807 } // namespace physx
00808 #endif
00809 
00811 #endif //PX_VEHICLE_WHEELS_H


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