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