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