1 | /* |
2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
3 | * |
4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
5 | * and proprietary rights in and to this software, related documentation |
6 | * and any modifications thereto. Any use, reproduction, disclosure or |
7 | * distribution of this software and related documentation without an express |
8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
9 | */ |
10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
12 | |
13 | |
14 | |
15 | #ifndef PX_PHYSICS_CCT_CONTROLLER |
16 | #define PX_PHYSICS_CCT_CONTROLLER |
17 | /** \addtogroup character |
18 | @{ |
19 | */ |
20 | |
21 | #include "characterkinematic/PxCharacter.h" |
22 | #include "characterkinematic/PxExtended.h" |
23 | #include "characterkinematic/PxControllerObstacles.h" |
24 | #include "PxQueryFiltering.h" |
25 | #include "foundation/PxFoundation.h" |
26 | #include "foundation/PxErrorCallback.h" |
27 | |
28 | #ifndef PX_DOXYGEN |
29 | namespace physx |
30 | { |
31 | #endif |
32 | |
33 | /** |
34 | \brief The type of controller, eg box, sphere or capsule. |
35 | */ |
36 | struct PxControllerShapeType |
37 | { |
38 | enum Enum |
39 | { |
40 | /** |
41 | \brief A box controller. |
42 | |
43 | @see PxBoxController PxBoxControllerDesc |
44 | */ |
45 | eBOX, |
46 | |
47 | /** |
48 | \brief A capsule controller |
49 | |
50 | @see PxCapsuleController PxCapsuleControllerDesc |
51 | */ |
52 | eCAPSULE, |
53 | |
54 | eFORCE_DWORD = 0x7fffffff |
55 | }; |
56 | }; |
57 | |
58 | class PxShape; |
59 | class PxScene; |
60 | class PxController; |
61 | class PxRigidDynamic; |
62 | class PxMaterial; |
63 | struct PxFilterData; |
64 | class PxQueryFilterCallback; |
65 | class PxControllerBehaviorCallback; |
66 | class PxObstacleContext; |
67 | class PxObstacle; |
68 | |
69 | /** |
70 | \brief specifies how a CCT interacts with non-walkable parts. |
71 | |
72 | This is only used when slopeLimit is non zero. It is currently enabled for static actors only, and not supported for spheres or capsules. |
73 | */ |
74 | struct PxControllerNonWalkableMode |
75 | { |
76 | enum Enum |
77 | { |
78 | ePREVENT_CLIMBING, //!< Stops character from climbing up non-walkable slopes, but doesn't move it otherwise |
79 | ePREVENT_CLIMBING_AND_FORCE_SLIDING, //!< Stops character from climbing up non-walkable slopes, and forces it to slide down those slopes |
80 | |
81 | eFORCE_SLIDING = ePREVENT_CLIMBING_AND_FORCE_SLIDING //!< \deprecated PX_DEPRECATED |
82 | }; |
83 | }; |
84 | /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ |
85 | typedef PX_DEPRECATED PxControllerNonWalkableMode PxCCTNonWalkableMode; |
86 | |
87 | /** |
88 | \brief specifies which sides a character is colliding with. |
89 | */ |
90 | struct PxControllerCollisionFlag |
91 | { |
92 | enum Enum |
93 | { |
94 | eCOLLISION_SIDES = (1<<0), //!< Character is colliding to the sides. |
95 | eCOLLISION_UP = (1<<1), //!< Character has collision above. |
96 | eCOLLISION_DOWN = (1<<2) //!< Character has collision below. |
97 | }; |
98 | }; |
99 | |
100 | /** |
101 | \brief Bitfield that contains a set of raised flags defined in PxControllerCollisionFlag. |
102 | |
103 | @see PxControllerCollisionFlag |
104 | */ |
105 | typedef PxFlags<PxControllerCollisionFlag::Enum, PxU8> PxControllerCollisionFlags; |
106 | PX_FLAGS_OPERATORS(PxControllerCollisionFlag::Enum, PxU8) |
107 | |
108 | /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ |
109 | typedef PX_DEPRECATED PxControllerCollisionFlag PxControllerFlag; |
110 | /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ |
111 | typedef PX_DEPRECATED PxControllerCollisionFlags PxControllerFlags; |
112 | |
113 | |
114 | /** |
115 | \brief Describes a controller's internal state. |
116 | */ |
117 | struct PxControllerState |
118 | { |
119 | PxVec3 deltaXP; //!< delta position vector for the object the CCT is standing/riding on. Not always match the CCT delta when variable timesteps are used. |
120 | PxShape* touchedShape; //!< Shape on which the CCT is standing |
121 | PxRigidActor* touchedActor; //!< Actor owning 'touchedShape' |
122 | ObstacleHandle touchedObstacleHandle; // Obstacle on which the CCT is standing |
123 | PxU32 collisionFlags; //!< Last known collision flags (PxControllerCollisionFlag) |
124 | bool standOnAnotherCCT; //!< Are we standing on another CCT? |
125 | bool standOnObstacle; //!< Are we standing on a user-defined obstacle? |
126 | bool isMovingUp; //!< is CCT moving up or not? (i.e. explicit jumping) |
127 | }; |
128 | |
129 | /** |
130 | \brief Describes a controller's internal statistics. |
131 | */ |
132 | struct PxControllerStats |
133 | { |
134 | PxU16 nbIterations; |
135 | PxU16 nbFullUpdates; |
136 | PxU16 nbPartialUpdates; |
137 | PxU16 nbTessellation; |
138 | }; |
139 | |
140 | /** |
141 | \brief Describes a generic CCT hit. |
142 | */ |
143 | struct PxControllerHit |
144 | { |
145 | PxController* controller; //!< Current controller |
146 | PxExtendedVec3 worldPos; //!< Contact position in world space |
147 | PxVec3 worldNormal; //!< Contact normal in world space |
148 | PxVec3 dir; //!< Motion direction |
149 | PxF32 length; //!< Motion length |
150 | }; |
151 | /** \deprecated Deprecated definition for backwards compatibility with PhysX 3.2 */ |
152 | typedef PX_DEPRECATED PxControllerHit PxCCTHit; |
153 | |
154 | /** |
155 | \brief Describes a hit between a CCT and a shape. Passed to onShapeHit() |
156 | |
157 | @see PxUserControllerHitReport.onShapeHit() |
158 | */ |
159 | struct PxControllerShapeHit : PxControllerHit |
160 | { |
161 | PxShape* shape; //!< Touched shape |
162 | PxRigidActor* actor; //!< Touched actor |
163 | PxU32 triangleIndex; //!< touched triangle index (only for meshes/heightfields) |
164 | }; |
165 | |
166 | /** |
167 | \brief Describes a hit between a CCT and another CCT. Passed to onControllerHit(). |
168 | |
169 | @see PxUserControllerHitReport.onControllerHit() |
170 | */ |
171 | struct PxControllersHit : PxControllerHit |
172 | { |
173 | PxController* other; //!< Touched controller |
174 | }; |
175 | |
176 | /** |
177 | \brief Describes a hit between a CCT and a user-defined obstacle. Passed to onObstacleHit(). |
178 | |
179 | @see PxUserControllerHitReport.onObstacleHit() PxObstacleContext |
180 | */ |
181 | struct PxControllerObstacleHit : PxControllerHit |
182 | { |
183 | const void* userData; |
184 | }; |
185 | |
186 | /** |
187 | \brief User callback class for character controller events. |
188 | |
189 | \note Character controller hit reports are only generated when move is called. |
190 | |
191 | @see PxControllerDesc.callback |
192 | */ |
193 | class PxUserControllerHitReport |
194 | { |
195 | public: |
196 | |
197 | /** |
198 | \brief Called when current controller hits a shape. |
199 | |
200 | This is called when the CCT moves and hits a shape. This will not be called when a moving shape hits a non-moving CCT. |
201 | |
202 | \param[in] hit Provides information about the hit. |
203 | |
204 | @see PxControllerShapeHit |
205 | */ |
206 | virtual void onShapeHit(const PxControllerShapeHit& hit) = 0; |
207 | |
208 | /** |
209 | \brief Called when current controller hits another controller. |
210 | |
211 | \param[in] hit Provides information about the hit. |
212 | |
213 | @see PxControllersHit |
214 | */ |
215 | virtual void onControllerHit(const PxControllersHit& hit) = 0; |
216 | |
217 | /** |
218 | \brief Called when current controller hits a user-defined obstacle. |
219 | |
220 | \param[in] hit Provides information about the hit. |
221 | |
222 | @see PxControllerObstacleHit PxObstacleContext |
223 | */ |
224 | virtual void onObstacleHit(const PxControllerObstacleHit& hit) = 0; |
225 | |
226 | protected: |
227 | virtual ~PxUserControllerHitReport(){} |
228 | }; |
229 | |
230 | |
231 | /** |
232 | \brief Dedicated filtering callback for CCT vs CCT. |
233 | |
234 | This controls collisions between CCTs (one CCT vs anoter CCT). |
235 | |
236 | To make each CCT collide against all other CCTs, just return true - or simply avoid defining a callback. |
237 | To make each CCT freely go through all other CCTs, just return false. |
238 | Otherwise create a custom filtering logic in this callback. |
239 | |
240 | @see PxControllerFilters |
241 | */ |
242 | class PxControllerFilterCallback |
243 | { |
244 | public: |
245 | virtual ~PxControllerFilterCallback(){} |
246 | |
247 | /** |
248 | \brief Filtering method for CCT-vs-CCT. |
249 | |
250 | \param[in] a First CCT |
251 | \param[in] b Second CCT |
252 | \return true to keep the pair, false to filter it out |
253 | */ |
254 | virtual bool filter(const PxController& a, const PxController& b) = 0; |
255 | }; |
256 | |
257 | /** |
258 | \brief Filtering data for "move" call. |
259 | |
260 | This class contains all filtering-related parameters for the PxController::move() call. |
261 | |
262 | Collisions between a CCT and the world are filtered using the mFilterData, mFilterCallback and mFilterFlags |
263 | members. These parameters are internally passed to PxScene::overlap() to find objects touched by the CCT. |
264 | Please refer to the PxScene::overlap() documentation for details. |
265 | |
266 | Collisions between a CCT and another CCT are filtered using the mCCTFilterCallback member. If this filter |
267 | callback is not defined, none of the CCT-vs-CCT collisions are filtered, and each CCT will collide against |
268 | all other CCTs. |
269 | |
270 | \note PxQueryFlag::eANY_HIT and PxQueryFlag::eNO_BLOCK are ignored in mFilterFlags. |
271 | |
272 | @see PxController.move() PxControllerFilterCallback |
273 | */ |
274 | class PxControllerFilters |
275 | { |
276 | public: |
277 | //********************************************************************* |
278 | // DEPRECATED MEMBERS: |
279 | // |
280 | // PX_DEPRECATED PxU32 mActiveGroups; |
281 | // |
282 | // => replaced with: |
283 | // |
284 | // PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there. |
285 | // |
286 | //********************************************************************* |
287 | |
288 | PX_INLINE PxControllerFilters(const PxFilterData* filterData=NULL, PxQueryFilterCallback* cb=NULL, PxControllerFilterCallback* cctFilterCb=NULL) : |
289 | mFilterData (filterData), |
290 | mFilterCallback (cb), |
291 | mFilterFlags (PxQueryFlag::eSTATIC|PxQueryFlag::eDYNAMIC|PxQueryFlag::ePREFILTER), |
292 | mCCTFilterCallback (cctFilterCb) |
293 | {} |
294 | |
295 | // CCT-vs-shapes: |
296 | const PxFilterData* mFilterData; //!< Data for internal PxQueryFilterData structure. Passed to PxScene::overlap() call. |
297 | //!< This can be NULL, in which case a default PxFilterData is used. |
298 | PxQueryFilterCallback* mFilterCallback; //!< Custom filter logic (can be NULL). Passed to PxScene::overlap() call. |
299 | PxQueryFlags mFilterFlags; //!< Flags for internal PxQueryFilterData structure. Passed to PxScene::overlap() call. |
300 | // CCT-vs-CCT: |
301 | PxControllerFilterCallback* mCCTFilterCallback; //!< CCT-vs-CCT filter callback. If NULL, all CCT-vs-CCT collisions are kept. |
302 | }; |
303 | |
304 | |
305 | /** |
306 | \brief Descriptor class for a character controller. |
307 | |
308 | @see PxBoxController PxCapsuleController |
309 | */ |
310 | class PxControllerDesc |
311 | { |
312 | public: |
313 | //********************************************************************* |
314 | // DEPRECATED MEMBERS: |
315 | // |
316 | // PX_DEPRECATED PxUserControllerHitReport* callback; |
317 | // |
318 | // => replaced with: |
319 | // |
320 | // PxUserControllerHitReport* reportCallback; |
321 | // |
322 | // ---------------------------- |
323 | // |
324 | // PX_DEPRECATED PxCCTInteractionMode::Enum interactionMode; |
325 | // PX_DEPRECATED PxU32 groupsBitmask; |
326 | // |
327 | // => replaced with: |
328 | // |
329 | // PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there. |
330 | // |
331 | //********************************************************************* |
332 | |
333 | /** |
334 | \brief returns true if the current settings are valid |
335 | |
336 | \return True if the descriptor is valid. |
337 | */ |
338 | PX_INLINE virtual bool isValid() const; |
339 | |
340 | /** |
341 | \brief Returns the character controller type |
342 | |
343 | \return The controllers type. |
344 | |
345 | @see PxControllerType PxCapsuleControllerDesc PxBoxControllerDesc |
346 | */ |
347 | PX_INLINE PxControllerShapeType::Enum getType() const { return mType; } |
348 | |
349 | /** |
350 | \brief The position of the character |
351 | |
352 | \note The character's initial position must be such that it does not overlap the static geometry. |
353 | |
354 | <b>Default:</b> Zero |
355 | */ |
356 | PxExtendedVec3 position; |
357 | |
358 | /** |
359 | \brief Specifies the 'up' direction |
360 | |
361 | In order to provide stepping functionality the SDK must be informed about the up direction. |
362 | |
363 | <b>Default:</b> (0, 1, 0) |
364 | |
365 | */ |
366 | PxVec3 upDirection; |
367 | |
368 | /** |
369 | \brief The maximum slope which the character can walk up. |
370 | |
371 | In general it is desirable to limit where the character can walk, in particular it is unrealistic |
372 | for the character to be able to climb arbitary slopes. |
373 | |
374 | The limit is expressed as the cosine of desired limit angle. A value of 0 disables this feature. |
375 | |
376 | \warning It is currently enabled for static actors only (not for dynamic/kinematic actors), and not supported for spheres or capsules. |
377 | |
378 | <b>Default:</b> 0.707 |
379 | |
380 | @see upDirection invisibleWallHeight maxJumpHeight |
381 | */ |
382 | PxF32 slopeLimit; |
383 | |
384 | /** |
385 | \brief Height of invisible walls created around non-walkable triangles |
386 | |
387 | The library can automatically create invisible walls around non-walkable triangles defined |
388 | by the 'slopeLimit' parameter. This defines the height of those walls. If it is 0.0, then |
389 | no extra triangles are created. |
390 | |
391 | <b>Default:</b> 0.0 |
392 | |
393 | @see upDirection slopeLimit maxJumpHeight |
394 | */ |
395 | PxF32 invisibleWallHeight; |
396 | |
397 | /** |
398 | \brief Maximum height a jumping character can reach |
399 | |
400 | This is only used if invisible walls are created ('invisibleWallHeight' is non zero). |
401 | |
402 | When a character jumps, the non-walkable triangles he might fly over are not found |
403 | by the collision queries (since the character's bounding volume does not touch them). |
404 | Thus those non-walkable triangles do not create invisible walls, and it is possible |
405 | for a jumping character to land on a non-walkable triangle, while he wouldn't have |
406 | reached that place by just walking. |
407 | |
408 | The 'maxJumpHeight' variable is used to extend the size of the collision volume |
409 | downward. This way, all the non-walkable triangles are properly found by the collision |
410 | queries and it becomes impossible to 'jump over' invisible walls. |
411 | |
412 | If the character in your game can not jump, it is safe to use 0.0 here. Otherwise it |
413 | is best to keep this value as small as possible, since a larger collision volume |
414 | means more triangles to process. |
415 | |
416 | <b>Default:</b> 0.0 |
417 | |
418 | @see upDirection slopeLimit invisibleWallHeight |
419 | */ |
420 | PxF32 maxJumpHeight; |
421 | |
422 | /** |
423 | \brief The contact offset used by the controller. |
424 | |
425 | Specifies a skin around the object within which contacts will be generated. |
426 | Use it to avoid numerical precision issues. |
427 | |
428 | This is dependant on the scale of the users world, but should be a small, positive |
429 | non zero value. |
430 | |
431 | <b>Default:</b> 0.1 |
432 | */ |
433 | PxF32 contactOffset; |
434 | |
435 | /** |
436 | \brief Defines the maximum height of an obstacle which the character can climb. |
437 | |
438 | A small value will mean that the character gets stuck and cannot walk up stairs etc, |
439 | a value which is too large will mean that the character can climb over unrealistically |
440 | high obstacles. |
441 | |
442 | <b>Default:</b> 0.5 |
443 | |
444 | @see upDirection |
445 | */ |
446 | PxF32 stepOffset; |
447 | |
448 | /** |
449 | \brief Density of underlying kinematic actor |
450 | |
451 | The CCT creates a PhysX's kinematic actor under the hood. This controls its density. |
452 | |
453 | <b>Default:</b> 10.0 |
454 | */ |
455 | PxF32 density; |
456 | |
457 | /** |
458 | \brief Scale coefficient for underlying kinematic actor |
459 | |
460 | The CCT creates a PhysX's kinematic actor under the hood. This controls its scale factor. |
461 | This should be a number a bit smaller than 1.0. |
462 | |
463 | <b>Default:</b> 0.8 |
464 | */ |
465 | PxF32 scaleCoeff; |
466 | |
467 | /** |
468 | \brief Cached volume growth |
469 | |
470 | Amount of space around the controller we cache to improve performance. This is a scale factor |
471 | that should be higher than 1.0f but not too big, ideally lower than 2.0f. |
472 | |
473 | <b>Default:</b> 1.5 |
474 | */ |
475 | PxF32 volumeGrowth; |
476 | |
477 | /** |
478 | \brief Specifies a user report callback. |
479 | |
480 | This report callback is called when the character collides with shapes and other characters. |
481 | |
482 | Setting this to NULL disables the callback. |
483 | |
484 | <b>Default:</b> NULL |
485 | |
486 | @see PxUserControllerHitReport |
487 | */ |
488 | PxUserControllerHitReport* reportCallback; |
489 | PX_DEPRECATED PxUserControllerHitReport* callback; //!< \deprecated |
490 | |
491 | /** |
492 | \brief Specifies a user behavior callback. |
493 | |
494 | This behavior callback is called to customize the controller's behavior w.r.t. touched shapes. |
495 | |
496 | Setting this to NULL disables the callback. |
497 | |
498 | <b>Default:</b> NULL |
499 | |
500 | @see PxControllerBehaviorCallback |
501 | */ |
502 | PxControllerBehaviorCallback* behaviorCallback; |
503 | |
504 | /** |
505 | \brief The non-walkable mode controls if a character controller slides or not on a non-walkable part. |
506 | |
507 | This is only used when slopeLimit is non zero. |
508 | |
509 | <b>Default:</b> PxControllerNonWalkableMode::ePREVENT_CLIMBING |
510 | |
511 | @see PxControllerNonWalkableMode |
512 | */ |
513 | PxControllerNonWalkableMode::Enum nonWalkableMode; |
514 | |
515 | /** |
516 | \brief The material for the actor associated with the controller. |
517 | |
518 | The controller internally creates a rigid body actor. This parameter specifies the material of the actor. |
519 | |
520 | <b>Default:</b> NULL |
521 | |
522 | @see PxMaterial |
523 | */ |
524 | PxMaterial* material; |
525 | |
526 | /** |
527 | \brief User specified data associated with the controller. |
528 | |
529 | <b>Default:</b> NULL |
530 | */ |
531 | void* userData; |
532 | |
533 | protected: |
534 | const PxControllerShapeType::Enum mType; //!< The type of the controller. This gets set by the derived class' ctor, the user should not have to change it. |
535 | |
536 | /** |
537 | \brief constructor sets to default. |
538 | */ |
539 | PX_INLINE PxControllerDesc(PxControllerShapeType::Enum); |
540 | PX_INLINE virtual ~PxControllerDesc(); |
541 | |
542 | /** |
543 | \brief copy constructor. |
544 | */ |
545 | PX_INLINE PxControllerDesc(const PxControllerDesc&); |
546 | |
547 | /** |
548 | \brief assignment operator. |
549 | */ |
550 | PX_INLINE PxControllerDesc& operator=(const PxControllerDesc&); |
551 | |
552 | PX_INLINE void copy(const PxControllerDesc&); |
553 | }; |
554 | |
555 | PX_INLINE PxControllerDesc::PxControllerDesc(PxControllerShapeType::Enum t) : mType(t) |
556 | { |
557 | upDirection = PxVec3(0.0f, 1.0f, 0.0f); |
558 | slopeLimit = 0.707f; |
559 | contactOffset = 0.1f; |
560 | stepOffset = 0.5f; |
561 | density = 10.0f; |
562 | scaleCoeff = 0.8f; |
563 | volumeGrowth = 1.5f; |
564 | reportCallback = NULL; |
565 | callback = NULL; |
566 | behaviorCallback = NULL; |
567 | userData = NULL; |
568 | nonWalkableMode = PxControllerNonWalkableMode::ePREVENT_CLIMBING; |
569 | position.x = PxExtended(0.0); |
570 | position.y = PxExtended(0.0); |
571 | position.z = PxExtended(0.0); |
572 | material = NULL; |
573 | invisibleWallHeight = 0.0f; |
574 | maxJumpHeight = 0.0f; |
575 | } |
576 | |
577 | PX_INLINE PxControllerDesc::PxControllerDesc(const PxControllerDesc& other) : mType(other.mType) |
578 | { |
579 | copy(other); |
580 | } |
581 | |
582 | PX_INLINE PxControllerDesc& PxControllerDesc::operator=(const PxControllerDesc& other) |
583 | { |
584 | copy(other); |
585 | return *this; |
586 | } |
587 | |
588 | PX_INLINE void PxControllerDesc::copy(const PxControllerDesc& other) |
589 | { |
590 | upDirection = other.upDirection; |
591 | slopeLimit = other.slopeLimit; |
592 | contactOffset = other.contactOffset; |
593 | stepOffset = other.stepOffset; |
594 | density = other.density; |
595 | scaleCoeff = other.scaleCoeff; |
596 | volumeGrowth = other.volumeGrowth; |
597 | reportCallback = other.reportCallback; |
598 | callback = other.callback; |
599 | behaviorCallback = other.behaviorCallback; |
600 | userData = other.userData; |
601 | nonWalkableMode = other.nonWalkableMode; |
602 | position.x = other.position.x; |
603 | position.y = other.position.y; |
604 | position.z = other.position.z; |
605 | material = other.material; |
606 | invisibleWallHeight = other.invisibleWallHeight; |
607 | maxJumpHeight = other.maxJumpHeight; |
608 | } |
609 | |
610 | PX_INLINE PxControllerDesc::~PxControllerDesc() |
611 | { |
612 | } |
613 | |
614 | PX_INLINE bool PxControllerDesc::isValid() const |
615 | { |
616 | if( mType!=PxControllerShapeType::eBOX |
617 | && mType!=PxControllerShapeType::eCAPSULE) |
618 | return false; |
619 | if(scaleCoeff<0.0f) return false; |
620 | if(volumeGrowth<1.0f) return false; |
621 | if(density<0.0f) return false; |
622 | if(slopeLimit<0.0f) return false; |
623 | if(stepOffset<0.0f) return false; |
624 | if(contactOffset<=0.0f) return false; |
625 | if(!material) return false; |
626 | |
627 | if(callback && !reportCallback) |
628 | { |
629 | (const_cast<PxControllerDesc*>(this))->reportCallback = callback; |
630 | PxGetFoundation().getErrorCallback().reportError(PxErrorCode::eDEBUG_WARNING, "PxControllerDesc::callback is deprecated, please use PxControllerDesc::reportCallback instead." , __FILE__, __LINE__); |
631 | } |
632 | return true; |
633 | } |
634 | |
635 | |
636 | /** |
637 | \brief Base class for character controllers. |
638 | |
639 | @see PxCapsuleController PxBoxController |
640 | */ |
641 | class PxController |
642 | { |
643 | public: |
644 | //********************************************************************* |
645 | // DEPRECATED FUNCTIONS: |
646 | // |
647 | // PX_DEPRECATED virtual void setInteraction(PxCCTInteractionMode::Enum flag) = 0; |
648 | // PX_DEPRECATED virtual PxCCTInteractionMode::Enum getInteraction() const = 0; |
649 | // PX_DEPRECATED virtual void setGroupsBitmask(PxU32 bitmask) = 0; |
650 | // PX_DEPRECATED virtual PxU32 getGroupsBitmask() const = 0; |
651 | // |
652 | // => replaced with: |
653 | // |
654 | // PxControllerFilters::mCCTFilterCallback. Please define a PxControllerFilterCallback object and emulate the old interaction mode there. |
655 | // |
656 | //********************************************************************* |
657 | |
658 | /** |
659 | \brief Return the type of controller |
660 | |
661 | @see PxControllerType |
662 | */ |
663 | virtual PxControllerShapeType::Enum getType() const = 0; |
664 | |
665 | /** |
666 | \brief Releases the controller. |
667 | */ |
668 | virtual void release() = 0; |
669 | |
670 | /** |
671 | \brief Moves the character using a "collide-and-slide" algorithm. |
672 | |
673 | \param[in] disp Displacement vector |
674 | \param[in] minDist The minimum travelled distance to consider. If travelled distance is smaller, the character doesn't move. |
675 | This is used to stop the recursive motion algorithm when remaining distance to travel is small. |
676 | \param[in] elapsedTime Time elapsed since last call |
677 | \param[in] filters User-defined filters for this move |
678 | \param[in] obstacles Potential additional obstacles the CCT should collide with. |
679 | \return Collision flags, collection of ::PxControllerCollisionFlags |
680 | */ |
681 | virtual PxControllerCollisionFlags move(const PxVec3& disp, PxF32 minDist, PxF32 elapsedTime, const PxControllerFilters& filters, const PxObstacleContext* obstacles=NULL) = 0; |
682 | |
683 | /** |
684 | \brief Sets controller's position. |
685 | |
686 | The position controlled by this function is the center of the collision shape. |
687 | |
688 | \warning This is a 'teleport' function, it doesn't check for collisions. |
689 | \warning The character's position must be such that it does not overlap the static geometry. |
690 | |
691 | To move the character under normal conditions use the #move() function. |
692 | |
693 | \param[in] position The new (center) positon for the controller. |
694 | \return Currently always returns true. |
695 | |
696 | @see PxControllerDesc.position getPosition() getFootPosition() setFootPosition() move() |
697 | */ |
698 | virtual bool setPosition(const PxExtendedVec3& position) = 0; |
699 | |
700 | /** |
701 | \brief Retrieve the raw position of the controller. |
702 | |
703 | The position retrieved by this function is the center of the collision shape. To retrieve the bottom position of the shape, |
704 | a.k.a. the foot position, use the getFootPosition() function. |
705 | |
706 | The position is updated by calls to move(). Calling this method without calling |
707 | move() will return the last position or the initial position of the controller. |
708 | |
709 | \return The controller's center position |
710 | |
711 | @see PxControllerDesc.position setPosition() getFootPosition() setFootPosition() move() |
712 | */ |
713 | virtual const PxExtendedVec3& getPosition() const = 0; |
714 | |
715 | /** |
716 | \brief Set controller's foot position. |
717 | |
718 | The position controlled by this function is the bottom of the collision shape, a.k.a. the foot position. |
719 | |
720 | \note The foot position takes the contact offset into account |
721 | |
722 | \warning This is a 'teleport' function, it doesn't check for collisions. |
723 | |
724 | To move the character under normal conditions use the #move() function. |
725 | |
726 | \param[in] position The new (bottom) positon for the controller. |
727 | \return Currently always returns true. |
728 | |
729 | @see PxControllerDesc.position setPosition() getPosition() getFootPosition() move() |
730 | */ |
731 | virtual bool (const PxExtendedVec3& position) = 0; |
732 | |
733 | /** |
734 | \brief Retrieve the "foot" position of the controller, i.e. the position of the bottom of the CCT's shape. |
735 | |
736 | \note The foot position takes the contact offset into account |
737 | |
738 | \return The controller's foot position |
739 | |
740 | @see PxControllerDesc.position setPosition() getPosition() setFootPosition() move() |
741 | */ |
742 | virtual PxExtendedVec3 () const = 0; |
743 | |
744 | /** |
745 | \brief Get the rigid body actor associated with this controller (see PhysX documentation). |
746 | The behavior upon manually altering this actor is undefined, you should primarily |
747 | use it for reading const properties. |
748 | |
749 | \return the actor associated with the controller. |
750 | */ |
751 | virtual PxRigidDynamic* getActor() const = 0; |
752 | |
753 | /** |
754 | \brief The step height. |
755 | |
756 | \param[in] offset The new step offset for the controller. |
757 | |
758 | @see PxControllerDesc.stepOffset |
759 | */ |
760 | virtual void setStepOffset(const PxF32 offset) =0; |
761 | |
762 | /** |
763 | \brief Retrieve the step height. |
764 | |
765 | \return The step offset for the controller. |
766 | |
767 | @see setStepOffset() |
768 | */ |
769 | virtual PxF32 getStepOffset() const =0; |
770 | |
771 | /** |
772 | \brief Sets the non-walkable mode for the CCT. |
773 | |
774 | \param[in] flag The new value of the non-walkable mode. |
775 | |
776 | \see PxControllerNonWalkableMode |
777 | */ |
778 | virtual void setNonWalkableMode(PxControllerNonWalkableMode::Enum flag) = 0; |
779 | |
780 | /** |
781 | \brief Retrieves the non-walkable mode for the CCT. |
782 | |
783 | \return The current non-walkable mode. |
784 | |
785 | \see PxControllerNonWalkableMode |
786 | */ |
787 | virtual PxControllerNonWalkableMode::Enum getNonWalkableMode() const = 0; |
788 | |
789 | /** |
790 | \brief Retrieve the contact offset. |
791 | |
792 | \return The contact offset for the controller. |
793 | |
794 | @see PxControllerDesc.contactOffset |
795 | */ |
796 | virtual PxF32 getContactOffset() const =0; |
797 | |
798 | /** |
799 | \brief Sets the contact offset. |
800 | |
801 | \param[in] offset The contact offset for the controller. |
802 | |
803 | @see PxControllerDesc.contactOffset |
804 | */ |
805 | virtual void setContactOffset(PxF32 offset) =0; |
806 | |
807 | /** |
808 | \brief Retrieve the 'up' direction. |
809 | |
810 | \return The up direction for the controller. |
811 | |
812 | @see PxControllerDesc.upDirection |
813 | */ |
814 | virtual PxVec3 getUpDirection() const =0; |
815 | |
816 | /** |
817 | \brief Sets the 'up' direction. |
818 | |
819 | \param[in] up The up direction for the controller. |
820 | |
821 | @see PxControllerDesc.upDirection |
822 | */ |
823 | virtual void setUpDirection(const PxVec3& up) =0; |
824 | |
825 | /** |
826 | \brief Retrieve the slope limit. |
827 | |
828 | \return The slope limit for the controller. |
829 | |
830 | @see PxControllerDesc.slopeLimit |
831 | */ |
832 | virtual PxF32 getSlopeLimit() const =0; |
833 | |
834 | /** |
835 | \brief Sets the slope limit. |
836 | |
837 | \note This feature can not be enabled at runtime, i.e. if the slope limit is zero when creating the CCT |
838 | (which disables the feature) then changing the slope limit at runtime will not have any effect, and the call |
839 | will be ignored. |
840 | |
841 | \param[in] slopeLimit The slope limit for the controller. |
842 | |
843 | @see PxControllerDesc.slopeLimit |
844 | */ |
845 | virtual void setSlopeLimit(PxF32 slopeLimit) =0; |
846 | |
847 | /** |
848 | \brief Flushes internal geometry cache. |
849 | |
850 | The character controller uses caching in order to speed up collision testing. The cache is |
851 | automatically flushed when a change to static objects is detected in the scene. For example when a |
852 | static shape is added, updated, or removed from the scene, the cache is automatically invalidated. |
853 | |
854 | However there may be situations that cannot be automatically detected, and those require manual |
855 | invalidation of the cache. Currently the user must call this when the filtering behavior changes (the |
856 | PxControllerFilters parameter of the PxController::move call). While the controller in principle |
857 | could detect a change in these parameters, it cannot detect a change in the behavior of the filtering |
858 | function. |
859 | |
860 | @see PxController.move |
861 | */ |
862 | virtual void invalidateCache() = 0; |
863 | |
864 | /** |
865 | \brief Retrieve the scene associated with the controller. |
866 | |
867 | \return The physics scene |
868 | */ |
869 | virtual PxScene* getScene() = 0; |
870 | |
871 | /** |
872 | \brief Returns the user data associated with this controller. |
873 | |
874 | \return The user pointer associated with the controller. |
875 | |
876 | @see PxControllerDesc.userData |
877 | */ |
878 | virtual void* getUserData() const = 0; |
879 | |
880 | /** |
881 | \brief Sets the user data associated with this controller. |
882 | |
883 | \param[in] userData The user pointer associated with the controller. |
884 | |
885 | @see PxControllerDesc.userData |
886 | */ |
887 | virtual void setUserData(void* userData) = 0; |
888 | |
889 | /** |
890 | \brief Returns information about the controller's internal state. |
891 | |
892 | \param[out] state The controller's internal state |
893 | |
894 | @see PxControllerState |
895 | */ |
896 | virtual void getState(PxControllerState& state) const = 0; |
897 | |
898 | /** |
899 | \brief Returns the controller's internal statistics. |
900 | |
901 | \param[out] stats The controller's internal statistics |
902 | |
903 | @see PxControllerStats |
904 | */ |
905 | virtual void getStats(PxControllerStats& stats) const = 0; |
906 | |
907 | /** |
908 | \brief Resizes the controller. |
909 | |
910 | This function attempts to resize the controller to a given size, while making sure the bottom |
911 | position of the controller remains constant. In other words the function modifies both the |
912 | height and the (center) position of the controller. This is a helper function that can be used |
913 | to implement a 'crouch' functionality for example. |
914 | |
915 | \param[in] height Desired controller's height |
916 | */ |
917 | virtual void resize(PxReal height) = 0; |
918 | |
919 | protected: |
920 | PX_INLINE PxController() {} |
921 | virtual ~PxController() {} |
922 | }; |
923 | |
924 | #ifndef PX_DOXYGEN |
925 | } // namespace physx |
926 | #endif |
927 | |
928 | /** @} */ |
929 | #endif |
930 | |