| 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 | #ifndef PX_PHYSICS_CCT_CAPSULE_CONTROLLER |
| 15 | #define PX_PHYSICS_CCT_CAPSULE_CONTROLLER |
| 16 | /** \addtogroup character |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "characterkinematic/PxCharacter.h" |
| 21 | #include "characterkinematic/PxController.h" |
| 22 | |
| 23 | #ifndef PX_DOXYGEN |
| 24 | namespace physx |
| 25 | { |
| 26 | #endif |
| 27 | |
| 28 | struct PxCapsuleClimbingMode |
| 29 | { |
| 30 | enum Enum |
| 31 | { |
| 32 | eEASY, //!< Standard mode, let the capsule climb over surfaces according to impact normal |
| 33 | eCONSTRAINED, //!< Constrained mode, try to limit climbing according to the step offset |
| 34 | |
| 35 | eLAST |
| 36 | }; |
| 37 | }; |
| 38 | |
| 39 | /** |
| 40 | \brief A descriptor for a capsule character controller. |
| 41 | |
| 42 | @see PxCapsuleController PxControllerDesc |
| 43 | */ |
| 44 | class PxCapsuleControllerDesc : public PxControllerDesc |
| 45 | { |
| 46 | public: |
| 47 | /** |
| 48 | \brief constructor sets to default. |
| 49 | */ |
| 50 | PX_INLINE PxCapsuleControllerDesc (); |
| 51 | PX_INLINE virtual ~PxCapsuleControllerDesc () {} |
| 52 | |
| 53 | /** |
| 54 | \brief copy constructor. |
| 55 | */ |
| 56 | PX_INLINE PxCapsuleControllerDesc(const PxCapsuleControllerDesc&); |
| 57 | |
| 58 | /** |
| 59 | \brief assignment operator. |
| 60 | */ |
| 61 | PX_INLINE PxCapsuleControllerDesc& operator=(const PxCapsuleControllerDesc&); |
| 62 | |
| 63 | /** |
| 64 | \brief (re)sets the structure to the default. |
| 65 | */ |
| 66 | PX_INLINE virtual void setToDefault(); |
| 67 | /** |
| 68 | \brief returns true if the current settings are valid |
| 69 | |
| 70 | \return True if the descriptor is valid. |
| 71 | */ |
| 72 | PX_INLINE virtual bool isValid() const; |
| 73 | |
| 74 | /** |
| 75 | \brief The radius of the capsule |
| 76 | |
| 77 | <b>Default:</b> 0.0 |
| 78 | |
| 79 | @see PxCapsuleController |
| 80 | */ |
| 81 | PxF32 radius; |
| 82 | |
| 83 | /** |
| 84 | \brief The height of the controller |
| 85 | |
| 86 | <b>Default:</b> 0.0 |
| 87 | |
| 88 | @see PxCapsuleController |
| 89 | */ |
| 90 | PxF32 height; |
| 91 | |
| 92 | /** |
| 93 | \brief The climbing mode |
| 94 | |
| 95 | <b>Default:</b> PxCapsuleClimbingMode::eEASY |
| 96 | |
| 97 | @see PxCapsuleController |
| 98 | */ |
| 99 | PxCapsuleClimbingMode::Enum climbingMode; |
| 100 | |
| 101 | protected: |
| 102 | PX_INLINE void copy(const PxCapsuleControllerDesc&); |
| 103 | }; |
| 104 | |
| 105 | PX_INLINE PxCapsuleControllerDesc::PxCapsuleControllerDesc () : PxControllerDesc(PxControllerShapeType::eCAPSULE) |
| 106 | { |
| 107 | radius = height = 0.0f; |
| 108 | climbingMode = PxCapsuleClimbingMode::eEASY; |
| 109 | } |
| 110 | |
| 111 | PX_INLINE PxCapsuleControllerDesc::PxCapsuleControllerDesc(const PxCapsuleControllerDesc& other) : PxControllerDesc(other) |
| 112 | { |
| 113 | copy(other); |
| 114 | } |
| 115 | |
| 116 | PX_INLINE PxCapsuleControllerDesc& PxCapsuleControllerDesc::operator=(const PxCapsuleControllerDesc& other) |
| 117 | { |
| 118 | PxControllerDesc::operator=(other); |
| 119 | copy(other); |
| 120 | return *this; |
| 121 | } |
| 122 | |
| 123 | PX_INLINE void PxCapsuleControllerDesc::copy(const PxCapsuleControllerDesc& other) |
| 124 | { |
| 125 | radius = other.radius; |
| 126 | height = other.height; |
| 127 | climbingMode = other.climbingMode; |
| 128 | } |
| 129 | |
| 130 | PX_INLINE void PxCapsuleControllerDesc::setToDefault() |
| 131 | { |
| 132 | *this = PxCapsuleControllerDesc(); |
| 133 | } |
| 134 | |
| 135 | PX_INLINE bool PxCapsuleControllerDesc::isValid() const |
| 136 | { |
| 137 | if(!PxControllerDesc::isValid()) return false; |
| 138 | if(radius<=0.0f) return false; |
| 139 | if(height<=0.0f) return false; |
| 140 | if(stepOffset>height+radius*2.0f) return false; // Prevents obvious mistakes |
| 141 | return true; |
| 142 | } |
| 143 | /** |
| 144 | \brief A capsule character controller. |
| 145 | |
| 146 | The capsule is defined as a position, a vertical height, and a radius. |
| 147 | The height is the distance between the two sphere centers at the end of the capsule. |
| 148 | In other words: |
| 149 | |
| 150 | p = pos (returned by controller)<br> |
| 151 | h = height<br> |
| 152 | r = radius<br> |
| 153 | |
| 154 | p = center of capsule<br> |
| 155 | top sphere center = p.y + h*0.5<br> |
| 156 | bottom sphere center = p.y - h*0.5<br> |
| 157 | top capsule point = p.y + h*0.5 + r<br> |
| 158 | bottom capsule point = p.y - h*0.5 - r<br> |
| 159 | */ |
| 160 | class PxCapsuleController : public PxController |
| 161 | { |
| 162 | public: |
| 163 | |
| 164 | /** |
| 165 | \brief Gets controller's radius. |
| 166 | |
| 167 | \return The radius of the controller. |
| 168 | |
| 169 | @see PxCapsuleControllerDesc.radius setRadius() |
| 170 | */ |
| 171 | virtual PxF32 getRadius() const = 0; |
| 172 | |
| 173 | /** |
| 174 | \brief Sets controller's radius. |
| 175 | |
| 176 | \warning this doesn't check for collisions. |
| 177 | |
| 178 | \param[in] radius The new radius for the controller. |
| 179 | \return Currently always true. |
| 180 | |
| 181 | @see PxCapsuleControllerDesc.radius getRadius() |
| 182 | */ |
| 183 | virtual bool setRadius(PxF32 radius) = 0; |
| 184 | |
| 185 | /** |
| 186 | \brief Gets controller's height. |
| 187 | |
| 188 | \return The height of the capsule controller. |
| 189 | |
| 190 | @see PxCapsuleControllerDesc.height setHeight() |
| 191 | */ |
| 192 | virtual PxF32 getHeight() const = 0; |
| 193 | |
| 194 | /** |
| 195 | \brief Resets controller's height. |
| 196 | |
| 197 | \warning this doesn't check for collisions. |
| 198 | |
| 199 | \param[in] height The new height for the controller. |
| 200 | \return Currently always true. |
| 201 | |
| 202 | @see PxCapsuleControllerDesc.height getHeight() |
| 203 | */ |
| 204 | virtual bool setHeight(PxF32 height) = 0; |
| 205 | |
| 206 | /** |
| 207 | \brief Gets controller's climbing mode. |
| 208 | |
| 209 | \return The capsule controller's climbing mode. |
| 210 | |
| 211 | @see PxCapsuleControllerDesc.climbingMode setClimbingMode() |
| 212 | */ |
| 213 | virtual PxCapsuleClimbingMode::Enum getClimbingMode() const = 0; |
| 214 | |
| 215 | /** |
| 216 | \brief Sets controller's climbing mode. |
| 217 | |
| 218 | \param[in] mode The capsule controller's climbing mode. |
| 219 | |
| 220 | @see PxCapsuleControllerDesc.climbingMode getClimbingMode() |
| 221 | */ |
| 222 | virtual bool setClimbingMode(PxCapsuleClimbingMode::Enum mode) = 0; |
| 223 | |
| 224 | protected: |
| 225 | PX_INLINE PxCapsuleController() {} |
| 226 | virtual ~PxCapsuleController() {} |
| 227 | }; |
| 228 | |
| 229 | #ifndef PX_DOXYGEN |
| 230 | } // namespace physx |
| 231 | #endif |
| 232 | |
| 233 | /** @} */ |
| 234 | #endif |
| 235 | |