| 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 | #ifndef PX_JOINTCONSTRAINT_H |
| 31 | #define PX_JOINTCONSTRAINT_H |
| 32 | /** \addtogroup extensions |
| 33 | @{ |
| 34 | */ |
| 35 | |
| 36 | #include "foundation/PxTransform.h" |
| 37 | #include "PxRigidActor.h" |
| 38 | #include "PxConstraint.h" |
| 39 | #include "common/PxBase.h" |
| 40 | |
| 41 | #if !PX_DOXYGEN |
| 42 | namespace physx |
| 43 | { |
| 44 | #endif |
| 45 | |
| 46 | class PxRigidActor; |
| 47 | class PxScene; |
| 48 | class PxPhysics; |
| 49 | class PxConstraint; |
| 50 | |
| 51 | /** |
| 52 | \brief an enumeration of PhysX' built-in joint types |
| 53 | |
| 54 | @see PxJoint |
| 55 | */ |
| 56 | struct PxJointConcreteType |
| 57 | { |
| 58 | enum Enum |
| 59 | { |
| 60 | eSPHERICAL = PxConcreteType::eFIRST_PHYSX_EXTENSION, |
| 61 | eREVOLUTE, |
| 62 | ePRISMATIC, |
| 63 | eFIXED, |
| 64 | eDISTANCE, |
| 65 | eD6, |
| 66 | eCONTACT, |
| 67 | eLast |
| 68 | }; |
| 69 | }; |
| 70 | |
| 71 | PX_DEFINE_TYPEINFO(PxJoint, PxConcreteType::eUNDEFINED) |
| 72 | PX_DEFINE_TYPEINFO(PxD6Joint, PxJointConcreteType::eD6) |
| 73 | PX_DEFINE_TYPEINFO(PxDistanceJoint, PxJointConcreteType::eDISTANCE) |
| 74 | PX_DEFINE_TYPEINFO(PxContactJoint, PxJointConcreteType::eCONTACT) |
| 75 | PX_DEFINE_TYPEINFO(PxFixedJoint, PxJointConcreteType::eFIXED) |
| 76 | PX_DEFINE_TYPEINFO(PxPrismaticJoint, PxJointConcreteType::ePRISMATIC) |
| 77 | PX_DEFINE_TYPEINFO(PxRevoluteJoint, PxJointConcreteType::eREVOLUTE) |
| 78 | PX_DEFINE_TYPEINFO(PxSphericalJoint, PxJointConcreteType::eSPHERICAL) |
| 79 | |
| 80 | |
| 81 | /** |
| 82 | \brief an enumeration for specifying one or other of the actors referenced by a joint |
| 83 | |
| 84 | @see PxJoint |
| 85 | */ |
| 86 | |
| 87 | struct PxJointActorIndex |
| 88 | { |
| 89 | enum Enum |
| 90 | { |
| 91 | eACTOR0, |
| 92 | eACTOR1, |
| 93 | COUNT |
| 94 | }; |
| 95 | }; |
| 96 | |
| 97 | /** |
| 98 | \brief a base interface providing common functionality for PhysX joints |
| 99 | */ |
| 100 | |
| 101 | class PxJoint : public PxBase |
| 102 | { |
| 103 | //= ATTENTION! ===================================================================================== |
| 104 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
| 105 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
| 106 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
| 107 | // accordingly. |
| 108 | //================================================================================================== |
| 109 | public: |
| 110 | |
| 111 | /** |
| 112 | \brief Set the actors for this joint. |
| 113 | |
| 114 | An actor may be NULL to indicate the world frame. At most one of the actors may be NULL. |
| 115 | |
| 116 | \param[in] actor0 the first actor. |
| 117 | \param[in] actor1 the second actor |
| 118 | |
| 119 | @see getActors() |
| 120 | */ |
| 121 | virtual void setActors(PxRigidActor* actor0, PxRigidActor* actor1) = 0; |
| 122 | |
| 123 | /** |
| 124 | \brief Get the actors for this joint. |
| 125 | |
| 126 | \param[out] actor0 the first actor. |
| 127 | \param[out] actor1 the second actor |
| 128 | |
| 129 | @see setActors() |
| 130 | */ |
| 131 | virtual void getActors(PxRigidActor*& actor0, PxRigidActor*& actor1) const = 0; |
| 132 | |
| 133 | /** |
| 134 | \brief Set the joint local pose for an actor. |
| 135 | |
| 136 | This is the relative pose which locates the joint frame relative to the actor. |
| 137 | |
| 138 | \param[in] actor 0 for the first actor, 1 for the second actor. |
| 139 | \param[in] localPose the local pose for the actor this joint |
| 140 | |
| 141 | @see getLocalPose() |
| 142 | */ |
| 143 | virtual void setLocalPose(PxJointActorIndex::Enum actor, const PxTransform& localPose) = 0; |
| 144 | |
| 145 | /** |
| 146 | \brief get the joint local pose for an actor. |
| 147 | |
| 148 | \param[in] actor 0 for the first actor, 1 for the second actor. |
| 149 | |
| 150 | return the local pose for this joint |
| 151 | |
| 152 | @see setLocalPose() |
| 153 | */ |
| 154 | virtual PxTransform getLocalPose(PxJointActorIndex::Enum actor) const = 0; |
| 155 | |
| 156 | /** |
| 157 | \brief get the relative pose for this joint |
| 158 | |
| 159 | This function returns the pose of the joint frame of actor1 relative to actor0 |
| 160 | |
| 161 | */ |
| 162 | virtual PxTransform getRelativeTransform() const = 0; |
| 163 | |
| 164 | /** |
| 165 | \brief get the relative linear velocity of the joint |
| 166 | |
| 167 | This function returns the linear velocity of the origin of the constraint frame of actor1, relative to the origin of the constraint |
| 168 | frame of actor0. The value is returned in the constraint frame of actor0 |
| 169 | */ |
| 170 | virtual PxVec3 getRelativeLinearVelocity() const = 0; |
| 171 | |
| 172 | /** |
| 173 | \brief get the relative angular velocity of the joint |
| 174 | |
| 175 | This function returns the angular velocity of actor1 relative to actor0. The value is returned in the constraint frame of actor0 |
| 176 | */ |
| 177 | virtual PxVec3 getRelativeAngularVelocity() const = 0; |
| 178 | |
| 179 | /** |
| 180 | \brief set the break force for this joint. |
| 181 | |
| 182 | if the constraint force or torque on the joint exceeds the specified values, the joint will break, |
| 183 | at which point it will not constrain the two actors and the flag PxConstraintFlag::eBROKEN will be set. The |
| 184 | force and torque are measured in the joint frame of the first actor |
| 185 | |
| 186 | \param[in] force the maximum force the joint can apply before breaking |
| 187 | \param[in] torque the maximum torque the joint can apply before breaking |
| 188 | */ |
| 189 | virtual void setBreakForce(PxReal force, PxReal torque) = 0; |
| 190 | |
| 191 | /** |
| 192 | \brief get the break force for this joint. |
| 193 | |
| 194 | \param[out] force the maximum force the joint can apply before breaking |
| 195 | \param[out] torque the maximum torque the joint can apply before breaking |
| 196 | |
| 197 | @see setBreakForce() |
| 198 | */ |
| 199 | virtual void getBreakForce(PxReal& force, PxReal& torque) const = 0; |
| 200 | |
| 201 | /** |
| 202 | \brief set the constraint flags for this joint. |
| 203 | |
| 204 | \param[in] flags the constraint flags |
| 205 | |
| 206 | @see PxConstraintFlag |
| 207 | */ |
| 208 | virtual void setConstraintFlags(PxConstraintFlags flags) = 0; |
| 209 | |
| 210 | /** |
| 211 | \brief set a constraint flags for this joint to a specified value. |
| 212 | |
| 213 | \param[in] flag the constraint flag |
| 214 | \param[in] value the value to which to set the flag |
| 215 | |
| 216 | @see PxConstraintFlag |
| 217 | */ |
| 218 | virtual void setConstraintFlag(PxConstraintFlag::Enum flag, bool value) = 0; |
| 219 | |
| 220 | /** |
| 221 | \brief get the constraint flags for this joint. |
| 222 | |
| 223 | \return the constraint flags |
| 224 | |
| 225 | @see PxConstraintFlag |
| 226 | */ |
| 227 | virtual PxConstraintFlags getConstraintFlags() const = 0; |
| 228 | |
| 229 | /** |
| 230 | \brief set the inverse mass scale for actor0. |
| 231 | |
| 232 | \param[in] invMassScale the scale to apply to the inverse mass of actor 0 for resolving this constraint |
| 233 | |
| 234 | @see getInvMassScale0 |
| 235 | */ |
| 236 | virtual void setInvMassScale0(PxReal invMassScale) = 0; |
| 237 | |
| 238 | /** |
| 239 | \brief get the inverse mass scale for actor0. |
| 240 | |
| 241 | \return inverse mass scale for actor0 |
| 242 | |
| 243 | @see setInvMassScale0 |
| 244 | */ |
| 245 | virtual PxReal getInvMassScale0() const = 0; |
| 246 | |
| 247 | /** |
| 248 | \brief set the inverse inertia scale for actor0. |
| 249 | |
| 250 | \param[in] invInertiaScale the scale to apply to the inverse inertia of actor0 for resolving this constraint |
| 251 | |
| 252 | @see getInvMassScale0 |
| 253 | */ |
| 254 | virtual void setInvInertiaScale0(PxReal invInertiaScale) = 0; |
| 255 | |
| 256 | /** |
| 257 | \brief get the inverse inertia scale for actor0. |
| 258 | |
| 259 | \return inverse inertia scale for actor0 |
| 260 | |
| 261 | @see setInvInertiaScale0 |
| 262 | */ |
| 263 | virtual PxReal getInvInertiaScale0() const = 0; |
| 264 | |
| 265 | /** |
| 266 | \brief set the inverse mass scale for actor1. |
| 267 | |
| 268 | \param[in] invMassScale the scale to apply to the inverse mass of actor 1 for resolving this constraint |
| 269 | |
| 270 | @see getInvMassScale1 |
| 271 | */ |
| 272 | virtual void setInvMassScale1(PxReal invMassScale) = 0; |
| 273 | |
| 274 | /** |
| 275 | \brief get the inverse mass scale for actor1. |
| 276 | |
| 277 | \return inverse mass scale for actor1 |
| 278 | |
| 279 | @see setInvMassScale1 |
| 280 | */ |
| 281 | virtual PxReal getInvMassScale1() const = 0; |
| 282 | |
| 283 | /** |
| 284 | \brief set the inverse inertia scale for actor1. |
| 285 | |
| 286 | \param[in] invInertiaScale the scale to apply to the inverse inertia of actor1 for resolving this constraint |
| 287 | |
| 288 | @see getInvInertiaScale1 |
| 289 | */ |
| 290 | virtual void setInvInertiaScale1(PxReal invInertiaScale) = 0; |
| 291 | |
| 292 | /** |
| 293 | \brief get the inverse inertia scale for actor1. |
| 294 | |
| 295 | \return inverse inertia scale for actor1 |
| 296 | |
| 297 | @see setInvInertiaScale1 |
| 298 | */ |
| 299 | virtual PxReal getInvInertiaScale1() const = 0; |
| 300 | |
| 301 | /** |
| 302 | \brief Retrieves the PxConstraint corresponding to this joint. |
| 303 | |
| 304 | This can be used to determine, among other things, the force applied at the joint. |
| 305 | |
| 306 | \return the constraint |
| 307 | */ |
| 308 | virtual PxConstraint* getConstraint() const = 0; |
| 309 | |
| 310 | /** |
| 311 | \brief Sets a name string for the object that can be retrieved with getName(). |
| 312 | |
| 313 | This is for debugging and is not used by the SDK. The string is not copied by the SDK, |
| 314 | only the pointer is stored. |
| 315 | |
| 316 | \param[in] name String to set the objects name to. |
| 317 | |
| 318 | @see getName() |
| 319 | */ |
| 320 | virtual void setName(const char* name) = 0; |
| 321 | |
| 322 | /** |
| 323 | \brief Retrieves the name string set with setName(). |
| 324 | |
| 325 | \return Name string associated with object. |
| 326 | |
| 327 | @see setName() |
| 328 | */ |
| 329 | virtual const char* getName() const = 0; |
| 330 | |
| 331 | /** |
| 332 | \brief Deletes the joint. |
| 333 | |
| 334 | \note This call does not wake up the connected rigid bodies. |
| 335 | */ |
| 336 | virtual void release() = 0; |
| 337 | |
| 338 | /** |
| 339 | \brief Retrieves the scene which this joint belongs to. |
| 340 | |
| 341 | \return Owner Scene. NULL if not part of a scene. |
| 342 | |
| 343 | @see PxScene |
| 344 | */ |
| 345 | virtual PxScene* getScene() const = 0; |
| 346 | |
| 347 | void* userData; //!< user can assign this to whatever, usually to create a 1:1 relationship with a user object. |
| 348 | |
| 349 | //serialization |
| 350 | |
| 351 | /** |
| 352 | \brief Put class meta data in stream, used for serialization |
| 353 | */ |
| 354 | static void getBinaryMetaData(PxOutputStream& stream); |
| 355 | |
| 356 | //~serialization |
| 357 | |
| 358 | protected: |
| 359 | virtual ~PxJoint() {} |
| 360 | |
| 361 | //serialization |
| 362 | |
| 363 | /** |
| 364 | \brief Constructor |
| 365 | */ |
| 366 | PX_INLINE PxJoint(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags), userData(NULL) {} |
| 367 | |
| 368 | /** |
| 369 | \brief Deserialization constructor |
| 370 | */ |
| 371 | PX_INLINE PxJoint(PxBaseFlags baseFlags) : PxBase(baseFlags) {} |
| 372 | |
| 373 | /** |
| 374 | \brief Returns whether a given type name matches with the type of this instance |
| 375 | */ |
| 376 | virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxJoint" , s2: name) || PxBase::isKindOf(superClass: name); } |
| 377 | |
| 378 | //~serialization |
| 379 | }; |
| 380 | |
| 381 | class PxSpring |
| 382 | { |
| 383 | //= ATTENTION! ===================================================================================== |
| 384 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
| 385 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
| 386 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
| 387 | // accordingly. |
| 388 | //================================================================================================== |
| 389 | public: |
| 390 | |
| 391 | PxReal stiffness; //!< the spring strength of the drive: that is, the force proportional to the position error |
| 392 | PxReal damping; //!< the damping strength of the drive: that is, the force proportional to the velocity error |
| 393 | |
| 394 | PxSpring(PxReal stiffness_, PxReal damping_): stiffness(stiffness_), damping(damping_) {} |
| 395 | }; |
| 396 | |
| 397 | |
| 398 | #if !PX_DOXYGEN |
| 399 | } // namespace physx |
| 400 | #endif |
| 401 | |
| 402 | /** \brief Helper function to setup a joint's global frame |
| 403 | |
| 404 | This replaces the following functions from previous SDK versions: |
| 405 | |
| 406 | void NxJointDesc::setGlobalAnchor(const NxVec3& wsAnchor); |
| 407 | void NxJointDesc::setGlobalAxis(const NxVec3& wsAxis); |
| 408 | |
| 409 | The function sets the joint's localPose using world-space input parameters. |
| 410 | |
| 411 | \param[in] wsAnchor Global frame anchor point. <b>Range:</b> position vector |
| 412 | \param[in] wsAxis Global frame axis. <b>Range:</b> direction vector |
| 413 | \param[in,out] joint Joint having its global frame set. |
| 414 | */ |
| 415 | |
| 416 | PX_C_EXPORT void PX_CALL_CONV PxSetJointGlobalFrame(physx::PxJoint& joint, const physx::PxVec3* wsAnchor, const physx::PxVec3* wsAxis); |
| 417 | |
| 418 | /** @} */ |
| 419 | #endif |
| 420 | |