odecpp.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] 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. /* C++ interface for non-collision stuff */
  23. #ifndef _ODE_ODECPP_H_
  24. #define _ODE_ODECPP_H_
  25. #ifdef __cplusplus
  26. //namespace ode {
  27. class dWorld {
  28. dWorldID _id;
  29. // intentionally undefined, don't use these
  30. dWorld (const dWorld &);
  31. void operator= (const dWorld &);
  32. public:
  33. dWorld()
  34. { _id = dWorldCreate(); }
  35. ~dWorld()
  36. { dWorldDestroy (_id); }
  37. dWorldID id() const
  38. { return _id; }
  39. operator dWorldID() const
  40. { return _id; }
  41. void setGravity (dReal x, dReal y, dReal z)
  42. { dWorldSetGravity (_id,x,y,z); }
  43. void setGravity (const dVector3 g)
  44. { setGravity (g[0], g[1], g[2]); }
  45. void getGravity (dVector3 g) const
  46. { dWorldGetGravity (_id,g); }
  47. void setERP (dReal erp)
  48. { dWorldSetERP(_id, erp); }
  49. dReal getERP() const
  50. { return dWorldGetERP(_id); }
  51. void setCFM (dReal cfm)
  52. { dWorldSetCFM(_id, cfm); }
  53. dReal getCFM() const
  54. { return dWorldGetCFM(_id); }
  55. void step (dReal stepsize)
  56. { dWorldStep (_id,stepsize); }
  57. void stepFast1 (dReal stepsize, int maxiterations)
  58. { dWorldStepFast1 (_id,stepsize,maxiterations); }
  59. void setAutoEnableDepthSF1(dWorldID, int depth)
  60. { dWorldSetAutoEnableDepthSF1 (_id, depth); }
  61. int getAutoEnableDepthSF1(dWorldID) const
  62. { return dWorldGetAutoEnableDepthSF1 (_id); }
  63. void quickStep(dReal stepsize)
  64. { dWorldQuickStep (_id, stepsize); }
  65. void setQuickStepNumIterations(int num)
  66. { dWorldSetQuickStepNumIterations (_id, num); }
  67. int getQuickStepNumIterations() const
  68. { return dWorldGetQuickStepNumIterations (_id); }
  69. void setQuickStepW(dReal over_relaxation)
  70. { dWorldSetQuickStepW (_id, over_relaxation); }
  71. dReal getQuickStepW() const
  72. { return dWorldGetQuickStepW (_id); }
  73. void setAutoDisableLinearThreshold (dReal threshold)
  74. { dWorldSetAutoDisableLinearThreshold (_id,threshold); }
  75. dReal getAutoDisableLinearThreshold() const
  76. { return dWorldGetAutoDisableLinearThreshold (_id); }
  77. void setAutoDisableAngularThreshold (dReal threshold)
  78. { dWorldSetAutoDisableAngularThreshold (_id,threshold); }
  79. dReal getAutoDisableAngularThreshold() const
  80. { return dWorldGetAutoDisableAngularThreshold (_id); }
  81. void setAutoDisableSteps (int steps)
  82. { dWorldSetAutoDisableSteps (_id,steps); }
  83. int getAutoDisableSteps() const
  84. { return dWorldGetAutoDisableSteps (_id); }
  85. void setAutoDisableTime (dReal time)
  86. { dWorldSetAutoDisableTime (_id,time); }
  87. dReal getAutoDisableTime() const
  88. { return dWorldGetAutoDisableTime (_id); }
  89. void setAutoDisableFlag (int do_auto_disable)
  90. { dWorldSetAutoDisableFlag (_id,do_auto_disable); }
  91. int getAutoDisableFlag() const
  92. { return dWorldGetAutoDisableFlag (_id); }
  93. dReal getLinearDampingThreshold() const
  94. { return dWorldGetLinearDampingThreshold(_id); }
  95. void setLinearDampingThreshold(dReal threshold)
  96. { dWorldSetLinearDampingThreshold(_id, threshold); }
  97. dReal getAngularDampingThreshold() const
  98. { return dWorldGetAngularDampingThreshold(_id); }
  99. void setAngularDampingThreshold(dReal threshold)
  100. { dWorldSetAngularDampingThreshold(_id, threshold); }
  101. dReal getLinearDamping() const
  102. { return dWorldGetLinearDamping(_id); }
  103. void setLinearDamping(dReal scale)
  104. { dWorldSetLinearDamping(_id, scale); }
  105. dReal getAngularDamping() const
  106. { return dWorldGetAngularDamping(_id); }
  107. void setAngularDamping(dReal scale)
  108. { dWorldSetAngularDamping(_id, scale); }
  109. void setDamping(dReal linear_scale, dReal angular_scale)
  110. { dWorldSetDamping(_id, linear_scale, angular_scale); }
  111. dReal getMaxAngularSpeed() const
  112. { return dWorldGetMaxAngularSpeed(_id); }
  113. void setMaxAngularSpeed(dReal max_speed)
  114. { dWorldSetMaxAngularSpeed(_id, max_speed); }
  115. void setContactSurfaceLayer(dReal depth)
  116. { dWorldSetContactSurfaceLayer (_id, depth); }
  117. dReal getContactSurfaceLayer() const
  118. { return dWorldGetContactSurfaceLayer (_id); }
  119. void impulseToForce (dReal stepsize, dReal ix, dReal iy, dReal iz,
  120. dVector3 force)
  121. { dWorldImpulseToForce (_id,stepsize,ix,iy,iz,force); }
  122. };
  123. class dBody {
  124. dBodyID _id;
  125. // intentionally undefined, don't use these
  126. dBody (const dBody &);
  127. void operator= (const dBody &);
  128. public:
  129. dBody()
  130. { _id = 0; }
  131. dBody (dWorldID world)
  132. { _id = dBodyCreate (world); }
  133. dBody (dWorld& world)
  134. { _id = dBodyCreate (world.id()); }
  135. ~dBody()
  136. { if (_id) dBodyDestroy (_id); }
  137. void create (dWorldID world) {
  138. if (_id) dBodyDestroy (_id);
  139. _id = dBodyCreate (world);
  140. }
  141. void create (dWorld& world) {
  142. create(world.id());
  143. }
  144. dBodyID id() const
  145. { return _id; }
  146. operator dBodyID() const
  147. { return _id; }
  148. void setData (void *data)
  149. { dBodySetData (_id,data); }
  150. void *getData() const
  151. { return dBodyGetData (_id); }
  152. void setPosition (dReal x, dReal y, dReal z)
  153. { dBodySetPosition (_id,x,y,z); }
  154. void setPosition (const dVector3 p)
  155. { setPosition(p[0], p[1], p[2]); }
  156. void setRotation (const dMatrix3 R)
  157. { dBodySetRotation (_id,R); }
  158. void setQuaternion (const dQuaternion q)
  159. { dBodySetQuaternion (_id,q); }
  160. void setLinearVel (dReal x, dReal y, dReal z)
  161. { dBodySetLinearVel (_id,x,y,z); }
  162. void setLinearVel (const dVector3 v)
  163. { setLinearVel(v[0], v[1], v[2]); }
  164. void setAngularVel (dReal x, dReal y, dReal z)
  165. { dBodySetAngularVel (_id,x,y,z); }
  166. void setAngularVel (const dVector3 v)
  167. { setAngularVel (v[0], v[1], v[2]); }
  168. const dReal * getPosition() const
  169. { return dBodyGetPosition (_id); }
  170. const dReal * getRotation() const
  171. { return dBodyGetRotation (_id); }
  172. const dReal * getQuaternion() const
  173. { return dBodyGetQuaternion (_id); }
  174. const dReal * getLinearVel() const
  175. { return dBodyGetLinearVel (_id); }
  176. const dReal * getAngularVel() const
  177. { return dBodyGetAngularVel (_id); }
  178. void setMass (const dMass *mass)
  179. { dBodySetMass (_id,mass); }
  180. void setMass (const dMass &mass)
  181. { setMass (&mass); }
  182. dMass getMass () const
  183. { dMass mass; dBodyGetMass (_id,&mass); return mass; }
  184. void addForce (dReal fx, dReal fy, dReal fz)
  185. { dBodyAddForce (_id, fx, fy, fz); }
  186. void addForce (const dVector3 f)
  187. { addForce (f[0], f[1], f[2]); }
  188. void addTorque (dReal fx, dReal fy, dReal fz)
  189. { dBodyAddTorque (_id, fx, fy, fz); }
  190. void addTorque (const dVector3 t)
  191. { addTorque(t[0], t[1], t[2]); }
  192. void addRelForce (dReal fx, dReal fy, dReal fz)
  193. { dBodyAddRelForce (_id, fx, fy, fz); }
  194. void addRelForce (const dVector3 f)
  195. { addRelForce (f[0], f[1], f[2]); }
  196. void addRelTorque (dReal fx, dReal fy, dReal fz)
  197. { dBodyAddRelTorque (_id, fx, fy, fz); }
  198. void addRelTorque (const dVector3 t)
  199. { addRelTorque (t[0], t[1], t[2]); }
  200. void addForceAtPos (dReal fx, dReal fy, dReal fz,
  201. dReal px, dReal py, dReal pz)
  202. { dBodyAddForceAtPos (_id, fx, fy, fz, px, py, pz); }
  203. void addForceAtPos (const dVector3 f, const dVector3 p)
  204. { addForceAtPos (f[0], f[1], f[2], p[0], p[1], p[2]); }
  205. void addForceAtRelPos (dReal fx, dReal fy, dReal fz,
  206. dReal px, dReal py, dReal pz)
  207. { dBodyAddForceAtRelPos (_id, fx, fy, fz, px, py, pz); }
  208. void addForceAtRelPos (const dVector3 f, const dVector3 p)
  209. { addForceAtRelPos (f[0], f[1], f[2], p[0], p[1], p[2]); }
  210. void addRelForceAtPos (dReal fx, dReal fy, dReal fz,
  211. dReal px, dReal py, dReal pz)
  212. { dBodyAddRelForceAtPos (_id, fx, fy, fz, px, py, pz); }
  213. void addRelForceAtPos (const dVector3 f, const dVector3 p)
  214. { addRelForceAtPos (f[0], f[1], f[2], p[0], p[1], p[2]); }
  215. void addRelForceAtRelPos (dReal fx, dReal fy, dReal fz,
  216. dReal px, dReal py, dReal pz)
  217. { dBodyAddRelForceAtRelPos (_id, fx, fy, fz, px, py, pz); }
  218. void addRelForceAtRelPos (const dVector3 f, const dVector3 p)
  219. { addRelForceAtRelPos (f[0], f[1], f[2], p[0], p[1], p[2]); }
  220. const dReal * getForce() const
  221. { return dBodyGetForce(_id); }
  222. const dReal * getTorque() const
  223. { return dBodyGetTorque(_id); }
  224. void setForce (dReal x, dReal y, dReal z)
  225. { dBodySetForce (_id,x,y,z); }
  226. void setForce (const dVector3 f)
  227. { setForce (f[0], f[1], f[2]); }
  228. void setTorque (dReal x, dReal y, dReal z)
  229. { dBodySetTorque (_id,x,y,z); }
  230. void setTorque (const dVector3 t)
  231. { setTorque (t[0], t[1], t[2]); }
  232. void enable()
  233. { dBodyEnable (_id); }
  234. void disable()
  235. { dBodyDisable (_id); }
  236. bool isEnabled() const
  237. { return dBodyIsEnabled (_id) != 0; }
  238. void getRelPointPos (dReal px, dReal py, dReal pz, dVector3 result) const
  239. { dBodyGetRelPointPos (_id, px, py, pz, result); }
  240. void getRelPointPos (const dVector3 p, dVector3 result) const
  241. { getRelPointPos (p[0], p[1], p[2], result); }
  242. void getRelPointVel (dReal px, dReal py, dReal pz, dVector3 result) const
  243. { dBodyGetRelPointVel (_id, px, py, pz, result); }
  244. void getRelPointVel (const dVector3 p, dVector3 result) const
  245. { getRelPointVel (p[0], p[1], p[2], result); }
  246. void getPointVel (dReal px, dReal py, dReal pz, dVector3 result) const
  247. { dBodyGetPointVel (_id, px, py, pz, result); }
  248. void getPointVel (const dVector3 p, dVector3 result) const
  249. { getPointVel (p[0], p[1], p[2], result); }
  250. void getPosRelPoint (dReal px, dReal py, dReal pz, dVector3 result) const
  251. { dBodyGetPosRelPoint (_id, px, py, pz, result); }
  252. void getPosRelPoint (const dVector3 p, dVector3 result) const
  253. { getPosRelPoint (p[0], p[1], p[2], result); }
  254. void vectorToWorld (dReal px, dReal py, dReal pz, dVector3 result) const
  255. { dBodyVectorToWorld (_id, px, py, pz, result); }
  256. void vectorToWorld (const dVector3 p, dVector3 result) const
  257. { vectorToWorld (p[0], p[1], p[2], result); }
  258. void vectorFromWorld (dReal px, dReal py, dReal pz, dVector3 result) const
  259. { dBodyVectorFromWorld (_id,px,py,pz,result); }
  260. void vectorFromWorld (const dVector3 p, dVector3 result) const
  261. { vectorFromWorld (p[0], p[1], p[2], result); }
  262. void setFiniteRotationMode (bool mode)
  263. { dBodySetFiniteRotationMode (_id, mode); }
  264. void setFiniteRotationAxis (dReal x, dReal y, dReal z)
  265. { dBodySetFiniteRotationAxis (_id, x, y, z); }
  266. void setFiniteRotationAxis (const dVector3 a)
  267. { setFiniteRotationAxis (a[0], a[1], a[2]); }
  268. bool getFiniteRotationMode() const
  269. { return dBodyGetFiniteRotationMode (_id) != 0; }
  270. void getFiniteRotationAxis (dVector3 result) const
  271. { dBodyGetFiniteRotationAxis (_id, result); }
  272. int getNumJoints() const
  273. { return dBodyGetNumJoints (_id); }
  274. dJointID getJoint (int index) const
  275. { return dBodyGetJoint (_id, index); }
  276. void setGravityMode (bool mode)
  277. { dBodySetGravityMode (_id,mode); }
  278. bool getGravityMode() const
  279. { return dBodyGetGravityMode (_id) != 0; }
  280. bool isConnectedTo (dBodyID body) const
  281. { return dAreConnected (_id, body) != 0; }
  282. void setAutoDisableLinearThreshold (dReal threshold)
  283. { dBodySetAutoDisableLinearThreshold (_id,threshold); }
  284. dReal getAutoDisableLinearThreshold() const
  285. { return dBodyGetAutoDisableLinearThreshold (_id); }
  286. void setAutoDisableAngularThreshold (dReal threshold)
  287. { dBodySetAutoDisableAngularThreshold (_id,threshold); }
  288. dReal getAutoDisableAngularThreshold() const
  289. { return dBodyGetAutoDisableAngularThreshold (_id); }
  290. void setAutoDisableSteps (int steps)
  291. { dBodySetAutoDisableSteps (_id,steps); }
  292. int getAutoDisableSteps() const
  293. { return dBodyGetAutoDisableSteps (_id); }
  294. void setAutoDisableTime (dReal time)
  295. { dBodySetAutoDisableTime (_id,time); }
  296. dReal getAutoDisableTime() const
  297. { return dBodyGetAutoDisableTime (_id); }
  298. void setAutoDisableFlag (bool do_auto_disable)
  299. { dBodySetAutoDisableFlag (_id,do_auto_disable); }
  300. bool getAutoDisableFlag() const
  301. { return dBodyGetAutoDisableFlag (_id) != 0; }
  302. dReal getLinearDamping() const
  303. { return dBodyGetLinearDamping(_id); }
  304. void setLinearDamping(dReal scale)
  305. { dBodySetLinearDamping(_id, scale); }
  306. dReal getAngularDamping() const
  307. { return dBodyGetAngularDamping(_id); }
  308. void setAngularDamping(dReal scale)
  309. { dBodySetAngularDamping(_id, scale); }
  310. void setDamping(dReal linear_scale, dReal angular_scale)
  311. { dBodySetDamping(_id, linear_scale, angular_scale); }
  312. dReal getLinearDampingThreshold() const
  313. { return dBodyGetLinearDampingThreshold(_id); }
  314. void setLinearDampingThreshold(dReal threshold) const
  315. { dBodySetLinearDampingThreshold(_id, threshold); }
  316. dReal getAngularDampingThreshold() const
  317. { return dBodyGetAngularDampingThreshold(_id); }
  318. void setAngularDampingThreshold(dReal threshold)
  319. { dBodySetAngularDampingThreshold(_id, threshold); }
  320. void setDampingDefaults()
  321. { dBodySetDampingDefaults(_id); }
  322. dReal getMaxAngularSpeed() const
  323. { return dBodyGetMaxAngularSpeed(_id); }
  324. void setMaxAngularSpeed(dReal max_speed)
  325. { dBodySetMaxAngularSpeed(_id, max_speed); }
  326. };
  327. class dJointGroup {
  328. dJointGroupID _id;
  329. // intentionally undefined, don't use these
  330. dJointGroup (const dJointGroup &);
  331. void operator= (const dJointGroup &);
  332. public:
  333. dJointGroup (int dummy_arg=0)
  334. { _id = dJointGroupCreate (0); }
  335. ~dJointGroup()
  336. { dJointGroupDestroy (_id); }
  337. void create (int dummy_arg=0) {
  338. if (_id) dJointGroupDestroy (_id);
  339. _id = dJointGroupCreate (0);
  340. }
  341. dJointGroupID id() const
  342. { return _id; }
  343. operator dJointGroupID() const
  344. { return _id; }
  345. void empty()
  346. { dJointGroupEmpty (_id); }
  347. void clear()
  348. { empty(); }
  349. };
  350. class dJoint {
  351. private:
  352. // intentionally undefined, don't use these
  353. dJoint (const dJoint &) ;
  354. void operator= (const dJoint &);
  355. protected:
  356. dJointID _id;
  357. dJoint() // don't let user construct pure dJoint objects
  358. { _id = 0; }
  359. public:
  360. virtual ~dJoint() // :( Destructor must be virtual to suppress compiler warning "class XXX has virtual functions but non-virtual destructor"
  361. { if (_id) dJointDestroy (_id); }
  362. dJointID id() const
  363. { return _id; }
  364. operator dJointID() const
  365. { return _id; }
  366. int getNumBodies() const
  367. { return dJointGetNumBodies(_id); }
  368. void attach (dBodyID body1, dBodyID body2)
  369. { dJointAttach (_id, body1, body2); }
  370. void attach (dBody& body1, dBody& body2)
  371. { attach(body1.id(), body2.id()); }
  372. void setData (void *data)
  373. { dJointSetData (_id, data); }
  374. void *getData() const
  375. { return dJointGetData (_id); }
  376. dJointType getType() const
  377. { return dJointGetType (_id); }
  378. dBodyID getBody (int index) const
  379. { return dJointGetBody (_id, index); }
  380. void setFeedback(dJointFeedback *fb)
  381. { dJointSetFeedback(_id, fb); }
  382. dJointFeedback *getFeedback() const
  383. { return dJointGetFeedback(_id); }
  384. // If not implemented it will do nothing as describe in the doc
  385. virtual void setParam (int, dReal) {};
  386. virtual dReal getParam (int) const { return 0; }
  387. };
  388. class dBallJoint : public dJoint {
  389. private:
  390. // intentionally undefined, don't use these
  391. dBallJoint (const dBallJoint &);
  392. void operator= (const dBallJoint &);
  393. public:
  394. dBallJoint() { }
  395. dBallJoint (dWorldID world, dJointGroupID group=0)
  396. { _id = dJointCreateBall (world, group); }
  397. dBallJoint (dWorld& world, dJointGroupID group=0)
  398. { _id = dJointCreateBall (world.id(), group); }
  399. void create (dWorldID world, dJointGroupID group=0) {
  400. if (_id) dJointDestroy (_id);
  401. _id = dJointCreateBall (world, group);
  402. }
  403. void create (dWorld& world, dJointGroupID group=0)
  404. { create(world.id(), group); }
  405. void setAnchor (dReal x, dReal y, dReal z)
  406. { dJointSetBallAnchor (_id, x, y, z); }
  407. void setAnchor (const dVector3 a)
  408. { setAnchor (a[0], a[1], a[2]); }
  409. void getAnchor (dVector3 result) const
  410. { dJointGetBallAnchor (_id, result); }
  411. void getAnchor2 (dVector3 result) const
  412. { dJointGetBallAnchor2 (_id, result); }
  413. virtual void setParam (int parameter, dReal value)
  414. { dJointSetBallParam (_id, parameter, value); }
  415. virtual dReal getParam (int parameter) const
  416. { return dJointGetBallParam (_id, parameter); }
  417. // TODO: expose params through methods
  418. } ;
  419. class dHingeJoint : public dJoint {
  420. // intentionally undefined, don't use these
  421. dHingeJoint (const dHingeJoint &);
  422. void operator = (const dHingeJoint &);
  423. public:
  424. dHingeJoint() { }
  425. dHingeJoint (dWorldID world, dJointGroupID group=0)
  426. { _id = dJointCreateHinge (world, group); }
  427. dHingeJoint (dWorld& world, dJointGroupID group=0)
  428. { _id = dJointCreateHinge (world.id(), group); }
  429. void create (dWorldID world, dJointGroupID group=0) {
  430. if (_id) dJointDestroy (_id);
  431. _id = dJointCreateHinge (world, group);
  432. }
  433. void create (dWorld& world, dJointGroupID group=0)
  434. { create(world.id(), group); }
  435. void setAnchor (dReal x, dReal y, dReal z)
  436. { dJointSetHingeAnchor (_id, x, y, z); }
  437. void setAnchor (const dVector3 a)
  438. { setAnchor (a[0], a[1], a[2]); }
  439. void getAnchor (dVector3 result) const
  440. { dJointGetHingeAnchor (_id, result); }
  441. void getAnchor2 (dVector3 result) const
  442. { dJointGetHingeAnchor2 (_id, result); }
  443. void setAxis (dReal x, dReal y, dReal z)
  444. { dJointSetHingeAxis (_id, x, y, z); }
  445. void setAxis (const dVector3 a)
  446. { setAxis(a[0], a[1], a[2]); }
  447. void getAxis (dVector3 result) const
  448. { dJointGetHingeAxis (_id, result); }
  449. dReal getAngle() const
  450. { return dJointGetHingeAngle (_id); }
  451. dReal getAngleRate() const
  452. { return dJointGetHingeAngleRate (_id); }
  453. virtual void setParam (int parameter, dReal value)
  454. { dJointSetHingeParam (_id, parameter, value); }
  455. virtual dReal getParam (int parameter) const
  456. { return dJointGetHingeParam (_id, parameter); }
  457. // TODO: expose params through methods
  458. void addTorque (dReal torque)
  459. { dJointAddHingeTorque(_id, torque); }
  460. };
  461. class dSliderJoint : public dJoint {
  462. // intentionally undefined, don't use these
  463. dSliderJoint (const dSliderJoint &);
  464. void operator = (const dSliderJoint &);
  465. public:
  466. dSliderJoint() { }
  467. dSliderJoint (dWorldID world, dJointGroupID group=0)
  468. { _id = dJointCreateSlider (world, group); }
  469. dSliderJoint (dWorld& world, dJointGroupID group=0)
  470. { _id = dJointCreateSlider (world.id(), group); }
  471. void create (dWorldID world, dJointGroupID group=0) {
  472. if (_id) dJointDestroy (_id);
  473. _id = dJointCreateSlider (world, group);
  474. }
  475. void create (dWorld& world, dJointGroupID group=0)
  476. { create(world.id(), group); }
  477. void setAxis (dReal x, dReal y, dReal z)
  478. { dJointSetSliderAxis (_id, x, y, z); }
  479. void setAxis (const dVector3 a)
  480. { setAxis (a[0], a[1], a[2]); }
  481. void getAxis (dVector3 result) const
  482. { dJointGetSliderAxis (_id, result); }
  483. dReal getPosition() const
  484. { return dJointGetSliderPosition (_id); }
  485. dReal getPositionRate() const
  486. { return dJointGetSliderPositionRate (_id); }
  487. virtual void setParam (int parameter, dReal value)
  488. { dJointSetSliderParam (_id, parameter, value); }
  489. virtual dReal getParam (int parameter) const
  490. { return dJointGetSliderParam (_id, parameter); }
  491. // TODO: expose params through methods
  492. void addForce (dReal force)
  493. { dJointAddSliderForce(_id, force); }
  494. };
  495. class dUniversalJoint : public dJoint {
  496. // intentionally undefined, don't use these
  497. dUniversalJoint (const dUniversalJoint &);
  498. void operator = (const dUniversalJoint &);
  499. public:
  500. dUniversalJoint() { }
  501. dUniversalJoint (dWorldID world, dJointGroupID group=0)
  502. { _id = dJointCreateUniversal (world, group); }
  503. dUniversalJoint (dWorld& world, dJointGroupID group=0)
  504. { _id = dJointCreateUniversal (world.id(), group); }
  505. void create (dWorldID world, dJointGroupID group=0) {
  506. if (_id) dJointDestroy (_id);
  507. _id = dJointCreateUniversal (world, group);
  508. }
  509. void create (dWorld& world, dJointGroupID group=0)
  510. { create(world.id(), group); }
  511. void setAnchor (dReal x, dReal y, dReal z)
  512. { dJointSetUniversalAnchor (_id, x, y, z); }
  513. void setAnchor (const dVector3 a)
  514. { setAnchor(a[0], a[1], a[2]); }
  515. void setAxis1 (dReal x, dReal y, dReal z)
  516. { dJointSetUniversalAxis1 (_id, x, y, z); }
  517. void setAxis1 (const dVector3 a)
  518. { setAxis1 (a[0], a[1], a[2]); }
  519. void setAxis2 (dReal x, dReal y, dReal z)
  520. { dJointSetUniversalAxis2 (_id, x, y, z); }
  521. void setAxis2 (const dVector3 a)
  522. { setAxis2 (a[0], a[1], a[2]); }
  523. void getAnchor (dVector3 result) const
  524. { dJointGetUniversalAnchor (_id, result); }
  525. void getAnchor2 (dVector3 result) const
  526. { dJointGetUniversalAnchor2 (_id, result); }
  527. void getAxis1 (dVector3 result) const
  528. { dJointGetUniversalAxis1 (_id, result); }
  529. void getAxis2 (dVector3 result) const
  530. { dJointGetUniversalAxis2 (_id, result); }
  531. virtual void setParam (int parameter, dReal value)
  532. { dJointSetUniversalParam (_id, parameter, value); }
  533. virtual dReal getParam (int parameter) const
  534. { return dJointGetUniversalParam (_id, parameter); }
  535. // TODO: expose params through methods
  536. void getAngles(dReal *angle1, dReal *angle2) const
  537. { dJointGetUniversalAngles (_id, angle1, angle2); }
  538. dReal getAngle1() const
  539. { return dJointGetUniversalAngle1 (_id); }
  540. dReal getAngle1Rate() const
  541. { return dJointGetUniversalAngle1Rate (_id); }
  542. dReal getAngle2() const
  543. { return dJointGetUniversalAngle2 (_id); }
  544. dReal getAngle2Rate() const
  545. { return dJointGetUniversalAngle2Rate (_id); }
  546. void addTorques (dReal torque1, dReal torque2)
  547. { dJointAddUniversalTorques(_id, torque1, torque2); }
  548. };
  549. class dHinge2Joint : public dJoint {
  550. // intentionally undefined, don't use these
  551. dHinge2Joint (const dHinge2Joint &);
  552. void operator = (const dHinge2Joint &);
  553. public:
  554. dHinge2Joint() { }
  555. dHinge2Joint (dWorldID world, dJointGroupID group=0)
  556. { _id = dJointCreateHinge2 (world, group); }
  557. dHinge2Joint (dWorld& world, dJointGroupID group=0)
  558. { _id = dJointCreateHinge2 (world.id(), group); }
  559. void create (dWorldID world, dJointGroupID group=0) {
  560. if (_id) dJointDestroy (_id);
  561. _id = dJointCreateHinge2 (world, group);
  562. }
  563. void create (dWorld& world, dJointGroupID group=0)
  564. { create(world.id(), group); }
  565. void setAnchor (dReal x, dReal y, dReal z)
  566. { dJointSetHinge2Anchor (_id, x, y, z); }
  567. void setAnchor (const dVector3 a)
  568. { setAnchor(a[0], a[1], a[2]); }
  569. void setAxis1 (dReal x, dReal y, dReal z)
  570. { dJointSetHinge2Axis1 (_id, x, y, z); }
  571. void setAxis1 (const dVector3 a)
  572. { setAxis1 (a[0], a[1], a[2]); }
  573. void setAxis2 (dReal x, dReal y, dReal z)
  574. { dJointSetHinge2Axis2 (_id, x, y, z); }
  575. void setAxis2 (const dVector3 a)
  576. { setAxis2 (a[0], a[1], a[2]); }
  577. void getAnchor (dVector3 result) const
  578. { dJointGetHinge2Anchor (_id, result); }
  579. void getAnchor2 (dVector3 result) const
  580. { dJointGetHinge2Anchor2 (_id, result); }
  581. void getAxis1 (dVector3 result) const
  582. { dJointGetHinge2Axis1 (_id, result); }
  583. void getAxis2 (dVector3 result) const
  584. { dJointGetHinge2Axis2 (_id, result); }
  585. dReal getAngle1() const
  586. { return dJointGetHinge2Angle1 (_id); }
  587. dReal getAngle1Rate() const
  588. { return dJointGetHinge2Angle1Rate (_id); }
  589. dReal getAngle2Rate() const
  590. { return dJointGetHinge2Angle2Rate (_id); }
  591. virtual void setParam (int parameter, dReal value)
  592. { dJointSetHinge2Param (_id, parameter, value); }
  593. virtual dReal getParam (int parameter) const
  594. { return dJointGetHinge2Param (_id, parameter); }
  595. // TODO: expose params through methods
  596. void addTorques(dReal torque1, dReal torque2)
  597. { dJointAddHinge2Torques(_id, torque1, torque2); }
  598. };
  599. class dPRJoint : public dJoint {
  600. dPRJoint (const dPRJoint &);
  601. void operator = (const dPRJoint &);
  602. public:
  603. dPRJoint() { }
  604. dPRJoint (dWorldID world, dJointGroupID group=0)
  605. { _id = dJointCreatePR (world, group); }
  606. dPRJoint (dWorld& world, dJointGroupID group=0)
  607. { _id = dJointCreatePR (world.id(), group); }
  608. void create (dWorldID world, dJointGroupID group=0) {
  609. if (_id) dJointDestroy (_id);
  610. _id = dJointCreatePR (world, group);
  611. }
  612. void create (dWorld& world, dJointGroupID group=0)
  613. { create(world.id(), group); }
  614. void setAnchor (dReal x, dReal y, dReal z)
  615. { dJointSetPRAnchor (_id, x, y, z); }
  616. void setAnchor (const dVector3 a)
  617. { setAnchor (a[0], a[1], a[2]); }
  618. void setAxis1 (dReal x, dReal y, dReal z)
  619. { dJointSetPRAxis1 (_id, x, y, z); }
  620. void setAxis1 (const dVector3 a)
  621. { setAxis1(a[0], a[1], a[2]); }
  622. void setAxis2 (dReal x, dReal y, dReal z)
  623. { dJointSetPRAxis2 (_id, x, y, z); }
  624. void setAxis2 (const dVector3 a)
  625. { setAxis2(a[0], a[1], a[2]); }
  626. void getAnchor (dVector3 result) const
  627. { dJointGetPRAnchor (_id, result); }
  628. void getAxis1 (dVector3 result) const
  629. { dJointGetPRAxis1 (_id, result); }
  630. void getAxis2 (dVector3 result) const
  631. { dJointGetPRAxis2 (_id, result); }
  632. dReal getPosition() const
  633. { return dJointGetPRPosition (_id); }
  634. dReal getPositionRate() const
  635. { return dJointGetPRPositionRate (_id); }
  636. virtual void setParam (int parameter, dReal value)
  637. { dJointSetPRParam (_id, parameter, value); }
  638. virtual dReal getParam (int parameter) const
  639. { return dJointGetPRParam (_id, parameter); }
  640. };
  641. class dPUJoint : public dJoint
  642. {
  643. dPUJoint (const dPUJoint &);
  644. void operator = (const dPUJoint &);
  645. public:
  646. dPUJoint() { }
  647. dPUJoint (dWorldID world, dJointGroupID group=0)
  648. { _id = dJointCreatePU (world, group); }
  649. dPUJoint (dWorld& world, dJointGroupID group=0)
  650. { _id = dJointCreatePU (world.id(), group); }
  651. void create (dWorldID world, dJointGroupID group=0)
  652. {
  653. if (_id) dJointDestroy (_id);
  654. _id = dJointCreatePU (world, group);
  655. }
  656. void create (dWorld& world, dJointGroupID group=0)
  657. { create(world.id(), group); }
  658. void setAnchor (dReal x, dReal y, dReal z)
  659. { dJointSetPUAnchor (_id, x, y, z); }
  660. void setAnchor (const dVector3 a)
  661. { setAnchor (a[0], a[1], a[2]); }
  662. void setAxis1 (dReal x, dReal y, dReal z)
  663. { dJointSetPUAxis1 (_id, x, y, z); }
  664. void setAxis1 (const dVector3 a)
  665. { setAxis1(a[0], a[1], a[2]); }
  666. void setAxis2 (dReal x, dReal y, dReal z)
  667. { dJointSetPUAxis2 (_id, x, y, z); }
  668. void setAxis3 (dReal x, dReal y, dReal z)
  669. { dJointSetPUAxis3 (_id, x, y, z); }
  670. void setAxis3 (const dVector3 a)
  671. { setAxis3(a[0], a[1], a[2]); }
  672. void setAxisP (dReal x, dReal y, dReal z)
  673. { dJointSetPUAxis3 (_id, x, y, z); }
  674. void setAxisP (const dVector3 a)
  675. { setAxisP(a[0], a[1], a[2]); }
  676. virtual void getAnchor (dVector3 result) const
  677. { dJointGetPUAnchor (_id, result); }
  678. void getAxis1 (dVector3 result) const
  679. { dJointGetPUAxis1 (_id, result); }
  680. void getAxis2 (dVector3 result) const
  681. { dJointGetPUAxis2 (_id, result); }
  682. void getAxis3 (dVector3 result) const
  683. { dJointGetPUAxis3 (_id, result); }
  684. void getAxisP (dVector3 result) const
  685. { dJointGetPUAxis3 (_id, result); }
  686. dReal getAngle1() const
  687. { return dJointGetPUAngle1 (_id); }
  688. dReal getAngle1Rate() const
  689. { return dJointGetPUAngle1Rate (_id); }
  690. dReal getAngle2() const
  691. { return dJointGetPUAngle2 (_id); }
  692. dReal getAngle2Rate() const
  693. { return dJointGetPUAngle2Rate (_id); }
  694. dReal getPosition() const
  695. { return dJointGetPUPosition (_id); }
  696. dReal getPositionRate() const
  697. { return dJointGetPUPositionRate (_id); }
  698. virtual void setParam (int parameter, dReal value)
  699. { dJointSetPUParam (_id, parameter, value); }
  700. virtual dReal getParam (int parameter) const
  701. { return dJointGetPUParam (_id, parameter); }
  702. // TODO: expose params through methods
  703. };
  704. class dPistonJoint : public dJoint
  705. {
  706. // intentionally undefined, don't use these
  707. dPistonJoint (const dPistonJoint &);
  708. void operator = (const dPistonJoint &);
  709. public:
  710. dPistonJoint() { }
  711. dPistonJoint (dWorldID world, dJointGroupID group=0)
  712. { _id = dJointCreatePiston (world, group); }
  713. dPistonJoint (dWorld& world, dJointGroupID group=0)
  714. { _id = dJointCreatePiston (world, group); }
  715. void create (dWorldID world, dJointGroupID group=0)
  716. {
  717. if (_id) dJointDestroy (_id);
  718. _id = dJointCreatePiston (world, group);
  719. }
  720. void create (dWorld& world, dJointGroupID group=0)
  721. { create(world.id(), group); }
  722. void setAnchor (dReal x, dReal y, dReal z)
  723. { dJointSetPistonAnchor (_id, x, y, z); }
  724. void setAnchor (const dVector3 a)
  725. { setAnchor (a[0], a[1], a[2]); }
  726. void getAnchor (dVector3 result) const
  727. { dJointGetPistonAnchor (_id, result); }
  728. void getAnchor2 (dVector3 result) const
  729. { dJointGetPistonAnchor2 (_id, result); }
  730. void setAxis (dReal x, dReal y, dReal z)
  731. { dJointSetPistonAxis (_id, x, y, z); }
  732. void setAxis (const dVector3 a)
  733. { setAxis(a[0], a[1], a[2]); }
  734. void getAxis (dVector3 result) const
  735. { dJointGetPistonAxis (_id, result); }
  736. dReal getPosition() const
  737. { return dJointGetPistonPosition (_id); }
  738. dReal getPositionRate() const
  739. { return dJointGetPistonPositionRate (_id); }
  740. virtual void setParam (int parameter, dReal value)
  741. { dJointSetPistonParam (_id, parameter, value); }
  742. virtual dReal getParam (int parameter) const
  743. { return dJointGetPistonParam (_id, parameter); }
  744. // TODO: expose params through methods
  745. void addForce (dReal force)
  746. { dJointAddPistonForce (_id, force); }
  747. };
  748. class dFixedJoint : public dJoint
  749. {
  750. // intentionally undefined, don't use these
  751. dFixedJoint (const dFixedJoint &);
  752. void operator = (const dFixedJoint &);
  753. public:
  754. dFixedJoint() { }
  755. dFixedJoint (dWorldID world, dJointGroupID group=0)
  756. { _id = dJointCreateFixed (world, group); }
  757. dFixedJoint (dWorld& world, dJointGroupID group=0)
  758. { _id = dJointCreateFixed (world, group); }
  759. void create (dWorldID world, dJointGroupID group=0) {
  760. if (_id) dJointDestroy (_id);
  761. _id = dJointCreateFixed (world, group);
  762. }
  763. void create (dWorld& world, dJointGroup group=0)
  764. { create(world.id(), group); }
  765. void set()
  766. { dJointSetFixed (_id); }
  767. virtual void setParam (int parameter, dReal value)
  768. { dJointSetFixedParam (_id, parameter, value); }
  769. virtual dReal getParam (int parameter) const
  770. { return dJointGetFixedParam (_id, parameter); }
  771. // TODO: expose params through methods
  772. };
  773. class dContactJoint : public dJoint {
  774. // intentionally undefined, don't use these
  775. dContactJoint (const dContactJoint &);
  776. void operator = (const dContactJoint &);
  777. public:
  778. dContactJoint() { }
  779. dContactJoint (dWorldID world, dJointGroupID group, dContact *contact)
  780. { _id = dJointCreateContact (world, group, contact); }
  781. dContactJoint (dWorld& world, dJointGroupID group, dContact *contact)
  782. { _id = dJointCreateContact (world.id(), group, contact); }
  783. void create (dWorldID world, dJointGroupID group, dContact *contact) {
  784. if (_id) dJointDestroy (_id);
  785. _id = dJointCreateContact (world, group, contact);
  786. }
  787. void create (dWorld& world, dJointGroupID group, dContact *contact)
  788. { create(world.id(), group, contact); }
  789. };
  790. class dNullJoint : public dJoint {
  791. // intentionally undefined, don't use these
  792. dNullJoint (const dNullJoint &);
  793. void operator = (const dNullJoint &);
  794. public:
  795. dNullJoint() { }
  796. dNullJoint (dWorldID world, dJointGroupID group=0)
  797. { _id = dJointCreateNull (world, group); }
  798. dNullJoint (dWorld& world, dJointGroupID group=0)
  799. { _id = dJointCreateNull (world.id(), group); }
  800. void create (dWorldID world, dJointGroupID group=0) {
  801. if (_id) dJointDestroy (_id);
  802. _id = dJointCreateNull (world, group);
  803. }
  804. void create (dWorld& world, dJointGroupID group=0)
  805. { create(world.id(), group); }
  806. };
  807. class dAMotorJoint : public dJoint {
  808. // intentionally undefined, don't use these
  809. dAMotorJoint (const dAMotorJoint &);
  810. void operator = (const dAMotorJoint &);
  811. public:
  812. dAMotorJoint() { }
  813. dAMotorJoint (dWorldID world, dJointGroupID group=0)
  814. { _id = dJointCreateAMotor (world, group); }
  815. dAMotorJoint (dWorld& world, dJointGroupID group=0)
  816. { _id = dJointCreateAMotor (world.id(), group); }
  817. void create (dWorldID world, dJointGroupID group=0) {
  818. if (_id) dJointDestroy (_id);
  819. _id = dJointCreateAMotor (world, group);
  820. }
  821. void create (dWorld& world, dJointGroupID group=0)
  822. { create(world.id(), group); }
  823. void setMode (int mode)
  824. { dJointSetAMotorMode (_id, mode); }
  825. int getMode() const
  826. { return dJointGetAMotorMode (_id); }
  827. void setNumAxes (int num)
  828. { dJointSetAMotorNumAxes (_id, num); }
  829. int getNumAxes() const
  830. { return dJointGetAMotorNumAxes (_id); }
  831. void setAxis (int anum, int rel, dReal x, dReal y, dReal z)
  832. { dJointSetAMotorAxis (_id, anum, rel, x, y, z); }
  833. void setAxis (int anum, int rel, const dVector3 a)
  834. { setAxis(anum, rel, a[0], a[1], a[2]); }
  835. void getAxis (int anum, dVector3 result) const
  836. { dJointGetAMotorAxis (_id, anum, result); }
  837. int getAxisRel (int anum) const
  838. { return dJointGetAMotorAxisRel (_id, anum); }
  839. void setAngle (int anum, dReal angle)
  840. { dJointSetAMotorAngle (_id, anum, angle); }
  841. dReal getAngle (int anum) const
  842. { return dJointGetAMotorAngle (_id, anum); }
  843. dReal getAngleRate (int anum)
  844. { return dJointGetAMotorAngleRate (_id,anum); }
  845. void setParam (int parameter, dReal value)
  846. { dJointSetAMotorParam (_id, parameter, value); }
  847. dReal getParam (int parameter) const
  848. { return dJointGetAMotorParam (_id, parameter); }
  849. // TODO: expose params through methods
  850. void addTorques(dReal torque1, dReal torque2, dReal torque3)
  851. { dJointAddAMotorTorques(_id, torque1, torque2, torque3); }
  852. };
  853. class dLMotorJoint : public dJoint {
  854. // intentionally undefined, don't use these
  855. dLMotorJoint (const dLMotorJoint &);
  856. void operator = (const dLMotorJoint &);
  857. public:
  858. dLMotorJoint() { }
  859. dLMotorJoint (dWorldID world, dJointGroupID group=0)
  860. { _id = dJointCreateLMotor (world, group); }
  861. dLMotorJoint (dWorld& world, dJointGroupID group=0)
  862. { _id = dJointCreateLMotor (world.id(), group); }
  863. void create (dWorldID world, dJointGroupID group=0) {
  864. if (_id) dJointDestroy (_id);
  865. _id = dJointCreateLMotor (world, group);
  866. }
  867. void create (dWorld& world, dJointGroupID group=0)
  868. { create(world.id(), group); }
  869. void setNumAxes (int num)
  870. { dJointSetLMotorNumAxes (_id, num); }
  871. int getNumAxes() const
  872. { return dJointGetLMotorNumAxes (_id); }
  873. void setAxis (int anum, int rel, dReal x, dReal y, dReal z)
  874. { dJointSetLMotorAxis (_id, anum, rel, x, y, z); }
  875. void setAxis (int anum, int rel, const dVector3 a)
  876. { setAxis(anum, rel, a[0], a[1], a[2]); }
  877. void getAxis (int anum, dVector3 result) const
  878. { dJointGetLMotorAxis (_id, anum, result); }
  879. void setParam (int parameter, dReal value)
  880. { dJointSetLMotorParam (_id, parameter, value); }
  881. dReal getParam (int parameter) const
  882. { return dJointGetLMotorParam (_id, parameter); }
  883. // TODO: expose params through methods
  884. };
  885. //}
  886. #endif
  887. #endif
  888. // Local variables:
  889. // mode:c++
  890. // c-basic-offset:2
  891. // End: