PxController.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 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 
00032 #ifndef PX_PHYSICS_CCT_CONTROLLER
00033 #define PX_PHYSICS_CCT_CONTROLLER
00034 
00038 #include "characterkinematic/PxCharacter.h"
00039 #include "characterkinematic/PxExtended.h"
00040 #include "characterkinematic/PxControllerObstacles.h"
00041 #include "PxQueryFiltering.h"
00042 #include "foundation/PxErrorCallback.h"
00043 
00044 #if !PX_DOXYGEN
00045 namespace physx
00046 {
00047 #endif
00048 
00052 struct PxControllerShapeType
00053 {
00054     enum Enum
00055     {
00061         eBOX,
00062 
00068         eCAPSULE,
00069 
00070         eFORCE_DWORD = 0x7fffffff
00071     };
00072 };
00073 
00074 class PxShape;
00075 class PxScene;
00076 class PxController;
00077 class PxRigidDynamic;
00078 class PxMaterial;
00079 struct PxFilterData;
00080 class PxQueryFilterCallback;
00081 class PxControllerBehaviorCallback;
00082 class PxObstacleContext;
00083 class PxObstacle;
00084 
00090 struct PxControllerNonWalkableMode
00091 {
00092     enum Enum
00093     {
00094         ePREVENT_CLIMBING,                      
00095         ePREVENT_CLIMBING_AND_FORCE_SLIDING     
00096     };
00097 };
00098 
00102 struct PxControllerCollisionFlag
00103 {
00104     enum Enum
00105     {
00106         eCOLLISION_SIDES    = (1<<0),   
00107         eCOLLISION_UP       = (1<<1),   
00108         eCOLLISION_DOWN     = (1<<2)    
00109     };
00110 };
00111 
00117 typedef PxFlags<PxControllerCollisionFlag::Enum, PxU8> PxControllerCollisionFlags;
00118 PX_FLAGS_OPERATORS(PxControllerCollisionFlag::Enum, PxU8)
00119 
00120 
00121 
00124 struct PxControllerState
00125 {
00126     PxVec3          deltaXP;            
00127     PxShape*        touchedShape;       
00128     PxRigidActor*   touchedActor;       
00129     ObstacleHandle  touchedObstacleHandle;  // Obstacle on which the CCT is standing
00130     PxU32           collisionFlags;     
00131     bool            standOnAnotherCCT;  
00132     bool            standOnObstacle;    
00133     bool            isMovingUp;         
00134 };
00135 
00139 struct PxControllerStats
00140 {
00141     PxU16           nbIterations;
00142     PxU16           nbFullUpdates;
00143     PxU16           nbPartialUpdates;
00144     PxU16           nbTessellation;
00145 };
00146 
00150 struct PxControllerHit
00151 {
00152     PxController*   controller;     
00153     PxExtendedVec3  worldPos;       
00154     PxVec3          worldNormal;    
00155     PxVec3          dir;            
00156     PxF32           length;         
00157 };
00158 
00164 struct PxControllerShapeHit : public PxControllerHit
00165 {
00166     PxShape*        shape;          
00167     PxRigidActor*   actor;          
00168     PxU32           triangleIndex;  
00169 };
00170 
00176 struct PxControllersHit : public PxControllerHit
00177 {
00178     PxController*   other;          
00179 };
00180 
00186 struct PxControllerObstacleHit : public PxControllerHit
00187 {
00188     const void*     userData;
00189 };
00190 
00198 class PxUserControllerHitReport
00199 {
00200 public:
00201 
00211     virtual void onShapeHit(const PxControllerShapeHit& hit) = 0;
00212 
00220     virtual void onControllerHit(const PxControllersHit& hit) = 0;
00221 
00229     virtual void onObstacleHit(const PxControllerObstacleHit& hit) = 0;
00230 
00231 protected:
00232     virtual ~PxUserControllerHitReport(){}
00233 };
00234 
00235 
00247 class PxControllerFilterCallback
00248 {
00249 public:
00250     virtual ~PxControllerFilterCallback(){}
00251 
00259     virtual bool filter(const PxController& a, const PxController& b) = 0;
00260 };
00261 
00279 class PxControllerFilters
00280 {
00281     public:
00282 
00283     PX_INLINE                   PxControllerFilters(const PxFilterData* filterData=NULL, PxQueryFilterCallback* cb=NULL, PxControllerFilterCallback* cctFilterCb=NULL) :
00284                                     mFilterData         (filterData),
00285                                     mFilterCallback     (cb),
00286                                     mFilterFlags        (PxQueryFlag::eSTATIC|PxQueryFlag::eDYNAMIC|PxQueryFlag::ePREFILTER),
00287                                     mCCTFilterCallback  (cctFilterCb)
00288                                 {}
00289 
00290     // CCT-vs-shapes:
00291     const PxFilterData*         mFilterData;            
00292 
00293     PxQueryFilterCallback*      mFilterCallback;        
00294     PxQueryFlags                mFilterFlags;           
00295     // CCT-vs-CCT:
00296     PxControllerFilterCallback* mCCTFilterCallback;     
00297 };
00298 
00304 class PxControllerDesc
00305 {
00306 public:
00307 
00313     PX_INLINE virtual   bool                        isValid()       const;
00314 
00322     PX_INLINE           PxControllerShapeType::Enum     getType()       const   { return mType;     }
00323 
00331     PxExtendedVec3              position;
00332 
00341     PxVec3                      upDirection;
00342 
00357     PxF32                       slopeLimit;
00358 
00370     PxF32                       invisibleWallHeight;
00371 
00395     PxF32                       maxJumpHeight;
00396 
00408     PxF32                       contactOffset;
00409 
00421     PxF32                       stepOffset;
00422 
00430     PxF32                       density;
00431 
00440     PxF32                       scaleCoeff;
00441 
00450     PxF32                       volumeGrowth;
00451 
00463     PxUserControllerHitReport*  reportCallback;
00464 
00476     PxControllerBehaviorCallback*   behaviorCallback;
00477 
00487     PxControllerNonWalkableMode::Enum   nonWalkableMode;
00488 
00498     PxMaterial*                 material;
00499 
00511     bool                        registerDeletionListener;
00512 
00518     void*                       userData;
00519 
00520 protected:
00521     const PxControllerShapeType::Enum mType;        
00522 
00526     PX_INLINE                                       PxControllerDesc(PxControllerShapeType::Enum);
00527     PX_INLINE virtual                               ~PxControllerDesc();
00528 
00532     PX_INLINE                                       PxControllerDesc(const PxControllerDesc&);
00533 
00537     PX_INLINE PxControllerDesc&                     operator=(const PxControllerDesc&);
00538 
00539     PX_INLINE void                                  copy(const PxControllerDesc&);
00540 };
00541 
00542 PX_INLINE PxControllerDesc::PxControllerDesc(PxControllerShapeType::Enum t) : mType(t)
00543 {
00544     upDirection         = PxVec3(0.0f, 1.0f, 0.0f);
00545     slopeLimit          = 0.707f;
00546     contactOffset       = 0.1f;
00547     stepOffset          = 0.5f;
00548     density             = 10.0f;
00549     scaleCoeff          = 0.8f;
00550     volumeGrowth        = 1.5f;
00551     reportCallback      = NULL;
00552     behaviorCallback    = NULL;
00553     userData            = NULL;
00554     nonWalkableMode     = PxControllerNonWalkableMode::ePREVENT_CLIMBING;
00555     position.x          = PxExtended(0.0);
00556     position.y          = PxExtended(0.0);
00557     position.z          = PxExtended(0.0);
00558     material            = NULL;
00559     invisibleWallHeight = 0.0f;
00560     maxJumpHeight       = 0.0f;
00561     registerDeletionListener = true;
00562 }
00563 
00564 PX_INLINE PxControllerDesc::PxControllerDesc(const PxControllerDesc& other) : mType(other.mType)
00565 {
00566     copy(other);
00567 }
00568 
00569 PX_INLINE PxControllerDesc& PxControllerDesc::operator=(const PxControllerDesc& other)
00570 {
00571     copy(other);
00572     return *this;
00573 }
00574 
00575 PX_INLINE void PxControllerDesc::copy(const PxControllerDesc& other)
00576 {
00577     upDirection         = other.upDirection;
00578     slopeLimit          = other.slopeLimit;
00579     contactOffset       = other.contactOffset;
00580     stepOffset          = other.stepOffset;
00581     density             = other.density;
00582     scaleCoeff          = other.scaleCoeff;
00583     volumeGrowth        = other.volumeGrowth;
00584     reportCallback      = other.reportCallback;
00585     behaviorCallback    = other.behaviorCallback;
00586     userData            = other.userData;
00587     nonWalkableMode     = other.nonWalkableMode;
00588     position.x          = other.position.x;
00589     position.y          = other.position.y;
00590     position.z          = other.position.z;
00591     material            = other.material;
00592     invisibleWallHeight = other.invisibleWallHeight;
00593     maxJumpHeight       = other.maxJumpHeight;
00594     registerDeletionListener = other.registerDeletionListener;
00595 }
00596 
00597 PX_INLINE PxControllerDesc::~PxControllerDesc()
00598 {
00599 }
00600 
00601 PX_INLINE bool PxControllerDesc::isValid() const
00602 {
00603     if(     mType!=PxControllerShapeType::eBOX
00604         &&  mType!=PxControllerShapeType::eCAPSULE)
00605         return false;
00606     if(scaleCoeff<0.0f)     return false;
00607     if(volumeGrowth<1.0f)   return false;
00608     if(density<0.0f)        return false;
00609     if(slopeLimit<0.0f)     return false;
00610     if(stepOffset<0.0f)     return false;
00611     if(contactOffset<=0.0f) return false;
00612     if(!material)           return false;
00613 
00614     return true;
00615 }
00616 
00617 
00623 class PxController
00624 {
00625 public:
00626     //*********************************************************************
00627     // DEPRECATED FUNCTIONS:
00628     //
00629     //  PX_DEPRECATED virtual   void                        setInteraction(PxCCTInteractionMode::Enum flag) = 0;
00630     //  PX_DEPRECATED virtual   PxCCTInteractionMode::Enum  getInteraction()                    const       = 0;
00631     //  PX_DEPRECATED virtual   void                        setGroupsBitmask(PxU32 bitmask)                 = 0;
00632     //  PX_DEPRECATED virtual   PxU32                       getGroupsBitmask()                  const       = 0;
00633     //
00634     //  => replaced with:
00635     //
00636     //  PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there.
00637     //
00638     //*********************************************************************
00639 
00645     virtual     PxControllerShapeType::Enum getType()       const           = 0;
00646 
00650     virtual     void                    release() = 0;
00651 
00663     virtual     PxControllerCollisionFlags  move(const PxVec3& disp, PxF32 minDist, PxF32 elapsedTime, const PxControllerFilters& filters, const PxObstacleContext* obstacles=NULL) = 0;
00664 
00680     virtual     bool                    setPosition(const PxExtendedVec3& position) = 0;
00681 
00695     virtual     const PxExtendedVec3&   getPosition()           const   = 0;
00696 
00713     virtual     bool                    setFootPosition(const PxExtendedVec3& position) = 0;
00714 
00724     virtual     PxExtendedVec3          getFootPosition()       const   = 0;
00725 
00733     virtual     PxRigidDynamic*         getActor()              const   = 0;
00734 
00742     virtual     void                    setStepOffset(const PxF32 offset) =0;
00743 
00751     virtual     PxF32                   getStepOffset()                     const       =0;
00752 
00760     virtual     void                        setNonWalkableMode(PxControllerNonWalkableMode::Enum flag)  = 0;
00761 
00769     virtual     PxControllerNonWalkableMode::Enum   getNonWalkableMode()                const       = 0;
00770 
00778     virtual     PxF32                   getContactOffset()                  const       =0;
00779 
00787     virtual     void                    setContactOffset(PxF32 offset)                  =0;
00788 
00796     virtual     PxVec3                  getUpDirection()                    const       =0;
00797 
00805     virtual     void                    setUpDirection(const PxVec3& up)                =0;
00806 
00814     virtual     PxF32                   getSlopeLimit()                     const       =0;
00815 
00827     virtual     void                    setSlopeLimit(PxF32 slopeLimit)                 =0;
00828 
00844     virtual     void                    invalidateCache()           = 0;
00845 
00851     virtual     PxScene*                getScene()                      = 0;
00852 
00860     virtual     void*                   getUserData()       const       = 0;
00861 
00869     virtual     void                    setUserData(void* userData)     = 0;
00870 
00878     virtual     void                    getState(PxControllerState& state)  const       = 0;
00879 
00887     virtual     void                    getStats(PxControllerStats& stats)  const       = 0;
00888 
00899     virtual     void                    resize(PxReal height)   = 0;
00900 
00901 protected:
00902     PX_INLINE                           PxController()                  {}
00903     virtual                             ~PxController()                 {}
00904 };
00905 
00906 #if !PX_DOXYGEN
00907 } // namespace physx
00908 #endif
00909 
00911 #endif


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