PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/thirdPartyCode/ode-0.13/include/ode/odecpp_collision.h

https://bitbucket.org/rutad/libs
C Header | 429 lines | 304 code | 85 blank | 40 comment | 9 complexity | 2f993b4c635dcf6c713ced7813822334 MD5 | raw file
Possible License(s): BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-3.0
  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. /* 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 getRelPointPos (dReal px, dReal py, dReal pz, dVector3 result) const
  90. { dGeomGetRelPointPos (_id, px, py, pz, result); }
  91. void getRelPointPos (const dVector3 p, dVector3 result) const
  92. { getRelPointPos (p[0], p[1], p[2], result); }
  93. void getPosRelPoint (dReal px, dReal py, dReal pz, dVector3 result) const
  94. { dGeomGetPosRelPoint (_id, px, py, pz, result); }
  95. void getPosRelPoint (const dVector3 p, dVector3 result) const
  96. { getPosRelPoint (p[0], p[1], p[2], result); }
  97. void vectorToWorld (dReal px, dReal py, dReal pz, dVector3 result) const
  98. { dGeomVectorToWorld (_id, px, py, pz, result); }
  99. void vectorToWorld (const dVector3 p, dVector3 result) const
  100. { vectorToWorld (p[0], p[1], p[2], result); }
  101. void vectorFromWorld (dReal px, dReal py, dReal pz, dVector3 result) const
  102. { dGeomVectorFromWorld (_id, px, py, pz, result); }
  103. void vectorFromWorld (const dVector3 p, dVector3 result) const
  104. { vectorFromWorld (p[0], p[1], p[2], result); }
  105. void collide2 (dGeomID g, void *data, dNearCallback *callback)
  106. { dSpaceCollide2 (_id,g,data,callback); }
  107. };
  108. class dSpace : public dGeom {
  109. // intentionally undefined, don't use these
  110. dSpace (dSpace &);
  111. void operator= (dSpace &);
  112. protected:
  113. // the default constructor is protected so that you
  114. // can't instance this class. you must instance one
  115. // of its subclasses instead.
  116. dSpace () { _id = 0; }
  117. public:
  118. dSpaceID id() const
  119. { return (dSpaceID) _id; }
  120. operator dSpaceID() const
  121. { return (dSpaceID) _id; }
  122. void setCleanup (int mode)
  123. { dSpaceSetCleanup (id(), mode); }
  124. int getCleanup()
  125. { return dSpaceGetCleanup (id()); }
  126. void add (dGeomID x)
  127. { dSpaceAdd (id(), x); }
  128. void remove (dGeomID x)
  129. { dSpaceRemove (id(), x); }
  130. int query (dGeomID x)
  131. { return dSpaceQuery (id(),x); }
  132. int getNumGeoms()
  133. { return dSpaceGetNumGeoms (id()); }
  134. dGeomID getGeom (int i)
  135. { return dSpaceGetGeom (id(),i); }
  136. void collide (void *data, dNearCallback *callback)
  137. { dSpaceCollide (id(),data,callback); }
  138. };
  139. class dSimpleSpace : public dSpace {
  140. // intentionally undefined, don't use these
  141. dSimpleSpace (dSimpleSpace &);
  142. void operator= (dSimpleSpace &);
  143. public:
  144. dSimpleSpace ()
  145. { _id = (dGeomID) dSimpleSpaceCreate (0); }
  146. dSimpleSpace (dSpace &space)
  147. { _id = (dGeomID) dSimpleSpaceCreate (space.id()); }
  148. dSimpleSpace (dSpaceID space)
  149. { _id = (dGeomID) dSimpleSpaceCreate (space); }
  150. };
  151. class dHashSpace : public dSpace {
  152. // intentionally undefined, don't use these
  153. dHashSpace (dHashSpace &);
  154. void operator= (dHashSpace &);
  155. public:
  156. dHashSpace ()
  157. { _id = (dGeomID) dHashSpaceCreate (0); }
  158. dHashSpace (dSpace &space)
  159. { _id = (dGeomID) dHashSpaceCreate (space.id()); }
  160. dHashSpace (dSpaceID space)
  161. { _id = (dGeomID) dHashSpaceCreate (space); }
  162. void setLevels (int minlevel, int maxlevel)
  163. { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
  164. };
  165. class dQuadTreeSpace : public dSpace {
  166. // intentionally undefined, don't use these
  167. dQuadTreeSpace (dQuadTreeSpace &);
  168. void operator= (dQuadTreeSpace &);
  169. public:
  170. dQuadTreeSpace (const dVector3 center, const dVector3 extents, int depth)
  171. { _id = (dGeomID) dQuadTreeSpaceCreate (0,center,extents,depth); }
  172. dQuadTreeSpace (dSpace &space, const dVector3 center, const dVector3 extents, int depth)
  173. { _id = (dGeomID) dQuadTreeSpaceCreate (space.id(),center,extents,depth); }
  174. dQuadTreeSpace (dSpaceID space, const dVector3 center, const dVector3 extents, int depth)
  175. { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
  176. };
  177. class dSphere : public dGeom {
  178. // intentionally undefined, don't use these
  179. dSphere (dSphere &);
  180. void operator= (dSphere &);
  181. public:
  182. dSphere () { }
  183. dSphere (dReal radius)
  184. { _id = dCreateSphere (0, radius); }
  185. dSphere (dSpace &space, dReal radius)
  186. { _id = dCreateSphere (space.id(), radius); }
  187. dSphere (dSpaceID space, dReal radius)
  188. { _id = dCreateSphere (space, radius); }
  189. void create (dSpaceID space, dReal radius) {
  190. if (_id) dGeomDestroy (_id);
  191. _id = dCreateSphere (space, radius);
  192. }
  193. void setRadius (dReal radius)
  194. { dGeomSphereSetRadius (_id, radius); }
  195. dReal getRadius() const
  196. { return dGeomSphereGetRadius (_id); }
  197. };
  198. class dBox : public dGeom {
  199. // intentionally undefined, don't use these
  200. dBox (dBox &);
  201. void operator= (dBox &);
  202. public:
  203. dBox () { }
  204. dBox (dReal lx, dReal ly, dReal lz)
  205. { _id = dCreateBox (0,lx,ly,lz); }
  206. dBox (dSpace &space, dReal lx, dReal ly, dReal lz)
  207. { _id = dCreateBox (space,lx,ly,lz); }
  208. dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
  209. { _id = dCreateBox (space,lx,ly,lz); }
  210. void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
  211. if (_id) dGeomDestroy (_id);
  212. _id = dCreateBox (space,lx,ly,lz);
  213. }
  214. void setLengths (dReal lx, dReal ly, dReal lz)
  215. { dGeomBoxSetLengths (_id, lx, ly, lz); }
  216. void getLengths (dVector3 result) const
  217. { dGeomBoxGetLengths (_id,result); }
  218. };
  219. class dPlane : public dGeom {
  220. // intentionally undefined, don't use these
  221. dPlane (dPlane &);
  222. void operator= (dPlane &);
  223. public:
  224. dPlane() { }
  225. dPlane (dReal a, dReal b, dReal c, dReal d)
  226. { _id = dCreatePlane (0,a,b,c,d); }
  227. dPlane (dSpace &space, dReal a, dReal b, dReal c, dReal d)
  228. { _id = dCreatePlane (space.id(),a,b,c,d); }
  229. dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
  230. { _id = dCreatePlane (space,a,b,c,d); }
  231. void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
  232. if (_id) dGeomDestroy (_id);
  233. _id = dCreatePlane (space,a,b,c,d);
  234. }
  235. void setParams (dReal a, dReal b, dReal c, dReal d)
  236. { dGeomPlaneSetParams (_id, a, b, c, d); }
  237. void getParams (dVector4 result) const
  238. { dGeomPlaneGetParams (_id,result); }
  239. };
  240. class dCapsule : public dGeom {
  241. // intentionally undefined, don't use these
  242. dCapsule (dCapsule &);
  243. void operator= (dCapsule &);
  244. public:
  245. dCapsule() { }
  246. dCapsule (dReal radius, dReal length)
  247. { _id = dCreateCapsule (0,radius,length); }
  248. dCapsule (dSpace &space, dReal radius, dReal length)
  249. { _id = dCreateCapsule (space.id(),radius,length); }
  250. dCapsule (dSpaceID space, dReal radius, dReal length)
  251. { _id = dCreateCapsule (space,radius,length); }
  252. void create (dSpaceID space, dReal radius, dReal length) {
  253. if (_id) dGeomDestroy (_id);
  254. _id = dCreateCapsule (space,radius,length);
  255. }
  256. void setParams (dReal radius, dReal length)
  257. { dGeomCapsuleSetParams (_id, radius, length); }
  258. void getParams (dReal *radius, dReal *length) const
  259. { dGeomCapsuleGetParams (_id,radius,length); }
  260. };
  261. class dCylinder : public dGeom {
  262. // intentionally undefined, don't use these
  263. dCylinder (dCylinder &);
  264. void operator= (dCylinder &);
  265. public:
  266. dCylinder() { }
  267. dCylinder (dReal radius, dReal length)
  268. { _id = dCreateCylinder (0,radius,length); }
  269. dCylinder (dSpace &space, dReal radius, dReal length)
  270. { _id = dCreateCylinder (space.id(),radius,length); }
  271. dCylinder (dSpaceID space, dReal radius, dReal length)
  272. { _id = dCreateCylinder (space,radius,length); }
  273. void create (dSpaceID space, dReal radius, dReal length) {
  274. if (_id) dGeomDestroy (_id);
  275. _id = dCreateCylinder (space,radius,length);
  276. }
  277. void setParams (dReal radius, dReal length)
  278. { dGeomCylinderSetParams (_id, radius, length); }
  279. void getParams (dReal *radius, dReal *length) const
  280. { dGeomCylinderGetParams (_id,radius,length); }
  281. };
  282. class dRay : public dGeom {
  283. // intentionally undefined, don't use these
  284. dRay (dRay &);
  285. void operator= (dRay &);
  286. public:
  287. dRay() { }
  288. dRay (dReal length)
  289. { _id = dCreateRay (0,length); }
  290. dRay (dSpace &space, dReal length)
  291. { _id = dCreateRay (space.id(),length); }
  292. dRay (dSpaceID space, dReal length)
  293. { _id = dCreateRay (space,length); }
  294. void create (dSpaceID space, dReal length) {
  295. if (_id) dGeomDestroy (_id);
  296. _id = dCreateRay (space,length);
  297. }
  298. void setLength (dReal length)
  299. { dGeomRaySetLength (_id, length); }
  300. dReal getLength()
  301. { return dGeomRayGetLength (_id); }
  302. void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
  303. { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
  304. void get (dVector3 start, dVector3 dir)
  305. { dGeomRayGet (_id, start, dir); }
  306. void setParams (int firstContact, int backfaceCull)
  307. { dGeomRaySetParams (_id, firstContact, backfaceCull); }
  308. void getParams (int *firstContact, int *backfaceCull)
  309. { dGeomRayGetParams (_id, firstContact, backfaceCull); }
  310. void setClosestHit (int closestHit)
  311. { dGeomRaySetClosestHit (_id, closestHit); }
  312. int getClosestHit()
  313. { return dGeomRayGetClosestHit (_id); }
  314. };
  315. class dGeomTransform : public dGeom {
  316. // intentionally undefined, don't use these
  317. dGeomTransform (dGeomTransform &);
  318. void operator= (dGeomTransform &);
  319. public:
  320. dGeomTransform() { }
  321. dGeomTransform (dSpace &space)
  322. { _id = dCreateGeomTransform (space.id()); }
  323. dGeomTransform (dSpaceID space)
  324. { _id = dCreateGeomTransform (space); }
  325. void create (dSpaceID space=0) {
  326. if (_id) dGeomDestroy (_id);
  327. _id = dCreateGeomTransform (space);
  328. }
  329. void setGeom (dGeomID geom)
  330. { dGeomTransformSetGeom (_id, geom); }
  331. dGeomID getGeom() const
  332. { return dGeomTransformGetGeom (_id); }
  333. void setCleanup (int mode)
  334. { dGeomTransformSetCleanup (_id,mode); }
  335. int getCleanup ()
  336. { return dGeomTransformGetCleanup (_id); }
  337. void setInfo (int mode)
  338. { dGeomTransformSetInfo (_id,mode); }
  339. int getInfo()
  340. { return dGeomTransformGetInfo (_id); }
  341. };
  342. //}
  343. #endif
  344. #endif