1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsPhysXPrerequisites.h" |
6 | #include "Physics/BsCharacterController.h" |
7 | #include "PxPhysics.h" |
8 | #include "characterkinematic/PxCapsuleController.h" |
9 | |
10 | namespace bs |
11 | { |
12 | /** @addtogroup PhysX |
13 | * @{ |
14 | */ |
15 | |
16 | /** PhysX specific implementation if a CharacterController. */ |
17 | class PhysXCharacterController : public CharacterController |
18 | , physx::PxUserControllerHitReport |
19 | , physx::PxQueryFilterCallback |
20 | , physx::PxControllerFilterCallback |
21 | { |
22 | public: |
23 | PhysXCharacterController(physx::PxControllerManager* manager, const CHAR_CONTROLLER_DESC& desc); |
24 | ~PhysXCharacterController(); |
25 | |
26 | /** @copydoc CharacterController::move */ |
27 | CharacterCollisionFlags move(const Vector3& displacement) override; |
28 | |
29 | /** @copydoc CharacterController::getPosition */ |
30 | Vector3 getPosition() const override; |
31 | |
32 | /** @copydoc CharacterController::setPosition */ |
33 | void setPosition(const Vector3& position) override; |
34 | |
35 | /** @copydoc CharacterController::getFootPosition */ |
36 | Vector3 () const override; |
37 | |
38 | /** @copydoc CharacterController::setFootPosition */ |
39 | void (const Vector3& position) override; |
40 | |
41 | /** @copydoc CharacterController::getRadius */ |
42 | float getRadius() const override; |
43 | |
44 | /** @copydoc CharacterController::setRadius */ |
45 | void setRadius(float radius) override; |
46 | |
47 | /** @copydoc CharacterController::getHeight */ |
48 | float getHeight() const override; |
49 | |
50 | /** @copydoc CharacterController::setHeight */ |
51 | void setHeight(float height) override; |
52 | |
53 | /** @copydoc CharacterController::getUp */ |
54 | Vector3 getUp() const override; |
55 | |
56 | /** @copydoc CharacterController::setUp */ |
57 | void setUp(const Vector3& up) override; |
58 | |
59 | /** @copydoc CharacterController::getClimbingMode */ |
60 | CharacterClimbingMode getClimbingMode() const override; |
61 | |
62 | /** @copydoc CharacterController::setClimbingMode */ |
63 | void setClimbingMode(CharacterClimbingMode mode) override; |
64 | |
65 | /** @copydoc CharacterController::getNonWalkableMode */ |
66 | CharacterNonWalkableMode getNonWalkableMode() const override; |
67 | |
68 | /** @copydoc CharacterController::setNonWalkableMode */ |
69 | void setNonWalkableMode(CharacterNonWalkableMode mode) override; |
70 | |
71 | /** @copydoc CharacterController::getMinMoveDistance */ |
72 | float getMinMoveDistance() const override; |
73 | |
74 | /** @copydoc CharacterController::setMinMoveDistance */ |
75 | void setMinMoveDistance(float value) override; |
76 | |
77 | /** @copydoc CharacterController::getContactOffset */ |
78 | float getContactOffset() const override; |
79 | |
80 | /** @copydoc CharacterController::setContactOffset */ |
81 | void setContactOffset(float value) override; |
82 | |
83 | /** @copydoc CharacterController::getStepOffset */ |
84 | float getStepOffset() const override; |
85 | |
86 | /** @copydoc CharacterController::setStepOffset */ |
87 | void setStepOffset(float value) override; |
88 | |
89 | /** @copydoc CharacterController::getSlopeLimit */ |
90 | Radian getSlopeLimit() const override; |
91 | |
92 | /** @copydoc CharacterController::setSlopeLimit */ |
93 | void setSlopeLimit(Radian value) override; |
94 | |
95 | private: |
96 | /** @copydoc physx::PxUserControllerHitReport::onShapeHit */ |
97 | void onShapeHit(const physx::PxControllerShapeHit& hit) override; |
98 | |
99 | /** @copydoc physx::PxUserControllerHitReport::onControllerHit */ |
100 | void onControllerHit(const physx::PxControllersHit& hit) override; |
101 | |
102 | /** @copydoc physx::PxUserControllerHitReport::onObstacleHit */ |
103 | void onObstacleHit(const physx::PxControllerObstacleHit& hit) override { /* Do nothing */ }; |
104 | |
105 | /** @copydoc physx::PxQueryFilterCallback::preFilter */ |
106 | physx::PxQueryHitType::Enum preFilter(const physx::PxFilterData& filterData, const physx::PxShape* shape, |
107 | const physx::PxRigidActor* actor, physx::PxHitFlags& queryFlags) override; |
108 | |
109 | /** @copydoc physx::PxQueryFilterCallback::postFilter */ |
110 | physx::PxQueryHitType::Enum postFilter(const physx::PxFilterData& filterData, |
111 | const physx::PxQueryHit& hit) override; |
112 | |
113 | /** @copydoc physx::PxControllerFilterCallback::filter */ |
114 | bool filter(const physx::PxController& a, const physx::PxController& b) override; |
115 | |
116 | physx::PxCapsuleController* mController = nullptr; |
117 | float mMinMoveDistance = 0.0f; |
118 | float mLastMoveCall = 0.0f; |
119 | }; |
120 | |
121 | /** @} */ |
122 | } |