PxController.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-2021 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_PHYSICS_CCT_CONTROLLER
31 #define PX_PHYSICS_CCT_CONTROLLER
32 
38 #include "PxQueryFiltering.h"
40 
41 #if !PX_DOXYGEN
42 namespace physx
43 {
44 #endif
45 
50 {
51  enum Enum
52  {
59 
66 
67  eFORCE_DWORD = 0x7fffffff
68  };
69 };
70 
71 class PxShape;
72 class PxScene;
73 class PxController;
74 class PxRigidDynamic;
75 class PxMaterial;
76 struct PxFilterData;
79 class PxObstacleContext;
80 class PxObstacle;
81 
88 {
89  enum Enum
90  {
92  ePREVENT_CLIMBING_AND_FORCE_SLIDING
93  };
94 };
95 
100 {
101  enum Enum
102  {
103  eCOLLISION_SIDES = (1<<0),
104  eCOLLISION_UP = (1<<1),
105  eCOLLISION_DOWN = (1<<2)
106  };
107 };
108 
115 PX_FLAGS_OPERATORS(PxControllerCollisionFlag::Enum, PxU8)
116 
117 
121 {
125  ObstacleHandle touchedObstacleHandle; // Obstacle on which the CCT is standing
129  bool isMovingUp;
130 };
131 
136 {
141 };
142 
147 {
153 };
154 
161 {
165 };
166 
173 {
175 };
176 
183 {
184  const void* userData;
185 };
186 
195 {
196 public:
197 
207  virtual void onShapeHit(const PxControllerShapeHit& hit) = 0;
208 
216  virtual void onControllerHit(const PxControllersHit& hit) = 0;
217 
225  virtual void onObstacleHit(const PxControllerObstacleHit& hit) = 0;
226 
227 protected:
229 };
230 
231 
244 {
245 public:
247 
255  virtual bool filter(const PxController& a, const PxController& b) = 0;
256 };
257 
276 {
277  public:
278 
279  PX_INLINE PxControllerFilters(const PxFilterData* filterData=NULL, PxQueryFilterCallback* cb=NULL, PxControllerFilterCallback* cctFilterCb=NULL) :
280  mFilterData (filterData),
281  mFilterCallback (cb),
282  mFilterFlags (PxQueryFlag::eSTATIC|PxQueryFlag::eDYNAMIC|PxQueryFlag::ePREFILTER),
283  mCCTFilterCallback (cctFilterCb)
284  {}
285 
286  // CCT-vs-shapes:
288  PxQueryFilterCallback* mFilterCallback;
291  // CCT-vs-CCT:
293 };
294 
301 {
302 public:
303 
309  PX_INLINE virtual bool isValid() const;
310 
319 
328 
338 
354 
367 
392 
405 
418 
427 
437 
447 
460 
473 
484 
495 
508 
514  void* userData;
515 
516 protected:
518 
523  PX_INLINE virtual ~PxControllerDesc();
524 
529 
533  PX_INLINE PxControllerDesc& operator=(const PxControllerDesc&);
534 
535  PX_INLINE void copy(const PxControllerDesc&);
536 };
537 
539 {
540  upDirection = PxVec3(0.0f, 1.0f, 0.0f);
541  slopeLimit = 0.707f;
542  contactOffset = 0.1f;
543  stepOffset = 0.5f;
544  density = 10.0f;
545  scaleCoeff = 0.8f;
546  volumeGrowth = 1.5f;
547  reportCallback = NULL;
548  behaviorCallback = NULL;
549  userData = NULL;
551  position.x = PxExtended(0.0);
552  position.y = PxExtended(0.0);
553  position.z = PxExtended(0.0);
554  material = NULL;
555  invisibleWallHeight = 0.0f;
556  maxJumpHeight = 0.0f;
558 }
559 
561 {
562  copy(other);
563 }
564 
566 {
567  copy(other);
568  return *this;
569 }
570 
572 {
573  upDirection = other.upDirection;
574  slopeLimit = other.slopeLimit;
576  stepOffset = other.stepOffset;
577  density = other.density;
578  scaleCoeff = other.scaleCoeff;
579  volumeGrowth = other.volumeGrowth;
582  userData = other.userData;
584  position.x = other.position.x;
585  position.y = other.position.y;
586  position.z = other.position.z;
587  material = other.material;
591 }
592 
594 {
595 }
596 
598 {
601  return false;
602  if(scaleCoeff<0.0f)
603  return false;
604  if(volumeGrowth<1.0f)
605  return false;
606  if(density<0.0f)
607  return false;
608  if(slopeLimit<0.0f)
609  return false;
610  if(stepOffset<0.0f)
611  return false;
612  if(contactOffset<=0.0f)
613  return false;
614  if(!material)
615  return false;
616  if(!toVec3(position).isFinite())
617  return false; //the float version needs to be finite otherwise actor creation will fail.
618 
619  return true;
620 }
621 
622 
629 {
630 public:
631  //*********************************************************************
632  // DEPRECATED FUNCTIONS:
633  //
634  // PX_DEPRECATED virtual void setInteraction(PxCCTInteractionMode::Enum flag) = 0;
635  // PX_DEPRECATED virtual PxCCTInteractionMode::Enum getInteraction() const = 0;
636  // PX_DEPRECATED virtual void setGroupsBitmask(PxU32 bitmask) = 0;
637  // PX_DEPRECATED virtual PxU32 getGroupsBitmask() const = 0;
638  //
639  // => replaced with:
640  //
641  // PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there.
642  //
643  //*********************************************************************
644 
650  virtual PxControllerShapeType::Enum getType() const = 0;
651 
655  virtual void release() = 0;
656 
668  virtual PxControllerCollisionFlags move(const PxVec3& disp, PxF32 minDist, PxF32 elapsedTime, const PxControllerFilters& filters, const PxObstacleContext* obstacles=NULL) = 0;
669 
685  virtual bool setPosition(const PxExtendedVec3& position) = 0;
686 
700  virtual const PxExtendedVec3& getPosition() const = 0;
701 
718  virtual bool setFootPosition(const PxExtendedVec3& position) = 0;
719 
729  virtual PxExtendedVec3 getFootPosition() const = 0;
730 
738  virtual PxRigidDynamic* getActor() const = 0;
739 
747  virtual void setStepOffset(const PxF32 offset) =0;
748 
756  virtual PxF32 getStepOffset() const =0;
757 
766 
775 
783  virtual PxF32 getContactOffset() const =0;
784 
792  virtual void setContactOffset(PxF32 offset) =0;
793 
801  virtual PxVec3 getUpDirection() const =0;
802 
810  virtual void setUpDirection(const PxVec3& up) =0;
811 
819  virtual PxF32 getSlopeLimit() const =0;
820 
832  virtual void setSlopeLimit(PxF32 slopeLimit) =0;
833 
849  virtual void invalidateCache() = 0;
850 
856  virtual PxScene* getScene() = 0;
857 
865  virtual void* getUserData() const = 0;
866 
874  virtual void setUserData(void* userData) = 0;
875 
883  virtual void getState(PxControllerState& state) const = 0;
884 
892  virtual void getStats(PxControllerStats& stats) const = 0;
893 
904  virtual void resize(PxReal height) = 0;
905 
906 protected:
908  virtual ~PxController() {}
909 };
910 
911 #if !PX_DOXYGEN
912 } // namespace physx
913 #endif
914 
916 #endif
bool standOnObstacle
Are we standing on a user-defined obstacle?
Definition: PxController.h:128
PxVec3 deltaXP
delta position vector for the object the CCT is standing/riding on. Not always match the CCT delta wh...
Definition: PxController.h:122
Definition: GuContactBuffer.h:37
PxF32 volumeGrowth
Cached volume growth.
Definition: PxController.h:446
PxExtendedVec3 worldPos
Contact position in world space.
Definition: PxController.h:149
PxControllerBehaviorCallback * behaviorCallback
Specifies a user behavior callback.
Definition: PxController.h:472
virtual PxF32 getStepOffset() const =0
Retrieve the step height.
A scene is a collection of bodies and constraints which can interact.
Definition: PxScene.h:169
PxController * other
Touched controller.
Definition: PxController.h:174
const void * userData
Definition: PxController.h:184
PxU32 collisionFlags
Last known collision flags (PxControllerCollisionFlag)
Definition: PxController.h:126
Scene query filtering callbacks.
Definition: PxQueryFiltering.h:169
PxControllerFilterCallback * mCCTFilterCallback
CCT-vs-CCT filter callback. If NULL, all CCT-vs-CCT collisions are kept.
Definition: PxController.h:292
PxControllerNonWalkableMode::Enum nonWalkableMode
The non-walkable mode controls if a character controller slides or not on a non-walkable part...
Definition: PxController.h:483
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
PxRigidActor * actor
Touched actor.
Definition: PxController.h:163
virtual PX_INLINE bool isValid() const
returns true if the current settings are valid
Definition: PxController.h:597
Abstract class for collision shapes.
Definition: PxShape.h:142
float PxReal
Definition: PxSimpleTypes.h:78
A box controller.
Definition: PxController.h:58
PX_INLINE PxControllerDesc(PxControllerShapeType::Enum)
constructor sets to default.
Definition: PxController.h:538
Stops character from climbing up non-walkable slopes, but doesn&#39;t move it otherwise.
Definition: PxController.h:91
Describes a generic CCT hit.
Definition: PxController.h:146
PxQueryFlags mFilterFlags
Flags for internal PxQueryFilterData structure. Passed to PxScene::overlap() call.
Definition: PxController.h:290
PxVec3 upDirection
Specifies the &#39;up&#39; direction.
Definition: PxController.h:337
virtual void getStats(PxControllerStats &stats) const =0
Returns the controller&#39;s internal statistics.
PxExtended y
Definition: PxExtended.h:253
virtual void invalidateCache()=0
Flushes internal geometry cache.
virtual void setContactOffset(PxF32 offset)=0
Sets the contact offset.
User callback class for character controller events.
Definition: PxController.h:194
PX_INLINE PxControllerFilters(const PxFilterData *filterData=NULL, PxQueryFilterCallback *cb=NULL, PxControllerFilterCallback *cctFilterCb=NULL)
Definition: PxController.h:279
PX_INLINE PxController()
Definition: PxController.h:907
PxF32 scaleCoeff
Scale coefficient for underlying kinematic actor.
Definition: PxController.h:436
PxF32 slopeLimit
The maximum slope which the character can walk up.
Definition: PxController.h:353
virtual ~PxUserControllerHitReport()
Definition: PxController.h:228
PxF32 stepOffset
Defines the maximum height of an obstacle which the character can climb.
Definition: PxController.h:417
virtual PxControllerCollisionFlags move(const PxVec3 &disp, PxF32 minDist, PxF32 elapsedTime, const PxControllerFilters &filters, const PxObstacleContext *obstacles=NULL)=0
Moves the character using a "collide-and-slide" algorithm.
PxF32 invisibleWallHeight
Height of invisible walls created around non-walkable triangles.
Definition: PxController.h:366
virtual ~PxController()
Definition: PxController.h:908
virtual void * getUserData() const =0
Returns the user data associated with this controller.
PxU16 nbPartialUpdates
Definition: PxController.h:139
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite(float a)
platform-specific finiteness check (not INF or NAN)
Definition: PxUnixIntrinsics.h:127
virtual PxF32 getContactOffset() const =0
Retrieve the contact offset.
virtual PxControllerShapeType::Enum getType() const =0
Return the type of controller.
virtual void setUserData(void *userData)=0
Sets the user data associated with this controller.
virtual PxF32 getSlopeLimit() const =0
Retrieve the slope limit.
PxMaterial * material
The material for the actor associated with the controller.
Definition: PxController.h:494
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition: PxRigidActor.h:58
virtual ~PxControllerFilterCallback()
Definition: PxController.h:246
virtual void setStepOffset(const PxF32 offset)=0
The step height.
virtual const PxExtendedVec3 & getPosition() const =0
Retrieve the raw position of the controller.
Enum
Definition: PxController.h:89
Dedicated filtering callback for CCT vs CCT.
Definition: PxController.h:243
virtual PX_INLINE ~PxControllerDesc()
Definition: PxController.h:593
Context class for obstacles.
Definition: PxControllerObstacles.h:114
PxF32 length
Motion length.
Definition: PxController.h:152
PxF32 density
Density of underlying kinematic actor.
Definition: PxController.h:426
PxExtended x
Definition: PxExtended.h:253
PxU16 nbIterations
Definition: PxController.h:137
const PxControllerShapeType::Enum mType
The type of the controller. This gets set by the derived class&#39; ctor, the user should not have to cha...
Definition: PxController.h:517
PxShape * touchedShape
Shape on which the CCT is standing.
Definition: PxController.h:123
virtual void setNonWalkableMode(PxControllerNonWalkableMode::Enum flag)=0
Sets the non-walkable mode for the CCT.
Base class for character controllers.
Definition: PxController.h:628
A capsule controller.
Definition: PxController.h:65
PX_INLINE PxControllerShapeType::Enum getType() const
Returns the character controller type.
Definition: PxController.h:318
bool standOnAnotherCCT
Are we standing on another CCT?
Definition: PxController.h:127
PX_INLINE PxControllerDesc & operator=(const PxControllerDesc &)
assignment operator.
Definition: PxController.h:565
virtual void setUpDirection(const PxVec3 &up)=0
Sets the &#39;up&#39; direction.
PxF32 maxJumpHeight
Maximum height a jumping character can reach.
Definition: PxController.h:391
PxExtended z
Definition: PxExtended.h:253
PxVec3 worldNormal
Contact normal in world space.
Definition: PxController.h:150
uint8_t PxU8
Definition: PxSimpleTypes.h:75
virtual bool setPosition(const PxExtendedVec3 &position)=0
Sets controller&#39;s position.
Base class for obstacles.
Definition: PxControllerObstacles.h:53
PxU16 nbFullUpdates
Definition: PxController.h:138
PxShape * shape
Touched shape.
Definition: PxController.h:162
void * userData
User specified data associated with the controller.
Definition: PxController.h:514
PxU32 ObstacleHandle
Definition: PxControllerObstacles.h:105
virtual void release()=0
Releases the controller.
double PxExtended
Definition: PxExtended.h:52
PxU16 nbTessellation
Definition: PxController.h:140
PxRigidActor * touchedActor
Actor owning &#39;touchedShape&#39;.
Definition: PxController.h:124
specifies which sides a character is colliding with.
Definition: PxController.h:99
virtual bool setFootPosition(const PxExtendedVec3 &position)=0
Set controller&#39;s foot position.
bool isMovingUp
is CCT moving up or not? (i.e. explicit jumping)
Definition: PxController.h:129
virtual PxRigidDynamic * getActor() const =0
Get the rigid body actor associated with this controller (see PhysX documentation). The behavior upon manually altering this actor is undefined, you should primarily use it for reading const properties.
The type of controller, eg box, sphere or capsule.
Definition: PxController.h:49
User behavior callback.
Definition: PxControllerBehavior.h:73
virtual void getState(PxControllerState &state) const =0
Returns information about the controller&#39;s internal state.
specifies how a CCT interacts with non-walkable parts.
Definition: PxController.h:87
virtual PxScene * getScene()=0
Retrieve the scene associated with the controller.
Filtering flags for scene queries.
Definition: PxQueryFiltering.h:57
PxVec3 dir
Motion direction.
Definition: PxController.h:151
virtual void resize(PxReal height)=0
Resizes the controller.
Describes a hit between a CCT and a shape. Passed to onShapeHit()
Definition: PxController.h:160
Material class to represent a set of surface properties.
Definition: PxMaterial.h:143
ObstacleHandle touchedObstacleHandle
Definition: PxController.h:125
virtual PxExtendedVec3 getFootPosition() const =0
Retrieve the "foot" position of the controller, i.e. the position of the bottom of the CCT&#39;s shape...
Container for bitfield flag variables associated with a specific enum type.
Definition: PxFlags.h:73
Describes a hit between a CCT and a user-defined obstacle. Passed to onObstacleHit().
Definition: PxController.h:182
Enum
Definition: PxController.h:101
PxF32 contactOffset
The contact offset used by the controller.
Definition: PxController.h:404
PxController * controller
Current controller.
Definition: PxController.h:148
Filtering data for "move" call.
Definition: PxController.h:275
uint16_t PxU16
Definition: PxSimpleTypes.h:73
uint32_t PxU32
Definition: Px.h:48
Describes a controller&#39;s internal state.
Definition: PxController.h:120
virtual void setSlopeLimit(PxF32 slopeLimit)=0
Sets the slope limit.
PxExtendedVec3 position
The position of the character.
Definition: PxController.h:327
virtual PxControllerNonWalkableMode::Enum getNonWalkableMode() const =0
Retrieves the non-walkable mode for the CCT.
PX_FORCE_INLINE PxVec3 toVec3(const PxExtendedVec3 &v)
Definition: PxExtended.h:256
Descriptor class for a character controller.
Definition: PxController.h:300
Describes a controller&#39;s internal statistics.
Definition: PxController.h:135
const PxFilterData * mFilterData
Definition: PxController.h:287
PxFlags< PxControllerCollisionFlag::Enum, PxU8 > PxControllerCollisionFlags
Bitfield that contains a set of raised flags defined in PxControllerCollisionFlag.
Definition: PxController.h:114
#define PX_INLINE
Definition: PxPreprocessor.h:336
virtual PxVec3 getUpDirection() const =0
Retrieve the &#39;up&#39; direction.
Enum
Definition: PxController.h:51
bool registerDeletionListener
Use a deletion listener to get informed about released objects and clear internal caches if needed...
Definition: PxController.h:507
3 Element vector class.
Definition: PxVec3.h:49
PX_INLINE void copy(const PxControllerDesc &)
Definition: PxController.h:571
Describes a hit between a CCT and another CCT. Passed to onControllerHit().
Definition: PxController.h:172
PxU32 triangleIndex
touched triangle index (only for meshes/heightfields)
Definition: PxController.h:164
PxUserControllerHitReport * reportCallback
Specifies a user report callback.
Definition: PxController.h:459
Definition: PxExtended.h:56