| 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_NX_CONSTRAINT |
| 15 | #define PX_PHYSICS_NX_CONSTRAINT |
| 16 | |
| 17 | /** \addtogroup physics |
| 18 | @{ |
| 19 | */ |
| 20 | |
| 21 | #include "PxPhysXConfig.h" |
| 22 | #include "PxConstraintDesc.h" |
| 23 | #include "common/PxBase.h" |
| 24 | |
| 25 | #ifndef PX_DOXYGEN |
| 26 | namespace physx |
| 27 | { |
| 28 | #endif |
| 29 | |
| 30 | class PxRigidActor; |
| 31 | class PxScene; |
| 32 | class PxConstraintConnector; |
| 33 | |
| 34 | /** |
| 35 | \brief a table of function pointers for a constraint |
| 36 | |
| 37 | @see PxConstraint |
| 38 | */ |
| 39 | |
| 40 | /** |
| 41 | \brief constraint flags |
| 42 | |
| 43 | \note eBROKEN is a read only flag |
| 44 | */ |
| 45 | |
| 46 | struct PxConstraintFlag |
| 47 | { |
| 48 | enum Enum |
| 49 | { |
| 50 | eBROKEN = 1<<0, //!< whether the constraint is broken |
| 51 | ePROJECT_TO_ACTOR0 = 1<<1, //!< whether actor1 should get projected to actor0 for this constraint (note: projection of a static/kinematic actor to a dynamic actor will be ignored) |
| 52 | ePROJECT_TO_ACTOR1 = 1<<2, //!< whether actor0 should get projected to actor1 for this constraint (note: projection of a static/kinematic actor to a dynamic actor will be ignored) |
| 53 | ePROJECTION = ePROJECT_TO_ACTOR0 | ePROJECT_TO_ACTOR1, //!< whether the actors should get projected for this constraint (the direction will be chosen by PhysX) |
| 54 | eCOLLISION_ENABLED = 1<<3, //!< whether contacts should be generated between the objects this constraint constrains |
| 55 | eREPORTING = 1<<4, //!< whether this constraint should generate force reports. DEPRECATED, as constraints always generate reports |
| 56 | eVISUALIZATION = 1<<5, //!< whether this constraint should be visualized, if constraint visualization is turned on |
| 57 | eDRIVE_LIMITS_ARE_FORCES = 1<<6, //!< limits for drive strength are forces rather than impulses |
| 58 | eDEPRECATED_32_COMPATIBILITY= 1<<7, //!< legacy compatibility flag for 3.3; see user guide. This flag must not be set in order for drives to conform to an implicit spring model |
| 59 | eIMPROVED_SLERP = 1<<8 //!< perform preprocessing for improved accuracy on D6 Slerp Drive (this flag will be removed in a future release when preprocessing is no longer required) |
| 60 | }; |
| 61 | }; |
| 62 | |
| 63 | /** |
| 64 | \brief constraint flags |
| 65 | @see PxConstraintFlag |
| 66 | */ |
| 67 | |
| 68 | typedef PxFlags<PxConstraintFlag::Enum, PxU16> PxConstraintFlags; |
| 69 | PX_FLAGS_OPERATORS(PxConstraintFlag::Enum, PxU16) |
| 70 | |
| 71 | |
| 72 | struct PxConstraintShaderTable |
| 73 | { |
| 74 | enum |
| 75 | { |
| 76 | eMAX_SOLVERPREPSPU_BYTESIZE=19056 |
| 77 | }; |
| 78 | |
| 79 | enum |
| 80 | { |
| 81 | eMAX_SOLVERPRPEP_DATASIZE=400 |
| 82 | }; |
| 83 | |
| 84 | PxConstraintSolverPrep solverPrep; //< solver constraint generation function |
| 85 | void* solverPrepSpu; //< spu-optimized solver constraint generation function |
| 86 | PxU32 solverPrepSpuByteSize; //< code size of the spu-optimized solver constraint generation function |
| 87 | PxConstraintProject project; //< constraint projection function |
| 88 | PxConstraintVisualize visualize; //< constraint visualization function |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | /** |
| 93 | \brief A plugin class for implementing constraints |
| 94 | |
| 95 | @see PxPhysics.createConstraint |
| 96 | */ |
| 97 | |
| 98 | class PxConstraint : public PxBase |
| 99 | { |
| 100 | public: |
| 101 | |
| 102 | /** |
| 103 | \brief Releases a PxConstraint instance. |
| 104 | |
| 105 | \note This call does not wake up the connected rigid bodies. |
| 106 | |
| 107 | @see PxPhysics.createConstraint, PxBase.release() |
| 108 | */ |
| 109 | virtual void release() = 0; |
| 110 | |
| 111 | /** |
| 112 | \brief Retrieves the scene which this constraint belongs to. |
| 113 | |
| 114 | \return Owner Scene. NULL if not part of a scene. |
| 115 | |
| 116 | @see PxScene |
| 117 | */ |
| 118 | virtual PxScene* getScene() const = 0; |
| 119 | |
| 120 | /** |
| 121 | \brief Retrieves the actors for this constraint. |
| 122 | |
| 123 | \param[out] actor0 a reference to the pointer for the first actor |
| 124 | \param[out] actor1 a reference to the pointer for the second actor |
| 125 | |
| 126 | @see PxActor |
| 127 | */ |
| 128 | |
| 129 | virtual void getActors(PxRigidActor*& actor0, PxRigidActor*& actor1) const = 0; |
| 130 | |
| 131 | |
| 132 | /** |
| 133 | \brief Sets the actors for this constraint. |
| 134 | |
| 135 | \param[in] actor0 a reference to the pointer for the first actor |
| 136 | \param[in] actor1 a reference to the pointer for the second actor |
| 137 | |
| 138 | @see PxActor |
| 139 | */ |
| 140 | |
| 141 | virtual void setActors(PxRigidActor* actor0, PxRigidActor* actor1) = 0; |
| 142 | |
| 143 | /** |
| 144 | \brief Notify the scene that the constraint shader data has been updated by the application |
| 145 | */ |
| 146 | |
| 147 | virtual void markDirty() = 0; |
| 148 | |
| 149 | /** |
| 150 | \brief Set the flags for this constraint |
| 151 | |
| 152 | \param[in] flags the new constraint flags |
| 153 | |
| 154 | default: PxConstraintFlag::eDRIVE_LIMITS_ARE_FORCES |
| 155 | |
| 156 | @see PxConstraintFlags |
| 157 | */ |
| 158 | |
| 159 | virtual void setFlags(PxConstraintFlags flags) = 0; |
| 160 | |
| 161 | /** |
| 162 | \brief Retrieve the flags for this constraint |
| 163 | |
| 164 | \return the constraint flags |
| 165 | @see PxConstraintFlags |
| 166 | */ |
| 167 | |
| 168 | virtual PxConstraintFlags getFlags() const = 0; |
| 169 | |
| 170 | |
| 171 | /** |
| 172 | \brief Set a flag for this constraint |
| 173 | |
| 174 | \param[in] flag the constraint flag |
| 175 | \param[in] value the new value of the flag |
| 176 | |
| 177 | @see PxConstraintFlags |
| 178 | */ |
| 179 | |
| 180 | virtual void setFlag(PxConstraintFlag::Enum flag, bool value) = 0; |
| 181 | |
| 182 | /** |
| 183 | \brief Retrieve the constraint force most recently applied to maintain this constraint. |
| 184 | |
| 185 | \param[out] linear the constraint force |
| 186 | \param[out] angular the constraint torque |
| 187 | */ |
| 188 | virtual void getForce(PxVec3& linear, PxVec3& angular) const = 0; |
| 189 | |
| 190 | |
| 191 | /** |
| 192 | \brief whether the constraint is valid. |
| 193 | |
| 194 | A constraint is valid if it has at least one dynamic rigid body or articulation link. A constraint that |
| 195 | is not valid may not be inserted into a scene, and therefore a static actor to which an invalid constraint |
| 196 | is attached may not be inserted into a scene. |
| 197 | |
| 198 | Invalid constraints arise only when an actor to which the constraint is attached has been deleted. |
| 199 | |
| 200 | */ |
| 201 | virtual bool isValid() const = 0; |
| 202 | |
| 203 | /** |
| 204 | \brief Set the break force and torque thresholds for this constraint. |
| 205 | |
| 206 | If either the force or torque measured at the constraint exceed these thresholds the constraint will break. |
| 207 | |
| 208 | \param[in] linear the linear break threshold |
| 209 | \param[in] angular the angular break threshold |
| 210 | */ |
| 211 | |
| 212 | |
| 213 | virtual void setBreakForce(PxReal linear, PxReal angular) = 0; |
| 214 | |
| 215 | /** |
| 216 | \brief Retrieve the constraint break force and torque thresholds |
| 217 | |
| 218 | \param[out] linear the linear break threshold |
| 219 | \param[out] angular the angular break threshold |
| 220 | |
| 221 | */ |
| 222 | virtual void getBreakForce(PxReal& linear, PxReal& angular) const = 0; |
| 223 | |
| 224 | |
| 225 | /** |
| 226 | \brief Fetch external owner of the constraint. |
| 227 | |
| 228 | Provides a reference to the external owner of a constraint and a unique owner type ID. |
| 229 | |
| 230 | \param[out] typeID Unique type identifier of the external object. |
| 231 | \return Reference to the external object which owns the constraint. |
| 232 | |
| 233 | @see PxConstraintConnector.getExternalReference() |
| 234 | */ |
| 235 | virtual void* getExternalReference(PxU32& typeID) = 0; |
| 236 | |
| 237 | /** |
| 238 | \brief Set the constraint functions for this constraint |
| 239 | |
| 240 | \param[in] connector the constraint connector object by which the SDK communicates with the constraint. |
| 241 | \param[in] shaders the shader table for the constraint |
| 242 | |
| 243 | @see PxConstraintConnector PxConstraintSolverPrep PxConstraintProject PxConstraintVisualize |
| 244 | */ |
| 245 | virtual void setConstraintFunctions(PxConstraintConnector& connector, |
| 246 | const PxConstraintShaderTable& shaders) = 0; |
| 247 | |
| 248 | virtual const char* getConcreteTypeName() const { return "PxConstraint" ; } |
| 249 | |
| 250 | protected: |
| 251 | PX_INLINE PxConstraint(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {} |
| 252 | PX_INLINE PxConstraint(PxBaseFlags baseFlags) : PxBase(baseFlags) {} |
| 253 | virtual ~PxConstraint() {} |
| 254 | virtual bool isKindOf(const char* name) const { return !strcmp("PxConstraint" , name) || PxBase::isKindOf(name); } |
| 255 | |
| 256 | }; |
| 257 | |
| 258 | #ifndef PX_DOXYGEN |
| 259 | } // namespace physx |
| 260 | #endif |
| 261 | |
| 262 | /** @} */ |
| 263 | #endif |
| 264 | |