odecpp_collision.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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 new collision API */
  23. #ifndef _ODE_ODECPP_COLLISION_H_
  24. #define _ODE_ODECPP_COLLISION_H_
  25. #ifdef __cplusplus
  26. //#include <ode/error.h>
  27. //namespace ode {
  28. class dGeom {
  29. // intentionally undefined, don't use these
  30. dGeom (dGeom &);
  31. void operator= (dGeom &);
  32. protected:
  33. dGeomID _id;
  34. dGeom()
  35. { _id = 0; }
  36. public:
  37. ~dGeom()
  38. { if (_id) dGeomDestroy (_id); }
  39. dGeomID id() const
  40. { return _id; }
  41. operator dGeomID() const
  42. { return _id; }
  43. void destroy() {
  44. if (_id) dGeomDestroy (_id);
  45. _id = 0;
  46. }
  47. int getClass() const
  48. { return dGeomGetClass (_id); }
  49. dSpaceID getSpace() const
  50. { return dGeomGetSpace (_id); }
  51. void setData (void *data)
  52. { dGeomSetData (_id,data); }
  53. void *getData() const
  54. { return dGeomGetData (_id); }
  55. void setBody (dBodyID b)
  56. { dGeomSetBody (_id,b); }
  57. dBodyID getBody() const
  58. { return dGeomGetBody (_id); }
  59. void setPosition (dReal x, dReal y, dReal z)
  60. { dGeomSetPosition (_id,x,y,z); }
  61. const dReal * getPosition() const
  62. { return dGeomGetPosition (_id); }
  63. void setRotation (const dMatrix3 R)
  64. { dGeomSetRotation (_id,R); }
  65. const dReal * getRotation() const
  66. { return dGeomGetRotation (_id); }
  67. void setQuaternion (const dQuaternion quat)
  68. { dGeomSetQuaternion (_id,quat); }
  69. void getQuaternion (dQuaternion quat) const
  70. { dGeomGetQuaternion (_id,quat); }
  71. void getAABB (dReal aabb[6]) const
  72. { dGeomGetAABB (_id, aabb); }
  73. int isSpace()
  74. { return dGeomIsSpace (_id); }
  75. void setCategoryBits (unsigned long bits)
  76. { dGeomSetCategoryBits (_id, bits); }
  77. void setCollideBits (unsigned long bits)
  78. { dGeomSetCollideBits (_id, bits); }
  79. unsigned long getCategoryBits()
  80. { return dGeomGetCategoryBits (_id); }
  81. unsigned long getCollideBits()
  82. { return dGeomGetCollideBits (_id); }
  83. void enable()
  84. { dGeomEnable (_id); }
  85. void disable()
  86. { dGeomDisable (_id); }
  87. int isEnabled()
  88. { return dGeomIsEnabled (_id); }
  89. void collide2 (dGeomID g, void *data, dNearCallback *callback)
  90. { dSpaceCollide2 (_id,g,data,callback); }
  91. };
  92. class dSpace : public dGeom {
  93. // intentionally undefined, don't use these
  94. dSpace (dSpace &);
  95. void operator= (dSpace &);
  96. protected:
  97. // the default constructor is protected so that you
  98. // can't instance this class. you must instance one
  99. // of its subclasses instead.
  100. dSpace () { _id = 0; }
  101. public:
  102. dSpaceID id() const
  103. { return (dSpaceID) _id; }
  104. operator dSpaceID() const
  105. { return (dSpaceID) _id; }
  106. void setCleanup (int mode)
  107. { dSpaceSetCleanup (id(), mode); }
  108. int getCleanup()
  109. { return dSpaceGetCleanup (id()); }
  110. void add (dGeomID x)
  111. { dSpaceAdd (id(), x); }
  112. void remove (dGeomID x)
  113. { dSpaceRemove (id(), x); }
  114. int query (dGeomID x)
  115. { return dSpaceQuery (id(),x); }
  116. int getNumGeoms()
  117. { return dSpaceGetNumGeoms (id()); }
  118. dGeomID getGeom (int i)
  119. { return dSpaceGetGeom (id(),i); }
  120. void collide (void *data, dNearCallback *callback)
  121. { dSpaceCollide (id(),data,callback); }
  122. };
  123. class dSimpleSpace : public dSpace {
  124. // intentionally undefined, don't use these
  125. dSimpleSpace (dSimpleSpace &);
  126. void operator= (dSimpleSpace &);
  127. public:
  128. dSimpleSpace ()
  129. { _id = (dGeomID) dSimpleSpaceCreate (0); }
  130. dSimpleSpace (dSpace &space)
  131. { _id = (dGeomID) dSimpleSpaceCreate (space.id()); }
  132. dSimpleSpace (dSpaceID space)
  133. { _id = (dGeomID) dSimpleSpaceCreate (space); }
  134. };
  135. class dHashSpace : public dSpace {
  136. // intentionally undefined, don't use these
  137. dHashSpace (dHashSpace &);
  138. void operator= (dHashSpace &);
  139. public:
  140. dHashSpace ()
  141. { _id = (dGeomID) dHashSpaceCreate (0); }
  142. dHashSpace (dSpace &space)
  143. { _id = (dGeomID) dHashSpaceCreate (space.id()); }
  144. dHashSpace (dSpaceID space)
  145. { _id = (dGeomID) dHashSpaceCreate (space); }
  146. void setLevels (int minlevel, int maxlevel)
  147. { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
  148. };
  149. class dQuadTreeSpace : public dSpace {
  150. // intentionally undefined, don't use these
  151. dQuadTreeSpace (dQuadTreeSpace &);
  152. void operator= (dQuadTreeSpace &);
  153. public:
  154. dQuadTreeSpace (const dVector3 center, const dVector3 extents, int depth)
  155. { _id = (dGeomID) dQuadTreeSpaceCreate (0,center,extents,depth); }
  156. dQuadTreeSpace (dSpace &space, const dVector3 center, const dVector3 extents, int depth)
  157. { _id = (dGeomID) dQuadTreeSpaceCreate (space.id(),center,extents,depth); }
  158. dQuadTreeSpace (dSpaceID space, const dVector3 center, const dVector3 extents, int depth)
  159. { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
  160. };
  161. class dSphere : public dGeom {
  162. // intentionally undefined, don't use these
  163. dSphere (dSphere &);
  164. void operator= (dSphere &);
  165. public:
  166. dSphere () { }
  167. dSphere (dReal radius)
  168. { _id = dCreateSphere (0, radius); }
  169. dSphere (dSpace &space, dReal radius)
  170. { _id = dCreateSphere (space.id(), radius); }
  171. dSphere (dSpaceID space, dReal radius)
  172. { _id = dCreateSphere (space, radius); }
  173. void create (dSpaceID space, dReal radius) {
  174. if (_id) dGeomDestroy (_id);
  175. _id = dCreateSphere (space, radius);
  176. }
  177. void setRadius (dReal radius)
  178. { dGeomSphereSetRadius (_id, radius); }
  179. dReal getRadius() const
  180. { return dGeomSphereGetRadius (_id); }
  181. };
  182. class dBox : public dGeom {
  183. // intentionally undefined, don't use these
  184. dBox (dBox &);
  185. void operator= (dBox &);
  186. public:
  187. dBox () { }
  188. dBox (dReal lx, dReal ly, dReal lz)
  189. { _id = dCreateBox (0,lx,ly,lz); }
  190. dBox (dSpace &space, dReal lx, dReal ly, dReal lz)
  191. { _id = dCreateBox (space,lx,ly,lz); }
  192. dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
  193. { _id = dCreateBox (space,lx,ly,lz); }
  194. void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
  195. if (_id) dGeomDestroy (_id);
  196. _id = dCreateBox (space,lx,ly,lz);
  197. }
  198. void setLengths (dReal lx, dReal ly, dReal lz)
  199. { dGeomBoxSetLengths (_id, lx, ly, lz); }
  200. void getLengths (dVector3 result) const
  201. { dGeomBoxGetLengths (_id,result); }
  202. };
  203. class dPlane : public dGeom {
  204. // intentionally undefined, don't use these
  205. dPlane (dPlane &);
  206. void operator= (dPlane &);
  207. public:
  208. dPlane() { }
  209. dPlane (dReal a, dReal b, dReal c, dReal d)
  210. { _id = dCreatePlane (0,a,b,c,d); }
  211. dPlane (dSpace &space, dReal a, dReal b, dReal c, dReal d)
  212. { _id = dCreatePlane (space.id(),a,b,c,d); }
  213. dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
  214. { _id = dCreatePlane (space,a,b,c,d); }
  215. void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
  216. if (_id) dGeomDestroy (_id);
  217. _id = dCreatePlane (space,a,b,c,d);
  218. }
  219. void setParams (dReal a, dReal b, dReal c, dReal d)
  220. { dGeomPlaneSetParams (_id, a, b, c, d); }
  221. void getParams (dVector4 result) const
  222. { dGeomPlaneGetParams (_id,result); }
  223. };
  224. class dCapsule : public dGeom {
  225. // intentionally undefined, don't use these
  226. dCapsule (dCapsule &);
  227. void operator= (dCapsule &);
  228. public:
  229. dCapsule() { }
  230. dCapsule (dReal radius, dReal length)
  231. { _id = dCreateCapsule (0,radius,length); }
  232. dCapsule (dSpace &space, dReal radius, dReal length)
  233. { _id = dCreateCapsule (space.id(),radius,length); }
  234. dCapsule (dSpaceID space, dReal radius, dReal length)
  235. { _id = dCreateCapsule (space,radius,length); }
  236. void create (dSpaceID space, dReal radius, dReal length) {
  237. if (_id) dGeomDestroy (_id);
  238. _id = dCreateCapsule (space,radius,length);
  239. }
  240. void setParams (dReal radius, dReal length)
  241. { dGeomCapsuleSetParams (_id, radius, length); }
  242. void getParams (dReal *radius, dReal *length) const
  243. { dGeomCapsuleGetParams (_id,radius,length); }
  244. };
  245. class dCylinder : public dGeom {
  246. // intentionally undefined, don't use these
  247. dCylinder (dCylinder &);
  248. void operator= (dCylinder &);
  249. public:
  250. dCylinder() { }
  251. dCylinder (dReal radius, dReal length)
  252. { _id = dCreateCylinder (0,radius,length); }
  253. dCylinder (dSpace &space, dReal radius, dReal length)
  254. { _id = dCreateCylinder (space.id(),radius,length); }
  255. dCylinder (dSpaceID space, dReal radius, dReal length)
  256. { _id = dCreateCylinder (space,radius,length); }
  257. void create (dSpaceID space, dReal radius, dReal length) {
  258. if (_id) dGeomDestroy (_id);
  259. _id = dCreateCylinder (space,radius,length);
  260. }
  261. void setParams (dReal radius, dReal length)
  262. { dGeomCylinderSetParams (_id, radius, length); }
  263. void getParams (dReal *radius, dReal *length) const
  264. { dGeomCylinderGetParams (_id,radius,length); }
  265. };
  266. class dRay : public dGeom {
  267. // intentionally undefined, don't use these
  268. dRay (dRay &);
  269. void operator= (dRay &);
  270. public:
  271. dRay() { }
  272. dRay (dReal length)
  273. { _id = dCreateRay (0,length); }
  274. dRay (dSpace &space, dReal length)
  275. { _id = dCreateRay (space.id(),length); }
  276. dRay (dSpaceID space, dReal length)
  277. { _id = dCreateRay (space,length); }
  278. void create (dSpaceID space, dReal length) {
  279. if (_id) dGeomDestroy (_id);
  280. _id = dCreateRay (space,length);
  281. }
  282. void setLength (dReal length)
  283. { dGeomRaySetLength (_id, length); }
  284. dReal getLength()
  285. { return dGeomRayGetLength (_id); }
  286. void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
  287. { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
  288. void get (dVector3 start, dVector3 dir)
  289. { dGeomRayGet (_id, start, dir); }
  290. void setParams (int firstContact, int backfaceCull)
  291. { dGeomRaySetParams (_id, firstContact, backfaceCull); }
  292. void getParams (int *firstContact, int *backfaceCull)
  293. { dGeomRayGetParams (_id, firstContact, backfaceCull); }
  294. void setClosestHit (int closestHit)
  295. { dGeomRaySetClosestHit (_id, closestHit); }
  296. int getClosestHit()
  297. { return dGeomRayGetClosestHit (_id); }
  298. };
  299. class dGeomTransform : public dGeom {
  300. // intentionally undefined, don't use these
  301. dGeomTransform (dGeomTransform &);
  302. void operator= (dGeomTransform &);
  303. public:
  304. dGeomTransform() { }
  305. dGeomTransform (dSpace &space)
  306. { _id = dCreateGeomTransform (space.id()); }
  307. dGeomTransform (dSpaceID space)
  308. { _id = dCreateGeomTransform (space); }
  309. void create (dSpaceID space=0) {
  310. if (_id) dGeomDestroy (_id);
  311. _id = dCreateGeomTransform (space);
  312. }
  313. void setGeom (dGeomID geom)
  314. { dGeomTransformSetGeom (_id, geom); }
  315. dGeomID getGeom() const
  316. { return dGeomTransformGetGeom (_id); }
  317. void setCleanup (int mode)
  318. { dGeomTransformSetCleanup (_id,mode); }
  319. int getCleanup ()
  320. { return dGeomTransformGetCleanup (_id); }
  321. void setInfo (int mode)
  322. { dGeomTransformSetInfo (_id,mode); }
  323. int getInfo()
  324. { return dGeomTransformGetInfo (_id); }
  325. };
  326. //}
  327. #endif
  328. #endif