source: GTP/trunk/App/Games/Jungle_Rumble/src/physic/physics/include/NxJoint.h @ 1378

Revision 1378, 17.8 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#ifndef NX_PHYSICS_NXJOINT
2#define NX_PHYSICS_NXJOINT
3/*----------------------------------------------------------------------------*\
4|
5|                                               Public Interface to NovodeX Technology
6|
7|                                                            www.novodex.com
8|
9\*----------------------------------------------------------------------------*/
10/** \addtogroup physics
11  @{
12*/
13
14#include "Nxp.h"
15
16class NxActor;
17class NxScene;
18class NxRevoluteJoint;
19class NxPointInPlaneJoint;
20class NxPointOnLineJoint;
21class NxPrismaticJoint;
22class NxCylindricalJoint;
23class NxSphericalJoint;
24class NxFixedJoint;
25class NxDistanceJoint;
26class NxPulleyJoint;
27class NxD6Joint;
28
29/**
30 \brief Abstract base class for the different types of joints.
31
32 All joints are used to connect two dynamic actors, or an actor and the environment.
33
34 A NULL actor represents the environment. Whenever the below comments mention two actors,
35 one of them may always be the environment (NULL).
36
37<h3>Visulizations:</h3>
38\li #NX_VISUALIZE_JOINT_LOCAL_AXES
39\li #NX_VISUALIZE_JOINT_WORLD_AXES
40\li #NX_VISUALIZE_JOINT_LIMITS
41\li #NX_VISUALIZE_JOINT_ERROR
42\li #NX_VISUALIZE_JOINT_FORCE
43\li #NX_VISUALIZE_JOINT_REDUCED
44
45<b>Platform:</b>
46\li PC SW: Yes
47\li PPU  : No
48\li PS3  : Yes
49\li XB360: Yes
50
51 @see NxJointDesc NxScene.createJoint()
52 @see NxCylindricalJoint NxD6Joint NxDistanceJoint NxFixedJoint NxPointInPlaneJoint
53NxPointOnLineJoint NxPrismaticJoint NxPulleyJoint NxRevoluteJointDesc NxSphericalJoint
54*/
55class NxJoint
56        {
57        protected:
58        NX_INLINE                                       NxJoint() : userData(NULL), appData(NULL)
59                                                                                        {}
60        virtual                                         ~NxJoint()      {}
61
62        public:
63
64        /**
65        \brief Retrieves the Actors involved.
66
67        \param[out] actor1 First actor associated with joint.
68        \param[out] actor2 Second actor associated with joint.
69
70        <b>Platform:</b>
71        \li PC SW: Yes
72        \li PPU  : No
73        \li PS3  : Yes
74        \li XB360: Yes
75
76        @see NxJointDesc.actors NxActor
77        */
78        virtual void getActors(NxActor** actor1, NxActor** actor2) = 0;
79
80        /**
81        \brief Sets the point where the two actors are attached, specified in global coordinates.
82
83        Set this after setting the actors of the joint.
84
85        <b>Sleeping:</b> This call wakes the actor(s) if they are sleeping.
86
87        \param[in] vec Point the actors are attached at, specified in the global frame. <b>Range:</b> position vector
88
89        <b>Platform:</b>
90        \li PC SW: Yes
91        \li PPU  : No
92        \li PS3  : Yes
93        \li XB360: Yes
94
95        @see NxJointDesc.setGlobalAnchor() getGlobalAnchor()
96        */
97        virtual void setGlobalAnchor(const NxVec3 &vec) = 0;
98
99        /**
100        \brief Sets the direction of the joint's primary axis, specified in global coordinates.
101
102        The direction vector should be normalized to unit length.
103
104        <b>Sleeping:</b> This call wakes the actor(s) if they are sleeping.
105
106        \param[in] vec Direction of primary axis in the global frame. <b>Range:</b> direction vector
107
108        <b>Platform:</b>
109        \li PC SW: Yes
110        \li PPU  : No
111        \li PS3  : Yes
112        \li XB360: Yes
113
114        @see NxJointDesc.setGlobalAxis() getGlobalAxis()
115        */
116        virtual void setGlobalAxis(const NxVec3 &vec) = 0;
117
118        /**
119        \brief Retrieves the joint anchor.
120
121        \return The joints anchor point in the global frame.
122
123        <b>Platform:</b>
124        \li PC SW: Yes
125        \li PPU  : No
126        \li PS3  : Yes
127        \li XB360: Yes
128
129        @see setGlobalAnchor() getGlobalAxis()
130        */
131        virtual NxVec3  getGlobalAnchor()       const  = 0;
132
133        /**
134        \brief Retrieves the joint axis.
135
136        \return The joints axis in the global frame.
137
138        <b>Platform:</b>
139        \li PC SW: Yes
140        \li PPU  : No
141        \li PS3  : Yes
142        \li XB360: Yes
143
144        @see setGlobalAxis() getGlobalAnchor()
145        */
146        virtual NxVec3  getGlobalAxis()         const = 0;
147
148        /**
149        \brief Returns the state of the joint.
150
151        Joints are created in the NX_JS_UNBOUND state. Making certain changes to the simulation or the joint
152        can also make joints become unbound.
153        Unbound joints are automatically bound the next time Scene::run() is called, and this changes their
154        state to NX_JS_SIMULATING. NX_JS_BROKEN means that a breakable joint has broken due to a large force
155        or one of its actors has been deleted. In either case the joint was removed from the simulation,
156        so it should be released by the user to free up its memory.
157
158        \return The state of the joint. See #NxJointState.
159
160        <b>Platform:</b>
161        \li PC SW: Yes
162        \li PPU  : No
163        \li PS3  : Yes
164        \li XB360: Yes
165
166        @see NxJointState setBreakable()
167        */
168        virtual NxJointState getState() = 0;
169       
170        /**
171        \brief Sets the maximum force magnitude that the joint is able to withstand without breaking.
172       
173        If the joint force rises above this threshold, the joint breaks, and becomes disabled. Additionally,
174        the jointBreakNotify() method of the scene's user notify callback will be called.
175        (You can set this with NxScene::setUserNotify()).
176
177        There are two values, one for linear forces, and one for angular forces.
178
179        Both force values are NX_MAX_REAL by default. This setting makes the joint unbreakable.
180        The values should always be nonnegative.
181
182        The distinction between maxForce and maxTorque is dependant on how the joint is implimented internally,
183        which may not be obvious. For example what appears to be an angular degree of freedom may be constrained
184        indirectly by a linear constraint.
185
186    So in most practical applications the user should set both maxTorque and maxForce to low values.
187
188        <b>Sleeping:</b> This call wakes the actor(s) if they are sleeping.
189
190        \param[in] maxForce Maximum force the joint can withstand without breaking. <b>Range:</b> (0,inf]
191        \param[in] maxTorque Maximum torque the joint can withstand without breaking. <b>Range:</b> (0,inf]
192
193        <b>Platform:</b>
194        \li PC SW: Yes
195        \li PPU  : No
196        \li PS3  : Yes
197        \li XB360: Yes
198
199        @see NxJointDesc.maxForce NxJointDesc.maxTorque getState() getBreakable()
200        */
201        virtual void setBreakable(NxReal maxForce, NxReal maxTorque) = 0;
202
203        /**
204        \brief Retrieves the max forces of a breakable joint. See #setBreakable().
205
206        \param[out] maxForce Retrieves the maximum force the joint can withstand without breaking.
207        \param[out] maxTorque Retrieves the maximum torque the joint can withstand without breaking.
208
209        <b>Platform:</b>
210        \li PC SW: Yes
211        \li PPU  : No
212        \li PS3  : Yes
213        \li XB360: Yes
214
215        @see setBreakable NxJointDesc.maxForce NxJointDesc.maxTorque getState()
216        */
217        virtual void getBreakable(NxReal & maxForce, NxReal & maxTorque) = 0;
218
219/************************************************************************************************/
220
221/** @name Limits
222*/
223//@{
224
225        /**
226        \brief Sets the limit point.
227       
228        The point is specified in the global coordinate frame.
229
230        All types of joints may be limited with the same system:
231        You may elect a point attached to one of the two actors to act as the limit point.
232        You may also specify several planes attached to the other actor.
233
234        The points and planes move together with the actor they are attached to.
235
236        The simulation then makes certain that the pair of actors only move relative to eachother
237        so that the limit point stays on the positive side of all limit planes.
238
239        the default limit point is (0,0,0) in the local frame of actor2.
240        Calling this deletes all existing limit planes.
241
242        <b>Sleeping:</b> This call wakes the actor(s) if they are sleeping.
243
244        \param[in] point The limit reference point defined in the global frame. <b>Range:</b> position vector
245        \param[in] pointIsOnActor2 if true the point is attached to the second actor. Otherwise it is attached to the first.
246
247        <b>Platform:</b>
248        \li PC SW: Yes
249        \li PPU  : No
250        \li PS3  : Yes
251        \li XB360: Yes
252
253        @see getLimitPoint() addLimitPlane()
254        */
255
256        virtual void setLimitPoint(const NxVec3 & point, bool pointIsOnActor2 = true) = 0;
257
258        /**
259        \brief Retrieves the global space limit point.
260       
261        Returns true if the point is fixed on actor2.
262
263        \param[out] worldLimitPoint Used to store the global frame limit point.
264        \return True if the point is fixed to actor 2 otherwise the point is fixed to actor 1.
265
266        <b>Platform:</b>
267        \li PC SW: Yes
268        \li PPU  : No
269        \li PS3  : Yes
270        \li XB360: Yes
271
272        @see setLimitPoint() addLimitPlane()
273        */
274        virtual bool getLimitPoint(NxVec3 & worldLimitPoint) = 0;
275
276        /**
277        \brief Adds a limit plane.
278       
279        Both of the parameters are given in global coordinates. see setLimitPoint() for the meaning of limit planes.
280       
281        The plane is affixed to the     actor that does not have the limit point.
282
283        The normal of the plane points toward the positive side of the plane, and thus toward the
284        limit point. If the normal points away from the limit point at the time of this call, the
285        method returns false and the limit plane is ignored.
286
287        \note This function always returns true and adds the limit plane unlike earlier versions. This behavoir
288        was changed to allow the joint to be serialized easily.
289
290        <b>Sleeping:</b> This call wakes the actor(s) if they are sleeping.
291
292        \param[in] normal Normal for the limit plane in global coordinates. <b>Range:</b> direction vector
293        \param[in] pointInPlane Point in the limit plane in global coordinates. <b>Range:</b> position vector
294        \return Always true.
295
296        <b>Platform:</b>
297        \li PC SW: Yes
298        \li PPU  : No
299        \li PS3  : Yes
300        \li XB360: Yes
301
302        @see setLimitPoint() purgeLimitPlanes() getNextLimitPlane()
303        */
304        virtual bool addLimitPlane(const NxVec3 & normal, const NxVec3 & pointInPlane) = 0;
305
306        /**
307        \brief deletes all limit planes added to the joint.
308       
309        Invalidates limit plane iterator.
310
311        <b>Sleeping:</b> Does <b>NOT</b> wake the associated actor up automatically(To be fixed in 2.3.1).
312
313        <b>Platform:</b>
314        \li PC SW: Yes
315        \li PPU  : No
316        \li PS3  : Yes
317        \li XB360: Yes
318
319        @see addLimitPlane() getNextLimitPlane()
320        */
321        virtual void purgeLimitPlanes() = 0;
322
323        /**
324        \brief Restarts the limit plane iteration.
325       
326        Call before starting to iterate. This method may be used together with
327        the below two methods to enumerate the limit planes.
328        This iterator becomes invalid when planes
329        are added or removed, or the plane iterator mechanism is
330        invoked on another joint.
331
332        <b>Platform:</b>
333        \li PC SW: Yes
334        \li PPU  : No
335        \li PS3  : Yes
336        \li XB360: Yes
337
338        @see hasMoreLimitPlanes() getNextLimitPlane()
339        */
340        virtual void resetLimitPlaneIterator() = 0;
341
342        /**
343        \brief Returns true until the iterator reaches the end of the set of limit planes.
344       
345        Adding or removing elements does not reset the iterator.
346
347        \return True if the iterator has not eached the end of the sequence of limit planes.
348
349        <b>Platform:</b>
350        \li PC SW: Yes
351        \li PPU  : No
352        \li PS3  : Yes
353        \li XB360: Yes
354
355        @see resetLimitPlaneIterator() getNextLimitPlane()
356        */
357        virtual bool hasMoreLimitPlanes() = 0;
358
359        /**
360        \brief Returns the next element pointed to by the limit plane iterator, and increments the iterator.
361
362        Places the global frame plane equation (consisting of normal and d, the 4th
363        element) coefficients in the argument references. The plane equation is of the form:
364
365        dot(n,p) + d == 0 (n = normal, p = a point on the plane)
366
367        \note This convention for the plane equation differs from the convention used by #NxPlaneShape
368       
369        \param[out] planeNormal Used to store the plane normal.
370        \param[out] planeD Used to store the plane 'D'.
371        \return Returns true if the limit plane is satisfied.
372
373        <b>Platform:</b>
374        \li PC SW: Yes
375        \li PPU  : No
376        \li PS3  : Yes
377        \li XB360: Yes
378
379        @see resetLimitPlaneIterator() hasMoreLimitPlanes()
380        */
381        virtual bool getNextLimitPlane(NxVec3 & planeNormal, NxReal & planeD) = 0;
382//@}
383/************************************************************************************************/
384
385        /**
386        \brief Retrieve the type of this joint.
387        \return The type of joint.
388
389        <b>Platform:</b>
390        \li PC SW: Yes
391        \li PPU  : No
392        \li PS3  : Yes
393        \li XB360: Yes
394
395        @see NxJointType
396        */
397        virtual NxJointType  getType() const = 0;
398
399/************************************************************************************************/
400
401/** @name Is... Joint Type
402*/
403//@{
404
405        /**
406        \brief Type casting operator. The result may be cast to the desired subclass type.
407
408        \param[in] type Used to query for a specific joint type.
409        \return NULL if the object if not of type(see #NxJointType). Otherwise a pointer to this object.
410
411        <b>Platform:</b>
412        \li PC SW: Yes
413        \li PPU  : No
414        \li PS3  : Yes
415        \li XB360: Yes
416
417        @see NxJointType
418        */
419        NX_INLINE void* is(NxJointType type) { return (type == getType()) ? (void*)this : NULL;         };
420
421        /**
422        \brief Attempts to perform a cast to a #NxRevoluteJoint.
423
424        Returns NULL if this object is not of the appropriate type.
425
426        \return NULL if this object is not a #NxRevoluteJoint. Otherwise a pointer to this.
427
428        <b>Platform:</b>
429        \li PC SW: Yes
430        \li PPU  : No
431        \li PS3  : Yes
432        \li XB360: Yes
433
434        @see is NxRevoluteJoint
435        */
436        NX_INLINE NxRevoluteJoint* isRevoluteJoint() { return (NxRevoluteJoint*)is(NX_JOINT_REVOLUTE);}
437
438        /**
439        \brief Attempts to perform a cast to a #NxPointInPlaneJoint.
440
441        Returns NULL if this object is not of the appropriate type.
442
443        \return NULL if this object is not a #NxPointInPlaneJoint. Otherwise a pointer to this.
444
445        <b>Platform:</b>
446        \li PC SW: Yes
447        \li PPU  : No
448        \li PS3  : Yes
449        \li XB360: Yes
450
451        @see is NxPointInPlaneJoint
452        */
453        NX_INLINE NxPointInPlaneJoint* isPointInPlaneJoint() { return (NxPointInPlaneJoint*)is(NX_JOINT_POINT_IN_PLANE);}
454
455        /**
456        \brief Attempts to perform a cast to a #NxPointOnLineJoint.
457
458        Returns NULL if this object is not of the appropriate type.
459
460        \return NULL if this object is not a #NxPointOnLineJoint. Otherwise a pointer to this.
461
462        <b>Platform:</b>
463        \li PC SW: Yes
464        \li PPU  : No
465        \li PS3  : Yes
466        \li XB360: Yes
467
468        @see is NxPointOnLineJoint
469        */
470        NX_INLINE NxPointOnLineJoint* isPointOnLineJoint() { return (NxPointOnLineJoint*)is(NX_JOINT_POINT_ON_LINE);}
471
472        /**
473        \brief Attempts to perform a cast to a #NxD6Joint
474
475        Returns NULL if this object is not of the appropriate type.
476
477        \return NULL if this object is not a #NxD6Joint. Otherwise a pointer to this.
478
479        <b>Platform:</b>
480        \li PC SW: Yes
481        \li PPU  : No
482        \li PS3  : Yes
483        \li XB360: Yes
484
485        @see is NxD6Joint
486        */
487        NX_INLINE NxD6Joint* isD6Joint() { return (NxD6Joint*)is(NX_JOINT_D6);}
488
489        /**
490        \brief Attempts to perform a cast to a #NxPrismaticJoint
491
492        Returns NULL if this object is not of the appropriate type.
493
494        \return NULL if this object is not a #NxPrismaticJoint. Otherwise a pointer to this.
495
496        <b>Platform:</b>
497        \li PC SW: Yes
498        \li PPU  : No
499        \li PS3  : Yes
500        \li XB360: Yes
501
502        @see is NxPrismaticJoint
503        */
504        NX_INLINE NxPrismaticJoint* isPrismaticJoint() { return (NxPrismaticJoint*)is(NX_JOINT_PRISMATIC);}
505
506        /**
507        \brief Attempts to perform a cast to a #NxCylindricalJoint
508
509        Returns NULL if this object is not of the appropriate type.
510
511        \return NULL if this object is not a #NxCylindricalJoint. Otherwise a pointer to this.
512
513        <b>Platform:</b>
514        \li PC SW: Yes
515        \li PPU  : No
516        \li PS3  : Yes
517        \li XB360: Yes
518
519        @see is NxCylindricalJoint
520        */
521        NX_INLINE NxCylindricalJoint* isCylindricalJoint() { return (NxCylindricalJoint*)is(NX_JOINT_CYLINDRICAL);}
522
523        /**
524        \brief Attempts to perform a cast to a #NxSphericalJoint
525
526        Returns NULL if this object is not of the appropriate type.
527
528        \return NULL if this object is not a #NxSphericalJoint. Otherwise a pointer to this.
529
530        <b>Platform:</b>
531        \li PC SW: Yes
532        \li PPU  : No
533        \li PS3  : Yes
534        \li XB360: Yes
535
536        @see is NxSphericalJoint
537        */
538        NX_INLINE NxSphericalJoint* isSphericalJoint() { return (NxSphericalJoint*)is(NX_JOINT_SPHERICAL);}
539
540        /**
541        \brief Attempts to perform a cast to a #NxFixedJoint
542
543        Returns NULL if this object is not of the appropriate type.
544
545        \return NULL if this object is not a #NxFixedJoint. Otherwise a pointer to this.
546
547        <b>Platform:</b>
548        \li PC SW: Yes
549        \li PPU  : No
550        \li PS3  : Yes
551        \li XB360: Yes
552
553        @see is NxFixedJoint
554        */
555        NX_INLINE NxFixedJoint* isFixedJoint() { return (NxFixedJoint*)is(NX_JOINT_FIXED);}
556
557        /**
558        \brief Attempts to perform a cast to a #NxDistanceJoint
559
560        Returns NULL if this object is not of the appropriate type.
561
562        \return NULL if this object is not a #NxDistanceJoint. Otherwise a pointer to this.
563
564        <b>Platform:</b>
565        \li PC SW: Yes
566        \li PPU  : No
567        \li PS3  : Yes
568        \li XB360: Yes
569
570        @see is NxDistanceJoint
571        */
572        NX_INLINE NxDistanceJoint* isDistanceJoint() { return (NxDistanceJoint*)is(NX_JOINT_DISTANCE);}
573
574        /**
575        \brief Attempts to perform a cast to a #NxPulleyJoint
576
577        Returns NULL if this object is not of the appropriate type.
578
579        \return NULL if this object is not a #NxPulleyJoint. Otherwise a pointer to this.
580
581        <b>Platform:</b>
582        \li PC SW: Yes
583        \li PPU  : No
584        \li PS3  : Yes
585        \li XB360: Yes
586
587        @see is NxPulleyJoint
588        */
589        NX_INLINE NxPulleyJoint* isPulleyJoint() { return (NxPulleyJoint*)is(NX_JOINT_PULLEY);}
590//@}
591/************************************************************************************************/
592
593        /**
594        \brief Sets a name string for the object that can be retrieved with getName().
595       
596        This is for debugging and is not used by the SDK. The string is not copied by the SDK, only the pointer is stored.
597       
598        \param[in] name String to set the objects name to.
599
600        <b>Platform:</b>
601        \li PC SW: Yes
602        \li PPU  : No
603        \li PS3  : Yes
604        \li XB360: Yes
605
606        @see getName()
607        */
608        virtual void                    setName(const char* name)               = 0;
609
610        /**
611        \brief Retrieves the name string set with setName().
612
613        \return The name string for this object.
614
615        <b>Platform:</b>
616        \li PC SW: Yes
617        \li PPU  : No
618        \li PS3  : Yes
619        \li XB360: Yes
620
621        @see setName()
622        */
623        virtual const char*             getName()                       const   = 0;
624
625        /**
626        \brief Retrieves owner scene.
627
628        \return The scene which owns this joint.
629
630        <b>Platform:</b>
631       
632        \li PC SW: Yes
633        \li PPU  : No
634        \li PS3  : Yes
635        \li XB360: Yes
636
637        @see NxScene
638        */
639        virtual NxScene&                getScene() = 0;
640
641        void*                   userData;       //!< user can assign this to whatever, usually to create a 1:1 relationship with a user object.
642        void*                   appData;
643        };
644
645/** @} */
646#endif
647
648
649//AGCOPYRIGHTBEGIN
650///////////////////////////////////////////////////////////////////////////
651// Copyright © 2005 AGEIA Technologies.
652// All rights reserved. www.ageia.com
653///////////////////////////////////////////////////////////////////////////
654//AGCOPYRIGHTEND
655
Note: See TracBrowser for help on using the repository browser.