source: GTP/trunk/App/Demos/Geom/OgreStuff/include/ode/odecpp.h @ 1812

Revision 1812, 19.6 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1812]1/*************************************************************************
2 *                                                                       *
3 * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
4 * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
5 *                                                                       *
6 * This library is free software; you can redistribute it and/or         *
7 * modify it under the terms of EITHER:                                  *
8 *   (1) The GNU Lesser General Public License as published by the Free  *
9 *       Software Foundation; either version 2.1 of the License, or (at  *
10 *       your option) any later version. The text of the GNU Lesser      *
11 *       General Public License is included with this library in the     *
12 *       file LICENSE.TXT.                                               *
13 *   (2) The BSD-style license that is included with this library in     *
14 *       the file LICENSE-BSD.TXT.                                       *
15 *                                                                       *
16 * This library is distributed in the hope that it will be useful,       *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
20 *                                                                       *
21 *************************************************************************/
22
23/* C++ interface for non-collision stuff */
24
25
26#ifndef _ODE_ODECPP_H_
27#define _ODE_ODECPP_H_
28#ifdef __cplusplus
29
30#include <ode/error.h>
31
32
33class dWorld {
34  dWorldID _id;
35
36  // intentionally undefined, don't use these
37  dWorld (const dWorld &);
38  void operator= (const dWorld &);
39
40public:
41  dWorld()
42    { _id = dWorldCreate(); }
43  ~dWorld()
44    { dWorldDestroy (_id); }
45
46  dWorldID id() const
47    { return _id; }
48  operator dWorldID() const
49    { return _id; }
50
51  void setGravity (dReal x, dReal y, dReal z)
52    { dWorldSetGravity (_id,x,y,z); }
53  void getGravity (dVector3 g) const
54    { dWorldGetGravity (_id,g); }
55
56  void setERP (dReal erp)
57    { dWorldSetERP(_id, erp); }
58  dReal getERP() const
59    { return dWorldGetERP(_id); }
60
61  void setCFM (dReal cfm)
62    { dWorldSetCFM(_id, cfm); }
63  dReal getCFM() const
64    { return dWorldGetCFM(_id); }
65
66  void step (dReal stepsize)
67    { dWorldStep (_id,stepsize); }
68
69  void stepFast1 (dReal stepsize, int maxiterations)
70    { dWorldStepFast1 (_id,stepsize,maxiterations); }
71  void setAutoEnableDepthSF1(dWorldID, int depth)
72    { dWorldSetAutoEnableDepthSF1 (_id, depth); }
73  int getAutoEnableDepthSF1(dWorldID)
74    { return dWorldGetAutoEnableDepthSF1 (_id); }
75
76  void  setAutoDisableLinearThreshold (dReal threshold)
77    { dWorldSetAutoDisableLinearThreshold (_id,threshold); }
78  dReal getAutoDisableLinearThreshold()
79    { return dWorldGetAutoDisableLinearThreshold (_id); }
80  void setAutoDisableAngularThreshold (dReal threshold)
81    { dWorldSetAutoDisableAngularThreshold (_id,threshold); }
82  dReal getAutoDisableAngularThreshold()
83    { return dWorldGetAutoDisableAngularThreshold (_id); }
84  void setAutoDisableSteps (int steps)
85    { dWorldSetAutoDisableSteps (_id,steps); }
86  int getAutoDisableSteps()
87    { return dWorldGetAutoDisableSteps (_id); }
88  void setAutoDisableTime (dReal time)
89    { dWorldSetAutoDisableTime (_id,time); }
90  dReal getAutoDisableTime()
91    { return dWorldGetAutoDisableTime (_id); }
92  void setAutoDisableFlag (int do_auto_disable)
93    { dWorldSetAutoDisableFlag (_id,do_auto_disable); }
94  int getAutoDisableFlag()
95    { return dWorldGetAutoDisableFlag (_id); }
96
97  void impulseToForce (dReal stepsize, dReal ix, dReal iy, dReal iz,
98                       dVector3 force)
99    { dWorldImpulseToForce (_id,stepsize,ix,iy,iz,force); }
100};
101
102
103class dBody {
104  dBodyID _id;
105
106  // intentionally undefined, don't use these
107  dBody (const dBody &);
108  void operator= (const dBody &);
109
110public:
111  dBody()
112    { _id = 0; }
113  dBody (dWorldID world)
114    { _id = dBodyCreate (world); }
115  ~dBody()
116    { if (_id) dBodyDestroy (_id); }
117
118  void create (dWorldID world) {
119    if (_id) dBodyDestroy (_id);
120    _id = dBodyCreate (world);
121  }
122
123  dBodyID id() const
124    { return _id; }
125  operator dBodyID() const
126    { return _id; }
127
128  void setData (void *data)
129    { dBodySetData (_id,data); }
130  void *getData() const
131    { return dBodyGetData (_id); }
132
133  void setPosition (dReal x, dReal y, dReal z)
134    { dBodySetPosition (_id,x,y,z); }
135  void setRotation (const dMatrix3 R)
136    { dBodySetRotation (_id,R); }
137  void setQuaternion (const dQuaternion q)
138    { dBodySetQuaternion (_id,q); }
139  void setLinearVel  (dReal x, dReal y, dReal z)
140    { dBodySetLinearVel (_id,x,y,z); }
141  void setAngularVel (dReal x, dReal y, dReal z)
142    { dBodySetAngularVel (_id,x,y,z); }
143
144  const dReal * getPosition() const
145    { return dBodyGetPosition (_id); }
146  const dReal * getRotation() const
147    { return dBodyGetRotation (_id); }
148  const dReal * getQuaternion() const
149    { return dBodyGetQuaternion (_id); }
150  const dReal * getLinearVel() const
151    { return dBodyGetLinearVel (_id); }
152  const dReal * getAngularVel() const
153    { return dBodyGetAngularVel (_id); }
154
155  void setMass (const dMass *mass)
156    { dBodySetMass (_id,mass); }
157  void getMass (dMass *mass) const
158    { dBodyGetMass (_id,mass); }
159
160  void addForce (dReal fx, dReal fy, dReal fz)
161    { dBodyAddForce (_id, fx, fy, fz); }
162  void addTorque (dReal fx, dReal fy, dReal fz)
163    { dBodyAddTorque (_id, fx, fy, fz); }
164  void addRelForce (dReal fx, dReal fy, dReal fz)
165    { dBodyAddRelForce (_id, fx, fy, fz); }
166  void addRelTorque (dReal fx, dReal fy, dReal fz)
167    { dBodyAddRelTorque (_id, fx, fy, fz); }
168  void addForceAtPos (dReal fx, dReal fy, dReal fz,
169                      dReal px, dReal py, dReal pz)
170    { dBodyAddForceAtPos (_id, fx, fy, fz, px, py, pz); }
171  void addForceAtRelPos (dReal fx, dReal fy, dReal fz,
172                      dReal px, dReal py, dReal pz)
173    { dBodyAddForceAtRelPos (_id, fx, fy, fz, px, py, pz); }
174  void addRelForceAtPos (dReal fx, dReal fy, dReal fz,
175                         dReal px, dReal py, dReal pz)
176    { dBodyAddRelForceAtPos (_id, fx, fy, fz, px, py, pz); }
177  void addRelForceAtRelPos (dReal fx, dReal fy, dReal fz,
178                            dReal px, dReal py, dReal pz)
179    { dBodyAddRelForceAtRelPos (_id, fx, fy, fz, px, py, pz); }
180
181  const dReal * getForce() const
182    { return dBodyGetForce(_id); }
183  const dReal * getTorque() const
184    { return dBodyGetTorque(_id); }
185  void setForce (dReal x, dReal y, dReal z)
186    { dBodySetForce (_id,x,y,z); }
187  void setTorque (dReal x, dReal y, dReal z)
188    { dBodySetTorque (_id,x,y,z); }
189
190  void enable()
191    { dBodyEnable (_id); }
192  void disable()
193    { dBodyDisable (_id); }
194  int isEnabled() const
195    { return dBodyIsEnabled (_id); }
196
197  void getRelPointPos (dReal px, dReal py, dReal pz, dVector3 result) const
198    { dBodyGetRelPointPos (_id, px, py, pz, result); }
199  void getRelPointVel (dReal px, dReal py, dReal pz, dVector3 result) const
200    { dBodyGetRelPointVel (_id, px, py, pz, result); }
201  void getPointVel (dReal px, dReal py, dReal pz, dVector3 result) const
202    { dBodyGetPointVel (_id,px,py,pz,result); }
203  void getPosRelPoint (dReal px, dReal py, dReal pz, dVector3 result) const
204    { dBodyGetPosRelPoint (_id,px,py,pz,result); }
205  void vectorToWorld (dReal px, dReal py, dReal pz, dVector3 result) const
206    { dBodyVectorToWorld (_id,px,py,pz,result); }
207  void vectorFromWorld (dReal px, dReal py, dReal pz, dVector3 result) const
208    { dBodyVectorFromWorld (_id,px,py,pz,result); }
209
210  void setFiniteRotationMode (int mode)
211    { dBodySetFiniteRotationMode (_id, mode); }
212  void setFiniteRotationAxis (dReal x, dReal y, dReal z)
213    { dBodySetFiniteRotationAxis (_id, x, y, z); }
214
215  int getFiniteRotationMode() const
216    { return dBodyGetFiniteRotationMode (_id); }
217  void getFiniteRotationAxis (dVector3 result) const
218    { dBodyGetFiniteRotationAxis (_id, result); }
219
220  int getNumJoints() const
221    { return dBodyGetNumJoints (_id); }
222  dJointID getJoint (int index) const
223    { return dBodyGetJoint (_id, index); }
224
225  void setGravityMode (int mode)
226    { dBodySetGravityMode (_id,mode); }
227  int getGravityMode() const
228    { return dBodyGetGravityMode (_id); }
229
230  int isConnectedTo (dBodyID body) const
231    { return dAreConnected (_id, body); }
232
233  void  setAutoDisableLinearThreshold (dReal threshold)
234    { dBodySetAutoDisableLinearThreshold (_id,threshold); }
235  dReal getAutoDisableLinearThreshold()
236    { return dBodyGetAutoDisableLinearThreshold (_id); }
237  void setAutoDisableAngularThreshold (dReal threshold)
238    { dBodySetAutoDisableAngularThreshold (_id,threshold); }
239  dReal getAutoDisableAngularThreshold()
240    { return dBodyGetAutoDisableAngularThreshold (_id); }
241  void setAutoDisableSteps (int steps)
242    { dBodySetAutoDisableSteps (_id,steps); }
243  int getAutoDisableSteps()
244    { return dBodyGetAutoDisableSteps (_id); }
245  void setAutoDisableTime (dReal time)
246    { dBodySetAutoDisableTime (_id,time); }
247  dReal getAutoDisableTime()
248    { return dBodyGetAutoDisableTime (_id); }
249  void setAutoDisableFlag (int do_auto_disable)
250    { dBodySetAutoDisableFlag (_id,do_auto_disable); }
251  int getAutoDisableFlag()
252    { return dBodyGetAutoDisableFlag (_id); }
253};
254
255
256class dJointGroup {
257  dJointGroupID _id;
258
259  // intentionally undefined, don't use these
260  dJointGroup (const dJointGroup &);
261  void operator= (const dJointGroup &);
262
263public:
264  dJointGroup (int dummy_arg=0)
265    { _id = dJointGroupCreate (0); }
266  ~dJointGroup()
267    { dJointGroupDestroy (_id); }
268  void create (int dummy_arg=0) {
269    if (_id) dJointGroupDestroy (_id);
270    _id = dJointGroupCreate (0);
271  }
272
273  dJointGroupID id() const
274    { return _id; }
275  operator dJointGroupID() const
276    { return _id; }
277
278  void empty()
279    { dJointGroupEmpty (_id); }
280};
281
282
283class dJoint {
284private:
285  // intentionally undefined, don't use these
286  dJoint (const dJoint &) ;
287  void operator= (const dJoint &);
288
289protected:
290  dJointID _id;
291
292public:
293  dJoint()
294    { _id = 0; }
295  ~dJoint()
296    { if (_id) dJointDestroy (_id); }
297
298  dJointID id() const
299    { return _id; }
300  operator dJointID() const
301    { return _id; }
302
303  void attach (dBodyID body1, dBodyID body2)
304    { dJointAttach (_id, body1, body2); }
305
306  void setData (void *data)
307    { dJointSetData (_id, data); }
308  void *getData() const
309    { return dJointGetData (_id); }
310
311  int getType() const
312    { return dJointGetType (_id); }
313
314  dBodyID getBody (int index) const
315    { return dJointGetBody (_id, index); }
316};
317
318
319class dBallJoint : public dJoint {
320private:
321  // intentionally undefined, don't use these
322  dBallJoint (const dBallJoint &);
323  void operator= (const dBallJoint &);
324
325public:
326  dBallJoint() { }
327  dBallJoint (dWorldID world, dJointGroupID group=0)
328    { _id = dJointCreateBall (world, group); }
329
330  void create (dWorldID world, dJointGroupID group=0) {
331    if (_id) dJointDestroy (_id);
332    _id = dJointCreateBall (world, group);
333  }
334
335  void setAnchor (dReal x, dReal y, dReal z)
336    { dJointSetBallAnchor (_id, x, y, z); }
337  void getAnchor (dVector3 result) const
338    { dJointGetBallAnchor (_id, result); }
339  void getAnchor2 (dVector3 result) const
340    { dJointGetBallAnchor2 (_id, result); }
341} ;
342
343
344class dHingeJoint : public dJoint {
345  // intentionally undefined, don't use these
346  dHingeJoint (const dHingeJoint &);
347  void operator = (const dHingeJoint &);
348
349public:
350  dHingeJoint() { }
351  dHingeJoint (dWorldID world, dJointGroupID group=0)
352    { _id = dJointCreateHinge (world, group); }
353
354  void create (dWorldID world, dJointGroupID group=0) {
355    if (_id) dJointDestroy (_id);
356    _id = dJointCreateHinge (world, group);
357  }
358
359  void setAnchor (dReal x, dReal y, dReal z)
360    { dJointSetHingeAnchor (_id, x, y, z); }
361  void getAnchor (dVector3 result) const
362    { dJointGetHingeAnchor (_id, result); }
363  void getAnchor2 (dVector3 result) const
364    { dJointGetHingeAnchor2 (_id, result); }
365
366  void setAxis (dReal x, dReal y, dReal z)
367    { dJointSetHingeAxis (_id, x, y, z); }
368  void getAxis (dVector3 result) const
369    { dJointGetHingeAxis (_id, result); }
370
371  dReal getAngle() const
372    { return dJointGetHingeAngle (_id); }
373  dReal getAngleRate() const
374    { return dJointGetHingeAngleRate (_id); }
375
376  void setParam (int parameter, dReal value)
377    { dJointSetHingeParam (_id, parameter, value); }
378  dReal getParam (int parameter) const
379    { return dJointGetHingeParam (_id, parameter); }
380
381  void addTorque (dReal torque)
382        { dJointAddHingeTorque(_id, torque); }
383};
384
385
386class dSliderJoint : public dJoint {
387  // intentionally undefined, don't use these
388  dSliderJoint (const dSliderJoint &);
389  void operator = (const dSliderJoint &);
390
391public:
392  dSliderJoint() { }
393  dSliderJoint (dWorldID world, dJointGroupID group=0)
394    { _id = dJointCreateSlider (world, group); }
395
396  void create (dWorldID world, dJointGroupID group=0) {
397    if (_id) dJointDestroy (_id);
398    _id = dJointCreateSlider (world, group);
399  }
400
401  void setAxis (dReal x, dReal y, dReal z)
402    { dJointSetSliderAxis (_id, x, y, z); }
403  void getAxis (dVector3 result) const
404    { dJointGetSliderAxis (_id, result); }
405
406  dReal getPosition() const
407    { return dJointGetSliderPosition (_id); }
408  dReal getPositionRate() const
409    { return dJointGetSliderPositionRate (_id); }
410
411  void setParam (int parameter, dReal value)
412    { dJointSetSliderParam (_id, parameter, value); }
413  dReal getParam (int parameter) const
414    { return dJointGetSliderParam (_id, parameter); }
415
416  void addForce (dReal force)
417        { dJointAddSliderForce(_id, force); }
418};
419
420
421class dUniversalJoint : public dJoint {
422  // intentionally undefined, don't use these
423  dUniversalJoint (const dUniversalJoint &);
424  void operator = (const dUniversalJoint &);
425
426public:
427  dUniversalJoint() { }
428  dUniversalJoint (dWorldID world, dJointGroupID group=0)
429    { _id = dJointCreateUniversal (world, group); }
430
431  void create (dWorldID world, dJointGroupID group=0) {
432    if (_id) dJointDestroy (_id);
433    _id = dJointCreateUniversal (world, group);
434  }
435
436  void setAnchor (dReal x, dReal y, dReal z)
437    { dJointSetUniversalAnchor (_id, x, y, z); }
438  void setAxis1 (dReal x, dReal y, dReal z)
439    { dJointSetUniversalAxis1 (_id, x, y, z); }
440  void setAxis2 (dReal x, dReal y, dReal z)
441    { dJointSetUniversalAxis2 (_id, x, y, z); }
442  void setParam (int parameter, dReal value)
443    { dJointSetUniversalParam (_id, parameter, value); }
444
445  void getAnchor (dVector3 result) const
446    { dJointGetUniversalAnchor (_id, result); }
447  void getAnchor2 (dVector3 result) const
448    { dJointGetUniversalAnchor2 (_id, result); }
449  void getAxis1 (dVector3 result) const
450    { dJointGetUniversalAxis1 (_id, result); }
451  void getAxis2 (dVector3 result) const
452    { dJointGetUniversalAxis2 (_id, result); }
453  dReal getParam (int parameter) const
454    { return dJointGetUniversalParam (_id, parameter); }
455  dReal getAngle1() const
456    { return dJointGetUniversalAngle1 (_id); }
457  dReal getAngle1Rate() const
458    { return dJointGetUniversalAngle1Rate (_id); }
459  dReal getAngle2() const
460    { return dJointGetUniversalAngle2 (_id); }
461  dReal getAngle2Rate() const
462    { return dJointGetUniversalAngle2Rate (_id); }
463
464  void addTorques (dReal torque1, dReal torque2)
465        { dJointAddUniversalTorques(_id, torque1, torque2); }
466};
467
468
469class dHinge2Joint : public dJoint {
470  // intentionally undefined, don't use these
471  dHinge2Joint (const dHinge2Joint &);
472  void operator = (const dHinge2Joint &);
473
474public:
475  dHinge2Joint() { }
476  dHinge2Joint (dWorldID world, dJointGroupID group=0)
477    { _id = dJointCreateHinge2 (world, group); }
478
479  void create (dWorldID world, dJointGroupID group=0) {
480    if (_id) dJointDestroy (_id);
481    _id = dJointCreateHinge2 (world, group);
482  }
483
484  void setAnchor (dReal x, dReal y, dReal z)
485    { dJointSetHinge2Anchor (_id, x, y, z); }
486  void setAxis1 (dReal x, dReal y, dReal z)
487    { dJointSetHinge2Axis1 (_id, x, y, z); }
488  void setAxis2 (dReal x, dReal y, dReal z)
489    { dJointSetHinge2Axis2 (_id, x, y, z); }
490
491  void getAnchor (dVector3 result) const
492    { dJointGetHinge2Anchor (_id, result); }
493  void getAnchor2 (dVector3 result) const
494    { dJointGetHinge2Anchor2 (_id, result); }
495  void getAxis1 (dVector3 result) const
496    { dJointGetHinge2Axis1 (_id, result); }
497  void getAxis2 (dVector3 result) const
498    { dJointGetHinge2Axis2 (_id, result); }
499
500  dReal getAngle1() const
501    { return dJointGetHinge2Angle1 (_id); }
502  dReal getAngle1Rate() const
503    { return dJointGetHinge2Angle1Rate (_id); }
504  dReal getAngle2Rate() const
505    { return dJointGetHinge2Angle2Rate (_id); }
506
507  void setParam (int parameter, dReal value)
508    { dJointSetHinge2Param (_id, parameter, value); }
509  dReal getParam (int parameter) const
510    { return dJointGetHinge2Param (_id, parameter); }
511
512  void addTorques(dReal torque1, dReal torque2)
513        { dJointAddHinge2Torques(_id, torque1, torque2); }
514};
515
516
517class dFixedJoint : public dJoint {
518  // intentionally undefined, don't use these
519  dFixedJoint (const dFixedJoint &);
520  void operator = (const dFixedJoint &);
521
522public:
523  dFixedJoint() { }
524  dFixedJoint (dWorldID world, dJointGroupID group=0)
525    { _id = dJointCreateFixed (world, group); }
526
527  void create (dWorldID world, dJointGroupID group=0) {
528    if (_id) dJointDestroy (_id);
529    _id = dJointCreateFixed (world, group);
530  }
531
532  void set()
533    { dJointSetFixed (_id); }
534};
535
536
537class dContactJoint : public dJoint {
538  // intentionally undefined, don't use these
539  dContactJoint (const dContactJoint &);
540  void operator = (const dContactJoint &);
541
542public:
543  dContactJoint() { }
544  dContactJoint (dWorldID world, dJointGroupID group, dContact *contact)
545    { _id = dJointCreateContact (world, group, contact); }
546
547  void create (dWorldID world, dJointGroupID group, dContact *contact) {
548    if (_id) dJointDestroy (_id);
549    _id = dJointCreateContact (world, group, contact);
550  }
551};
552
553
554class dNullJoint : public dJoint {
555  // intentionally undefined, don't use these
556  dNullJoint (const dNullJoint &);
557  void operator = (const dNullJoint &);
558
559public:
560  dNullJoint() { }
561  dNullJoint (dWorldID world, dJointGroupID group=0)
562    { _id = dJointCreateNull (world, group); }
563
564  void create (dWorldID world, dJointGroupID group=0) {
565    if (_id) dJointDestroy (_id);
566    _id = dJointCreateNull (world, group);
567  }
568};
569
570
571class dAMotorJoint : public dJoint {
572  // intentionally undefined, don't use these
573  dAMotorJoint (const dAMotorJoint &);
574  void operator = (const dAMotorJoint &);
575
576public:
577  dAMotorJoint() { }
578  dAMotorJoint (dWorldID world, dJointGroupID group=0)
579    { _id = dJointCreateAMotor (world, group); }
580
581  void create (dWorldID world, dJointGroupID group=0) {
582    if (_id) dJointDestroy (_id);
583    _id = dJointCreateAMotor (world, group);
584  }
585
586  void setMode (int mode)
587    { dJointSetAMotorMode (_id, mode); }
588  int getMode() const
589    { return dJointGetAMotorMode (_id); }
590
591  void setNumAxes (int num)
592    { dJointSetAMotorNumAxes (_id, num); }
593  int getNumAxes() const
594    { return dJointGetAMotorNumAxes (_id); }
595
596  void setAxis (int anum, int rel, dReal x, dReal y, dReal z)
597    { dJointSetAMotorAxis (_id, anum, rel, x, y, z); }
598  void getAxis (int anum, dVector3 result) const
599    { dJointGetAMotorAxis (_id, anum, result); }
600  int getAxisRel (int anum) const
601    { return dJointGetAMotorAxisRel (_id, anum); }
602
603  void setAngle (int anum, dReal angle)
604    { dJointSetAMotorAngle (_id, anum, angle); }
605  dReal getAngle (int anum) const
606    { return dJointGetAMotorAngle (_id, anum); }
607  dReal getAngleRate (int anum)
608    { return dJointGetAMotorAngleRate (_id,anum); }
609
610  void setParam (int parameter, dReal value)
611    { dJointSetAMotorParam (_id, parameter, value); }
612  dReal getParam (int parameter) const
613    { return dJointGetAMotorParam (_id, parameter); }
614
615  void addTorques(dReal torque1, dReal torque2, dReal torque3)
616        { dJointAddAMotorTorques(_id, torque1, torque2, torque3); }
617};
618
619
620#endif
621#endif
Note: See TracBrowser for help on using the repository browser.