RavEngine
Loading...
Searching...
No Matches
PxController.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_CONTROLLER_H
30#define PX_CONTROLLER_H
35#include "characterkinematic/PxExtended.h"
36#include "characterkinematic/PxControllerObstacles.h"
37#include "PxQueryFiltering.h"
38#include "foundation/PxErrorCallback.h"
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
49{
50 enum Enum
51 {
58
65
66 eFORCE_DWORD = 0x7fffffff
67 };
68};
69
70class PxShape;
71class PxScene;
72class PxController;
73class PxRigidDynamic;
74class PxMaterial;
75struct PxFilterData;
76class PxQueryFilterCallback;
77class PxControllerBehaviorCallback;
78class PxObstacleContext;
79class PxObstacle;
80
94
99{
100 enum Enum
101 {
103 eCOLLISION_UP = (1<<1),
104 eCOLLISION_DOWN = (1<<2)
105 };
106};
107
114PX_FLAGS_OPERATORS(PxControllerCollisionFlag::Enum, PxU8)
115
116
120{
124 PxObstacleHandle touchedObstacleHandle; // Obstacle on which the CCT is standing
129};
130
135{
136 PxU16 nbIterations;
137 PxU16 nbFullUpdates;
138 PxU16 nbPartialUpdates;
139 PxU16 nbTessellation;
140};
141
153
165
175
182{
183 const void* userData;
184};
185
194{
195public:
196
206 virtual void onShapeHit(const PxControllerShapeHit& hit) = 0;
207
215 virtual void onControllerHit(const PxControllersHit& hit) = 0;
216
224 virtual void onObstacleHit(const PxControllerObstacleHit& hit) = 0;
225
226protected:
228};
229
230
243{
244public:
246
254 virtual bool filter(const PxController& a, const PxController& b) = 0;
255};
256
293
545
547 position (PxExtended(0.0), PxExtended(0.0), PxExtended(0.0)),
548 upDirection (0.0f, 1.0f, 0.0f),
549 slopeLimit (0.707f),
550 invisibleWallHeight (0.0f),
551 maxJumpHeight (0.0f),
552 contactOffset (0.1f),
553 stepOffset (0.5f),
554 density (10.0f),
555 scaleCoeff (0.8f),
556 volumeGrowth (1.5f),
557 reportCallback (NULL),
558 behaviorCallback (NULL),
559 nonWalkableMode (PxControllerNonWalkableMode::ePREVENT_CLIMBING),
560 material (NULL),
561 registerDeletionListener (true),
562 clientID (PX_DEFAULT_CLIENT),
563 userData (NULL),
564 mType (t)
565{
566}
567
569{
570 copy(other);
571}
572
574{
575 copy(other);
576 return *this;
577}
578
579PX_INLINE void PxControllerDesc::copy(const PxControllerDesc& other)
580{
581 upDirection = other.upDirection;
582 slopeLimit = other.slopeLimit;
584 stepOffset = other.stepOffset;
585 density = other.density;
586 scaleCoeff = other.scaleCoeff;
590 userData = other.userData;
592 position.x = other.position.x;
593 position.y = other.position.y;
594 position.z = other.position.z;
595 material = other.material;
599 clientID = other.clientID;
600}
601
602PX_INLINE PxControllerDesc::~PxControllerDesc()
603{
604}
605
607{
610 return false;
611 if(scaleCoeff<0.0f)
612 return false;
613 if(volumeGrowth<1.0f)
614 return false;
615 if(density<0.0f)
616 return false;
617 if(slopeLimit<0.0f)
618 return false;
619 if(stepOffset<0.0f)
620 return false;
621 if(contactOffset<=0.0f)
622 return false;
623 if(!material)
624 return false;
625 if(!toVec3(position).isFinite())
626 return false; //the float version needs to be finite otherwise actor creation will fail.
627
628 return true;
629}
630
631
638{
639public:
640 //*********************************************************************
641 // DEPRECATED FUNCTIONS:
642 //
643 // PX_DEPRECATED virtual void setInteraction(PxCCTInteractionMode::Enum flag) = 0;
644 // PX_DEPRECATED virtual PxCCTInteractionMode::Enum getInteraction() const = 0;
645 // PX_DEPRECATED virtual void setGroupsBitmask(PxU32 bitmask) = 0;
646 // PX_DEPRECATED virtual PxU32 getGroupsBitmask() const = 0;
647 //
648 // => replaced with:
649 //
650 // PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there.
651 //
652 //*********************************************************************
653
660
664 virtual void release() = 0;
665
677 virtual PxControllerCollisionFlags move(const PxVec3& disp, PxF32 minDist, PxF32 elapsedTime, const PxControllerFilters& filters, const PxObstacleContext* obstacles=NULL) = 0;
678
694 virtual bool setPosition(const PxExtendedVec3& position) = 0;
695
709 virtual const PxExtendedVec3& getPosition() const = 0;
710
727 virtual bool setFootPosition(const PxExtendedVec3& position) = 0;
728
738 virtual PxExtendedVec3 getFootPosition() const = 0;
739
747 virtual PxRigidDynamic* getActor() const = 0;
748
756 virtual void setStepOffset(const PxF32 offset) =0;
757
765 virtual PxF32 getStepOffset() const =0;
766
775
784
792 virtual PxF32 getContactOffset() const =0;
793
801 virtual void setContactOffset(PxF32 offset) =0;
802
810 virtual PxVec3 getUpDirection() const =0;
811
819 virtual void setUpDirection(const PxVec3& up) =0;
820
828 virtual PxF32 getSlopeLimit() const =0;
829
841 virtual void setSlopeLimit(PxF32 slopeLimit) =0;
842
858 virtual void invalidateCache() = 0;
859
865 virtual PxScene* getScene() = 0;
866
874 virtual void* getUserData() const = 0;
875
883 virtual void setUserData(void* userData) = 0;
884
892 virtual void getState(PxControllerState& state) const = 0;
893
901 virtual void getStats(PxControllerStats& stats) const = 0;
902
913 virtual void resize(PxReal height) = 0;
914
915protected:
917 virtual ~PxController() {}
918};
919
920#if !PX_DOXYGEN
921} // namespace physx
922#endif
923
925#endif
User behavior callback.
Definition PxControllerBehavior.h:73
Descriptor class for a character controller.
Definition PxController.h:300
bool registerDeletionListener
Use a deletion listener to get informed about released objects and clear internal caches if needed.
Definition PxController.h:506
const PxControllerShapeType::Enum mType
The type of the controller. This gets set by the derived class' ctor, the user should not have to cha...
Definition PxController.h:525
PxF32 slopeLimit
The maximum slope which the character can walk up.
Definition PxController.h:352
PxMaterial * material
The material for the actor associated with the controller.
Definition PxController.h:493
PxF32 invisibleWallHeight
Height of invisible walls created around non-walkable triangles.
Definition PxController.h:365
PxControllerNonWalkableMode::Enum nonWalkableMode
The non-walkable mode controls if a character controller slides or not on a non-walkable part.
Definition PxController.h:482
PxClientID clientID
Client ID for associated actor.
Definition PxController.h:515
PxUserControllerHitReport * reportCallback
Specifies a user report callback.
Definition PxController.h:458
void * userData
User specified data associated with the controller.
Definition PxController.h:522
PxF32 scaleCoeff
Scale coefficient for underlying kinematic actor.
Definition PxController.h:435
PxF32 volumeGrowth
Cached volume growth.
Definition PxController.h:445
PxF32 density
Density of underlying kinematic actor.
Definition PxController.h:425
PxExtendedVec3 position
The position of the character.
Definition PxController.h:326
virtual PX_INLINE bool isValid() const
returns true if the current settings are valid
Definition PxController.h:606
PxF32 contactOffset
The contact offset used by the controller.
Definition PxController.h:403
PxControllerBehaviorCallback * behaviorCallback
Specifies a user behavior callback.
Definition PxController.h:471
PxVec3 upDirection
Specifies the 'up' direction.
Definition PxController.h:336
PX_INLINE PxControllerDesc & operator=(const PxControllerDesc &)
assignment operator.
Definition PxController.h:573
PX_INLINE PxControllerDesc(PxControllerShapeType::Enum)
constructor sets to default.
Definition PxController.h:546
PX_INLINE PxControllerShapeType::Enum getType() const
Returns the character controller type.
Definition PxController.h:317
PxF32 maxJumpHeight
Maximum height a jumping character can reach.
Definition PxController.h:390
PxF32 stepOffset
Defines the maximum height of an obstacle which the character can climb.
Definition PxController.h:416
Dedicated filtering callback for CCT vs CCT.
Definition PxController.h:243
virtual bool filter(const PxController &a, const PxController &b)=0
Filtering method for CCT-vs-CCT.
Filtering data for "move" call.
Definition PxController.h:275
PxQueryFilterCallback * mFilterCallback
Custom filter logic (can be NULL). Passed to PxScene::overlap() call.
Definition PxController.h:288
PxQueryFlags mFilterFlags
Flags for internal PxQueryFilterData structure. Passed to PxScene::overlap() call.
Definition PxController.h:289
PxControllerFilterCallback * mCCTFilterCallback
CCT-vs-CCT filter callback. If NULL, all CCT-vs-CCT collisions are kept.
Definition PxController.h:291
const PxFilterData * mFilterData
Definition PxController.h:286
Base class for character controllers.
Definition PxController.h:638
virtual PxControllerNonWalkableMode::Enum getNonWalkableMode() const =0
Retrieves the non-walkable mode for the CCT.
virtual void setUserData(void *userData)=0
Sets the user data associated with this controller.
virtual void getState(PxControllerState &state) const =0
Returns information about the controller's internal state.
virtual void setUpDirection(const PxVec3 &up)=0
Sets the 'up' direction.
virtual void setStepOffset(const PxF32 offset)=0
The step height.
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.
virtual PxControllerShapeType::Enum getType() const =0
Return the type of controller.
virtual const PxExtendedVec3 & getPosition() const =0
Retrieve the raw position of the controller.
virtual PxF32 getContactOffset() const =0
Retrieve the contact offset.
virtual void setNonWalkableMode(PxControllerNonWalkableMode::Enum flag)=0
Sets the non-walkable mode for the CCT.
virtual PxRigidDynamic * getActor() const =0
Get the rigid body actor associated with this controller (see PhysX documentation)....
virtual void resize(PxReal height)=0
Resizes the controller.
virtual void invalidateCache()=0
Flushes internal geometry cache.
virtual PxExtendedVec3 getFootPosition() const =0
Retrieve the "foot" position of the controller, i.e. the position of the bottom of the CCT's shape.
virtual PxVec3 getUpDirection() const =0
Retrieve the 'up' direction.
virtual void setContactOffset(PxF32 offset)=0
Sets the contact offset.
virtual void setSlopeLimit(PxF32 slopeLimit)=0
Sets the slope limit.
virtual bool setFootPosition(const PxExtendedVec3 &position)=0
Set controller's foot position.
virtual PxF32 getStepOffset() const =0
Retrieve the step height.
virtual void getStats(PxControllerStats &stats) const =0
Returns the controller's internal statistics.
virtual bool setPosition(const PxExtendedVec3 &position)=0
Sets controller's position.
virtual void * getUserData() const =0
Returns the user data associated with this controller.
virtual PxScene * getScene()=0
Retrieve the scene associated with the controller.
virtual PxF32 getSlopeLimit() const =0
Retrieve the slope limit.
virtual void release()=0
Releases the controller.
Container for bitfield flag variables associated with a specific enum type.
Definition PxFlags.h:73
Material class to represent a set of surface properties.
Definition PxMaterial.h:149
Context class for obstacles.
Definition PxControllerObstacles.h:114
Scene query filtering callbacks.
Definition PxQueryFiltering.h:175
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
PxRigidDynamic represents a dynamic rigid simulation object in the physics SDK.
Definition PxRigidDynamic.h:82
A scene is a collection of bodies and constraints which can interact.
Definition PxScene.h:178
Abstract class for collision shapes.
Definition PxShape.h:146
User callback class for character controller events.
Definition PxController.h:194
virtual void onObstacleHit(const PxControllerObstacleHit &hit)=0
Called when current controller hits a user-defined obstacle.
virtual void onControllerHit(const PxControllersHit &hit)=0
Called when current controller hits another controller.
virtual void onShapeHit(const PxControllerShapeHit &hit)=0
Called when current controller hits a shape.
3 Element vector class.
Definition PxVec3.h:50
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxFlags< PxControllerCollisionFlag::Enum, PxU8 > PxControllerCollisionFlags
Bitfield that contains a set of raised flags defined in PxControllerCollisionFlag.
Definition PxController.h:113
PxU8 PxClientID
An ID to identify different clients for multiclient support.
Definition PxClient.h:44
specifies which sides a character is colliding with.
Definition PxController.h:99
Enum
Definition PxController.h:101
@ eCOLLISION_SIDES
Character is colliding to the sides.
Definition PxController.h:102
@ eCOLLISION_UP
Character has collision above.
Definition PxController.h:103
@ eCOLLISION_DOWN
Character has collision below.
Definition PxController.h:104
Describes a generic CCT hit.
Definition PxController.h:146
PxController * controller
Current controller.
Definition PxController.h:147
PxVec3 worldNormal
Contact normal in world space.
Definition PxController.h:149
PxF32 length
Motion length.
Definition PxController.h:151
PxVec3 dir
Motion direction.
Definition PxController.h:150
PxExtendedVec3 worldPos
Contact position in world space.
Definition PxController.h:148
specifies how a CCT interacts with non-walkable parts.
Definition PxController.h:87
Enum
Definition PxController.h:89
@ ePREVENT_CLIMBING
Stops character from climbing up non-walkable slopes, but doesn't move it otherwise.
Definition PxController.h:90
@ ePREVENT_CLIMBING_AND_FORCE_SLIDING
Stops character from climbing up non-walkable slopes, and forces it to slide down those slopes.
Definition PxController.h:91
Describes a hit between a CCT and a user-defined obstacle. Passed to onObstacleHit().
Definition PxController.h:182
Describes a hit between a CCT and a shape. Passed to onShapeHit()
Definition PxController.h:160
PxShape * shape
Touched shape.
Definition PxController.h:161
PxU32 triangleIndex
touched triangle index (only for meshes/heightfields)
Definition PxController.h:163
PxRigidActor * actor
Touched actor.
Definition PxController.h:162
The type of controller, eg box, sphere or capsule.
Definition PxController.h:49
Enum
Definition PxController.h:51
@ eCAPSULE
A capsule controller.
Definition PxController.h:64
@ eBOX
A box controller.
Definition PxController.h:57
Describes a controller's internal state.
Definition PxController.h:120
PxVec3 deltaXP
delta position vector for the object the CCT is standing/riding on. Not always match the CCT delta wh...
Definition PxController.h:121
bool isMovingUp
is CCT moving up or not? (i.e. explicit jumping)
Definition PxController.h:128
bool standOnObstacle
Are we standing on a user-defined obstacle?
Definition PxController.h:127
bool standOnAnotherCCT
Are we standing on another CCT?
Definition PxController.h:126
PxU32 collisionFlags
Last known collision flags (PxControllerCollisionFlag)
Definition PxController.h:125
PxShape * touchedShape
Shape on which the CCT is standing.
Definition PxController.h:122
PxRigidActor * touchedActor
Actor owning 'touchedShape'.
Definition PxController.h:123
Describes a controller's internal statistics.
Definition PxController.h:135
Describes a hit between a CCT and another CCT. Passed to onControllerHit().
Definition PxController.h:172
PxController * other
Touched controller.
Definition PxController.h:173
Definition PxExtended.h:55
PxFilterData is user-definable data which gets passed into the collision filtering shader and/or call...
Definition PxFiltering.h:365
@ eSTATIC
Traverse static shapes.
Definition PxQueryFiltering.h:58
@ ePREFILTER
Run the pre-intersection-test filter (see PxQueryFilterCallback::preFilter())
Definition PxQueryFiltering.h:62
@ eDYNAMIC
Traverse dynamic shapes.
Definition PxQueryFiltering.h:60