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

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

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#ifndef NX_PHYSICS_NXD6JOINTDESC
2#define NX_PHYSICS_NXD6JOINTDESC
3
4#include "Nxp.h"
5#include "NxJointDesc.h"
6#include "NxJointLimitSoftPairDesc.h"
7#include "NxBitField.h"
8#include "NxMotorDesc.h"
9/*----------------------------------------------------------------------------*\
10|
11|                                               Public Interface to NovodeX Technology
12|
13|                                                            www.novodex.com
14|
15\*----------------------------------------------------------------------------*/
16/** \addtogroup physics
17  @{
18*/
19
20
21
22
23
24///////////////////////////////////////////////////////////
25
26/**
27\brief Descriptor class for the D6Joint. See #NxD6Joint.
28
29 <p>In the D6Joint, the axes are assigned as follows:
30 <ul>
31 <li>x-axis = joint axis</li>
32 <li>y-axis = joint normal axis</li>
33 <li>z-axis = x-axis cross y-axis</li>
34 </ul>
35 These are defined relative to the parent body (0) of the joint.</p>
36
37 <p>
38 Swing is defined as the rotation of the x-axis with respect to the y- and z-axis.
39 </p>
40
41 <p>
42 Twist is defined as the rotation about the x-axis.
43 </p>
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 NxD6Joint NxJointDesc NxScene.createJoint()
52*/
53
54class NxD6JointDesc : public NxJointDesc
55{
56public:
57       
58/* Constraints */
59        /**
60        \brief Define the linear degrees of freedom
61
62        <b>Default:</b> NX_D6JOINT_MOTION_FREE
63
64        @see NxD6JointMotion xMotion yMotion zMotion
65        */
66        NxD6JointMotion                 xMotion, yMotion, zMotion;
67
68        /**
69        \brief Define the angular degrees of freedom
70
71        <b>Default:</b> NX_D6JOINT_MOTION_FREE
72
73        @see NxD6JointMotion swing1Motion swing2Motion twistMotion
74        */
75        NxD6JointMotion                 swing1Motion, swing2Motion, twistMotion;
76
77        /**
78        \brief If some linear DOF are limited, linearLimit defines the characteristics of these limits
79
80        <b>Range:</b> See #NxJointLimitSoftDesc<br>
81        <b>Default:</b> See #NxJointLimitSoftDesc
82
83        @see NxJointLimitSoftDesc swing1Limit swing2Limit twistLimit
84        */
85        NxJointLimitSoftDesc            linearLimit;
86
87        /**
88        \brief If swing1Motion is NX_D6JOINT_MOTION_LIMITED, swing1Limit defines the characteristics of the limit
89
90        <b>Range:</b> See #NxJointLimitSoftDesc<br>
91        <b>Default:</b> See #NxJointLimitSoftDesc
92
93        @see NxJointLimitSoftDesc linearLimit swing2Limit twistLimit
94        */
95        NxJointLimitSoftDesc            swing1Limit;
96       
97        /**
98        \brief If swing2Motion is NX_D6JOINT_MOTION_LIMITED, swing2Limit defines the characteristics of the limit
99
100        <b>Range:</b> See #NxJointLimitSoftDesc<br>
101        <b>Default:</b> See #NxJointLimitSoftDesc
102
103        @see NxJointLimitSoftDesc linearLimit swing1Limit twistLimit
104        */
105        NxJointLimitSoftDesc            swing2Limit;
106       
107        /**
108        \brief If twistMotion is NX_D6JOINT_MOTION_LIMITED, twistLimit defines the characteristics of the limit
109
110        <b>Range:</b> See #NxJointLimitSoftPairDesc<br>
111        <b>Default:</b> See #NxJointLimitSoftDesc
112
113        @see NxJointLimitSoftDesc linearLimit swing1Limit swing2imit
114        */
115        NxJointLimitSoftPairDesc        twistLimit;
116
117/* drive */
118       
119        /**
120        \brief Drive the three linear DOF
121
122        <b>Range:</b> See #NxJointDriveDesc<br>
123        <b>Default:</b> See #NxJointDriveDesc
124
125        @see NxJointDriveDesc xDrive yDrive zDrive drivePosition
126        */
127        NxJointDriveDesc                xDrive, yDrive, zDrive;
128
129        /**
130        \brief These drives are used if the flag NX_D6JOINT_SLERP_DRIVE is not set
131
132        <b>Range:</b> See #NxJointDriveDesc<br>
133        <b>Default:</b> See #NxJointDriveDesc
134
135        @see NxJointDriveDesc swingDrive twistDrive driveOrientation
136        */
137        NxJointDriveDesc                swingDrive, twistDrive;
138
139        /**
140        \brief This drive is used if the flag NX_D6JOINT_SLERP_DRIVE is set
141
142        <b>Range:</b> See #NxJointDriveDesc<br>
143        <b>Default:</b> See #NxJointDriveDesc
144
145        @see NxJointDriveDesc driveOrientation
146        */
147        NxJointDriveDesc                slerpDrive;
148
149       
150        /**
151        \brief If the type of xDrive (yDrive,zDrive) is NX_D6JOINT_DRIVE_POSITION, drivePosition defines the goal position
152
153        <b>Range:</b> position vector<br>
154        <b>Default:</b> Zero
155
156        @see xDrive yDrive zDrive NxD6Joint.setDrivePosition
157        */
158        NxVec3                                  drivePosition;
159
160        /**
161        \brief If the type of swingDrive or twistDrive is NX_D6JOINT_DRIVE_POSITION, driveOrientation defines the goal orientation
162
163        <b>Range:</b> unit quaternion<br>
164        <b>Default:</b> Identity Quaternian
165
166        @see slerpDrive swingDrive twistDrive NxD6Joint.setDriveOrientation()
167        */
168        NxQuat                                  driveOrientation;
169
170        /**
171        \brief If the type of xDrive (yDrive,zDrive) is NX_D6JOINT_DRIVE_VELOCITY, driveLinearVelocity defines the goal linear velocity
172
173        <b>Range:</b> velocity vector<br>
174        <b>Default:</b> Zero
175
176        @see xDrive yDrive zDrive NxD6Joint.setDriveLinearVelocity()
177        */
178        NxVec3                                  driveLinearVelocity;
179       
180        /**
181        \brief If the type of swingDrive or twistDrive is NX_D6JOINT_DRIVE_VELOCITY, driveAngularVelocity defines the goal angular velocity
182
183        <b>Range:</b> angular velocity vector<br>
184        <b>Default:</b> Zero
185
186        @see slerpDrive swingDrive twistDrive NxD6Joint.setDriveAngularVelocity()
187        */
188        NxVec3                                  driveAngularVelocity;
189
190        /**
191        \brief If projectionMode is NX_JPM_NONE, projection is disabled. If NX_JPM_POINT_MINDIST, bodies are projected to limits leaving an linear error of projectionDistance and an angular error of projectionAngle
192
193        <b>Default:</b> NX_JPM_NONE
194
195        @see NxJointProjectionMode projectionDistance projectionAngle
196        */
197        NxJointProjectionMode   projectionMode;
198       
199        /**
200        \brief The distance above which to project the joint.
201
202        <b>Range:</b> (0,inf)<br>
203        <b>Default:</b> 0.1
204
205        @see projectionMode projectionAngle
206        */
207        NxReal                                  projectionDistance;     
208       
209        /**
210        \brief The angle above which to project the joint.
211
212        <b>Range:</b> (0,inf)<br>
213        <b>Default:</b> 0.0872f (about 5 degrees in radians)
214
215        @see projectionMode ProjectionDistance
216        */
217        NxReal                                  projectionAngle;       
218
219        /**
220        \brief when the flag NX_D6JOINT_GEAR_ENABLED is set, the angular velocity of the second actor is driven towards the angular velocity of the first actor times gearRatio (both w.r.t. their primary axis)
221
222        <b>Range:</b> (0,inf)<br>
223        <b>Default:</b> 1.0
224
225        @see flags
226        */
227        NxReal                                  gearRatio;
228
229        /**
230        \brief This is a combination of the bits defined by ::NxD6JointFlag
231
232        <b>Default:</b> 0
233
234        @see NxD6JointFlag
235        */
236        NxU32 flags;
237
238        /**
239        \brief constructor sets to default.
240        */
241
242        NX_INLINE                       NxD6JointDesc();
243
244        /**
245        \brief (re)sets the structure to the default.   
246        */
247        NX_INLINE       void    setToDefault();
248
249        /**
250        \brief Returns true if the descriptor is valid.
251
252        \return returns true if the current settings are valid
253        */
254
255        NX_INLINE       bool    isValid() const;
256};
257
258NxD6JointDesc::NxD6JointDesc() : NxJointDesc(NX_JOINT_D6)
259{
260        setToDefault();
261}
262
263void NxD6JointDesc::setToDefault()
264{
265        NxJointDesc::setToDefault();
266
267        xMotion = NX_D6JOINT_MOTION_FREE;
268        yMotion = NX_D6JOINT_MOTION_FREE;
269        zMotion = NX_D6JOINT_MOTION_FREE;
270        twistMotion = NX_D6JOINT_MOTION_FREE;
271        swing1Motion = NX_D6JOINT_MOTION_FREE;
272        swing2Motion = NX_D6JOINT_MOTION_FREE;
273
274        drivePosition.set(0,0,0);
275        driveOrientation.id();
276
277        driveLinearVelocity.set(0,0,0);
278        driveAngularVelocity.set(0,0,0);
279
280        projectionMode = NX_JPM_NONE;   // choose NX_JPM_POINT_MINDIST to turn projection on
281        projectionDistance = 0.1f;
282        projectionAngle = 0.0872f;      //about 5 degrees in radians.
283
284        flags = 0;
285        gearRatio = 1.0f;
286}
287
288bool NxD6JointDesc::isValid() const
289{
290        if (flags & NX_D6JOINT_SLERP_DRIVE) {   // only possible with all angular DOF available
291                if (swing1Motion == NX_D6JOINT_MOTION_LOCKED ||
292                        swing2Motion == NX_D6JOINT_MOTION_LOCKED ||
293                        twistMotion == NX_D6JOINT_MOTION_LOCKED) return false;
294        }
295
296        // swing limits are symmetric, thus their range is 0..180 degrees
297        if (swing1Motion == NX_D6JOINT_MOTION_LIMITED) {
298                if (swing1Limit.value < 0.0f) return false;
299                if (swing1Limit.value > NxPi) return false;
300        }
301        if (swing2Motion == NX_D6JOINT_MOTION_LIMITED) {
302                if (swing2Limit.value < 0.0f) return false;
303                if (swing2Limit.value > NxPi) return false;
304        }
305
306        // twist limits are asymmetric with -180 <= low < high <= 180 degrees
307        if (twistMotion == NX_D6JOINT_MOTION_LIMITED) {
308                if (twistLimit.low.value < -NxPi) return false;
309                if (twistLimit.high.value > NxPi) return false;
310                if (twistLimit.low.value > twistLimit.high.value) return false;
311        }
312
313        // in angular limited-free mode, only -90..90 swings are possible
314        if (swing1Motion == NX_D6JOINT_MOTION_LIMITED && swing2Motion == NX_D6JOINT_MOTION_FREE)
315                if (swing1Limit.value > NxHalfPi) return false;
316        if (swing2Motion == NX_D6JOINT_MOTION_LIMITED && swing1Motion == NX_D6JOINT_MOTION_FREE)
317                if (swing2Limit.value > NxHalfPi) return false;
318
319        if (flags & NX_D6JOINT_GEAR_ENABLED)            // gear only with twist motion enabled
320                if (twistMotion == NX_D6JOINT_MOTION_LOCKED) return false;
321
322        return NxJointDesc::isValid();
323}
324
325/** @} */
326#endif
327
328
329//AGCOPYRIGHTBEGIN
330///////////////////////////////////////////////////////////////////////////
331// Copyright © 2005 AGEIA Technologies.
332// All rights reserved. www.ageia.com
333///////////////////////////////////////////////////////////////////////////
334//AGCOPYRIGHTEND
335
Note: See TracBrowser for help on using the repository browser.