ODE  0.13.1
 All Data Structures Functions Variables Typedefs Enumerations Groups
odecpp_collision.h
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 new collision API */
24 
25 
26 #ifndef _ODE_ODECPP_COLLISION_H_
27 #define _ODE_ODECPP_COLLISION_H_
28 #ifdef __cplusplus
29 
30 //#include <ode/error.h>
31 
32 //namespace ode {
33 
34 class dGeom {
35  // intentionally undefined, don't use these
36  dGeom (dGeom &);
37  void operator= (dGeom &);
38 
39 protected:
40  dGeomID _id;
41 
42  dGeom()
43  { _id = 0; }
44 public:
45  ~dGeom()
46  { if (_id) dGeomDestroy (_id); }
47 
48  dGeomID id() const
49  { return _id; }
50  operator dGeomID() const
51  { return _id; }
52 
53  void destroy() {
54  if (_id) dGeomDestroy (_id);
55  _id = 0;
56  }
57 
58  int getClass() const
59  { return dGeomGetClass (_id); }
60 
61  dSpaceID getSpace() const
62  { return dGeomGetSpace (_id); }
63 
64  void setData (void *data)
65  { dGeomSetData (_id,data); }
66  void *getData() const
67  { return dGeomGetData (_id); }
68 
69  void setBody (dBodyID b)
70  { dGeomSetBody (_id,b); }
71  dBodyID getBody() const
72  { return dGeomGetBody (_id); }
73 
74  void setPosition (dReal x, dReal y, dReal z)
75  { dGeomSetPosition (_id,x,y,z); }
76  const dReal * getPosition() const
77  { return dGeomGetPosition (_id); }
78 
79  void setRotation (const dMatrix3 R)
80  { dGeomSetRotation (_id,R); }
81  const dReal * getRotation() const
82  { return dGeomGetRotation (_id); }
83 
84  void setQuaternion (const dQuaternion quat)
85  { dGeomSetQuaternion (_id,quat); }
86  void getQuaternion (dQuaternion quat) const
87  { dGeomGetQuaternion (_id,quat); }
88 
89  void getAABB (dReal aabb[6]) const
90  { dGeomGetAABB (_id, aabb); }
91 
92  int isSpace()
93  { return dGeomIsSpace (_id); }
94 
95  void setCategoryBits (unsigned long bits)
96  { dGeomSetCategoryBits (_id, bits); }
97  void setCollideBits (unsigned long bits)
98  { dGeomSetCollideBits (_id, bits); }
99  unsigned long getCategoryBits()
100  { return dGeomGetCategoryBits (_id); }
101  unsigned long getCollideBits()
102  { return dGeomGetCollideBits (_id); }
103 
104  void enable()
105  { dGeomEnable (_id); }
106  void disable()
107  { dGeomDisable (_id); }
108  int isEnabled()
109  { return dGeomIsEnabled (_id); }
110 
111  void getRelPointPos (dReal px, dReal py, dReal pz, dVector3 result) const
112  { dGeomGetRelPointPos (_id, px, py, pz, result); }
113  void getRelPointPos (const dVector3 p, dVector3 result) const
114  { getRelPointPos (p[0], p[1], p[2], result); }
115 
116  void getPosRelPoint (dReal px, dReal py, dReal pz, dVector3 result) const
117  { dGeomGetPosRelPoint (_id, px, py, pz, result); }
118  void getPosRelPoint (const dVector3 p, dVector3 result) const
119  { getPosRelPoint (p[0], p[1], p[2], result); }
120 
121  void vectorToWorld (dReal px, dReal py, dReal pz, dVector3 result) const
122  { dGeomVectorToWorld (_id, px, py, pz, result); }
123  void vectorToWorld (const dVector3 p, dVector3 result) const
124  { vectorToWorld (p[0], p[1], p[2], result); }
125 
126  void vectorFromWorld (dReal px, dReal py, dReal pz, dVector3 result) const
127  { dGeomVectorFromWorld (_id, px, py, pz, result); }
128  void vectorFromWorld (const dVector3 p, dVector3 result) const
129  { vectorFromWorld (p[0], p[1], p[2], result); }
130 
131  void collide2 (dGeomID g, void *data, dNearCallback *callback)
132  { dSpaceCollide2 (_id,g,data,callback); }
133 };
134 
135 
136 class dSpace : public dGeom {
137  // intentionally undefined, don't use these
138  dSpace (dSpace &);
139  void operator= (dSpace &);
140 
141 protected:
142  // the default constructor is protected so that you
143  // can't instance this class. you must instance one
144  // of its subclasses instead.
145  dSpace () { _id = 0; }
146 
147 public:
148  dSpaceID id() const
149  { return (dSpaceID) _id; }
150  operator dSpaceID() const
151  { return (dSpaceID) _id; }
152 
153  void setCleanup (int mode)
154  { dSpaceSetCleanup (id(), mode); }
155  int getCleanup()
156  { return dSpaceGetCleanup (id()); }
157 
158  void add (dGeomID x)
159  { dSpaceAdd (id(), x); }
160  void remove (dGeomID x)
161  { dSpaceRemove (id(), x); }
162  int query (dGeomID x)
163  { return dSpaceQuery (id(),x); }
164 
165  int getNumGeoms()
166  { return dSpaceGetNumGeoms (id()); }
167  dGeomID getGeom (int i)
168  { return dSpaceGetGeom (id(),i); }
169 
170  void collide (void *data, dNearCallback *callback)
171  { dSpaceCollide (id(),data,callback); }
172 };
173 
174 
175 class dSimpleSpace : public dSpace {
176  // intentionally undefined, don't use these
177  dSimpleSpace (dSimpleSpace &);
178  void operator= (dSimpleSpace &);
179 
180 public:
181  dSimpleSpace ()
182  { _id = (dGeomID) dSimpleSpaceCreate (0); }
183  dSimpleSpace (dSpace &space)
184  { _id = (dGeomID) dSimpleSpaceCreate (space.id()); }
185  dSimpleSpace (dSpaceID space)
186  { _id = (dGeomID) dSimpleSpaceCreate (space); }
187 };
188 
189 
190 class dHashSpace : public dSpace {
191  // intentionally undefined, don't use these
192  dHashSpace (dHashSpace &);
193  void operator= (dHashSpace &);
194 
195 public:
196  dHashSpace ()
197  { _id = (dGeomID) dHashSpaceCreate (0); }
198  dHashSpace (dSpace &space)
199  { _id = (dGeomID) dHashSpaceCreate (space.id()); }
200  dHashSpace (dSpaceID space)
201  { _id = (dGeomID) dHashSpaceCreate (space); }
202 
203  void setLevels (int minlevel, int maxlevel)
204  { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
205 };
206 
207 
208 class dQuadTreeSpace : public dSpace {
209  // intentionally undefined, don't use these
210  dQuadTreeSpace (dQuadTreeSpace &);
211  void operator= (dQuadTreeSpace &);
212 
213 public:
214  dQuadTreeSpace (const dVector3 center, const dVector3 extents, int depth)
215  { _id = (dGeomID) dQuadTreeSpaceCreate (0,center,extents,depth); }
216  dQuadTreeSpace (dSpace &space, const dVector3 center, const dVector3 extents, int depth)
217  { _id = (dGeomID) dQuadTreeSpaceCreate (space.id(),center,extents,depth); }
218  dQuadTreeSpace (dSpaceID space, const dVector3 center, const dVector3 extents, int depth)
219  { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
220 };
221 
222 
223 class dSphere : public dGeom {
224  // intentionally undefined, don't use these
225  dSphere (dSphere &);
226  void operator= (dSphere &);
227 
228 public:
229  dSphere () { }
230  dSphere (dReal radius)
231  { _id = dCreateSphere (0, radius); }
232  dSphere (dSpace &space, dReal radius)
233  { _id = dCreateSphere (space.id(), radius); }
234  dSphere (dSpaceID space, dReal radius)
235  { _id = dCreateSphere (space, radius); }
236 
237  void create (dSpaceID space, dReal radius) {
238  if (_id) dGeomDestroy (_id);
239  _id = dCreateSphere (space, radius);
240  }
241 
242  void setRadius (dReal radius)
243  { dGeomSphereSetRadius (_id, radius); }
244  dReal getRadius() const
245  { return dGeomSphereGetRadius (_id); }
246 };
247 
248 
249 class dBox : public dGeom {
250  // intentionally undefined, don't use these
251  dBox (dBox &);
252  void operator= (dBox &);
253 
254 public:
255  dBox () { }
256  dBox (dReal lx, dReal ly, dReal lz)
257  { _id = dCreateBox (0,lx,ly,lz); }
258  dBox (dSpace &space, dReal lx, dReal ly, dReal lz)
259  { _id = dCreateBox (space,lx,ly,lz); }
260  dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
261  { _id = dCreateBox (space,lx,ly,lz); }
262 
263  void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
264  if (_id) dGeomDestroy (_id);
265  _id = dCreateBox (space,lx,ly,lz);
266  }
267 
268  void setLengths (dReal lx, dReal ly, dReal lz)
269  { dGeomBoxSetLengths (_id, lx, ly, lz); }
270  void getLengths (dVector3 result) const
271  { dGeomBoxGetLengths (_id,result); }
272 };
273 
274 
275 class dPlane : public dGeom {
276  // intentionally undefined, don't use these
277  dPlane (dPlane &);
278  void operator= (dPlane &);
279 
280 public:
281  dPlane() { }
282  dPlane (dReal a, dReal b, dReal c, dReal d)
283  { _id = dCreatePlane (0,a,b,c,d); }
284  dPlane (dSpace &space, dReal a, dReal b, dReal c, dReal d)
285  { _id = dCreatePlane (space.id(),a,b,c,d); }
286  dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
287  { _id = dCreatePlane (space,a,b,c,d); }
288 
289  void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
290  if (_id) dGeomDestroy (_id);
291  _id = dCreatePlane (space,a,b,c,d);
292  }
293 
294  void setParams (dReal a, dReal b, dReal c, dReal d)
295  { dGeomPlaneSetParams (_id, a, b, c, d); }
296  void getParams (dVector4 result) const
297  { dGeomPlaneGetParams (_id,result); }
298 };
299 
300 
301 class dCapsule : public dGeom {
302  // intentionally undefined, don't use these
303  dCapsule (dCapsule &);
304  void operator= (dCapsule &);
305 
306 public:
307  dCapsule() { }
308  dCapsule (dReal radius, dReal length)
309  { _id = dCreateCapsule (0,radius,length); }
310  dCapsule (dSpace &space, dReal radius, dReal length)
311  { _id = dCreateCapsule (space.id(),radius,length); }
312  dCapsule (dSpaceID space, dReal radius, dReal length)
313  { _id = dCreateCapsule (space,radius,length); }
314 
315  void create (dSpaceID space, dReal radius, dReal length) {
316  if (_id) dGeomDestroy (_id);
317  _id = dCreateCapsule (space,radius,length);
318  }
319 
320  void setParams (dReal radius, dReal length)
321  { dGeomCapsuleSetParams (_id, radius, length); }
322  void getParams (dReal *radius, dReal *length) const
323  { dGeomCapsuleGetParams (_id,radius,length); }
324 };
325 
326 
327 class dCylinder : public dGeom {
328  // intentionally undefined, don't use these
329  dCylinder (dCylinder &);
330  void operator= (dCylinder &);
331 
332 public:
333  dCylinder() { }
334  dCylinder (dReal radius, dReal length)
335  { _id = dCreateCylinder (0,radius,length); }
336  dCylinder (dSpace &space, dReal radius, dReal length)
337  { _id = dCreateCylinder (space.id(),radius,length); }
338  dCylinder (dSpaceID space, dReal radius, dReal length)
339  { _id = dCreateCylinder (space,radius,length); }
340 
341  void create (dSpaceID space, dReal radius, dReal length) {
342  if (_id) dGeomDestroy (_id);
343  _id = dCreateCylinder (space,radius,length);
344  }
345 
346  void setParams (dReal radius, dReal length)
347  { dGeomCylinderSetParams (_id, radius, length); }
348  void getParams (dReal *radius, dReal *length) const
349  { dGeomCylinderGetParams (_id,radius,length); }
350 };
351 
352 
353 class dRay : public dGeom {
354  // intentionally undefined, don't use these
355  dRay (dRay &);
356  void operator= (dRay &);
357 
358 public:
359  dRay() { }
360  dRay (dReal length)
361  { _id = dCreateRay (0,length); }
362  dRay (dSpace &space, dReal length)
363  { _id = dCreateRay (space.id(),length); }
364  dRay (dSpaceID space, dReal length)
365  { _id = dCreateRay (space,length); }
366 
367  void create (dSpaceID space, dReal length) {
368  if (_id) dGeomDestroy (_id);
369  _id = dCreateRay (space,length);
370  }
371 
372  void setLength (dReal length)
373  { dGeomRaySetLength (_id, length); }
374  dReal getLength()
375  { return dGeomRayGetLength (_id); }
376 
377  void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
378  { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
379  void get (dVector3 start, dVector3 dir)
380  { dGeomRayGet (_id, start, dir); }
381 
382 #ifdef WIN32
383 #pragma warning( push )
384 #pragma warning( disable : 4996 )
385 #else
386 #pragma GCC diagnostic push
387 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
388 #endif
389  ODE_API_DEPRECATED
390  void setParams (int firstContact, int backfaceCull)
391  { dGeomRaySetParams (_id, firstContact, backfaceCull); }
392 
393  ODE_API_DEPRECATED
394  void getParams (int *firstContact, int *backfaceCull)
395  { dGeomRayGetParams (_id, firstContact, backfaceCull); }
396 #ifdef WIN32
397 #pragma warning( pop )
398 #else
399 #pragma GCC diagnostic pop
400 #endif
401  void setBackfaceCull (int backfaceCull)
402  { dGeomRaySetBackfaceCull (_id, backfaceCull); }
403  int getBackfaceCull()
404  { return dGeomRayGetBackfaceCull (_id); }
405 
406  void setFirstContact (int firstContact)
407  { dGeomRaySetFirstContact (_id, firstContact); }
408  int getFirstContact()
409  { return dGeomRayGetFirstContact (_id); }
410 
411  void setClosestHit (int closestHit)
412  { dGeomRaySetClosestHit (_id, closestHit); }
413  int getClosestHit()
414  { return dGeomRayGetClosestHit (_id); }
415 };
416 
417 #ifdef WIN32
418 #pragma warning( push )
419 #pragma warning( disable : 4996 )
420 #else
421 #pragma GCC diagnostic push
422 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
423 #endif
424 
425 class ODE_API_DEPRECATED dGeomTransform : public dGeom {
426  // intentionally undefined, don't use these
427  dGeomTransform (dGeomTransform &);
428  void operator= (dGeomTransform &);
429 
430 public:
431  dGeomTransform() { }
432  dGeomTransform (dSpace &space)
433  { _id = dCreateGeomTransform (space.id()); }
434  dGeomTransform (dSpaceID space)
435  { _id = dCreateGeomTransform (space); }
436 
437  void create (dSpaceID space=0) {
438  if (_id) dGeomDestroy (_id);
439  _id = dCreateGeomTransform (space);
440  }
441 
442  void setGeom (dGeomID geom)
443  { dGeomTransformSetGeom (_id, geom); }
444  dGeomID getGeom() const
445  { return dGeomTransformGetGeom (_id); }
446 
447  void setCleanup (int mode)
448  { dGeomTransformSetCleanup (_id,mode); }
449  int getCleanup ()
450  { return dGeomTransformGetCleanup (_id); }
451 
452  void setInfo (int mode)
453  { dGeomTransformSetInfo (_id,mode); }
454  int getInfo()
455  { return dGeomTransformGetInfo (_id); }
456 };
457 
458 #ifdef WIN32
459 #pragma warning( pop )
460 #else
461 #pragma GCC diagnostic pop
462 #endif
463 
464 //}
465 
466 #endif
467 #endif
unsigned long dGeomGetCollideBits(dGeomID)
Get the &quot;collide&quot; bitfield for the given geom.
void dGeomDisable(dGeomID geom)
Disable a geom.
unsigned long dGeomGetCategoryBits(dGeomID)
Get the &quot;category&quot; bitfield for the given geom.
void dGeomSetCategoryBits(dGeomID geom, unsigned long bits)
Set the &quot;category&quot; bitfield for the given geom.
void dSpaceCollide2(dGeomID space1, dGeomID space2, void *data, dNearCallback *callback)
Determines which geoms from one space may potentially intersect with geoms from another space...
void dGeomGetPosRelPoint(dGeomID geom, dReal px, dReal py, dReal pz, dVector3 result)
takes a point in global coordinates and returns the point&#39;s position in geom-relative coordinates...
void dGeomSetCollideBits(dGeomID geom, unsigned long bits)
Set the &quot;collide&quot; bitfield for the given geom.
const dReal * dGeomGetPosition(dGeomID geom)
Get the position vector of a placeable geom.
void dGeomGetQuaternion(dGeomID geom, dQuaternion result)
Get the rotation quaternion of a placeable geom.
dSpaceID dGeomGetSpace(dGeomID)
Query for the space containing a particular geom.
void dGeomSetPosition(dGeomID geom, dReal x, dReal y, dReal z)
Set the position vector of a placeable geom.
dGeomID dCreateSphere(dSpaceID space, dReal radius)
Create a sphere geom of the given radius, and return its ID.
dReal dGeomSphereGetRadius(dGeomID sphere)
Retrieves the radius of a sphere geom.
void dGeomBoxGetLengths(dGeomID box, dVector3 result)
Get the side lengths of a box.
void dGeomGetRelPointPos(dGeomID geom, dReal px, dReal py, dReal pz, dVector3 result)
Get world position of a relative point on geom.
void dGeomSetData(dGeomID geom, void *data)
Set the user-defined data pointer stored in the geom.
void dGeomSphereSetRadius(dGeomID sphere, dReal radius)
Set the radius of a sphere geom.
void dGeomEnable(dGeomID geom)
Enable a geom.
void dSpaceCollide(dSpaceID space, void *data, dNearCallback *callback)
Determines which pairs of geoms in a space may potentially intersect, and calls the callback function...
void dGeomSetBody(dGeomID geom, dBodyID body)
Set the body associated with a placeable geom.
void dGeomSetQuaternion(dGeomID geom, const dQuaternion Q)
Set the rotation of a placeable geom.
void dNearCallback(void *data, dGeomID o1, dGeomID o2)
User callback for geom-geom collision testing.
Definition: collision_space.h:49
int dGeomIsSpace(dGeomID geom)
Determing if a geom is a space.
dBodyID dGeomGetBody(dGeomID geom)
Get the body associated with a placeable geom.
const dReal * dGeomGetRotation(dGeomID geom)
Get the rotation matrix of a placeable geom.
void dGeomBoxSetLengths(dGeomID box, dReal lx, dReal ly, dReal lz)
Set the side lengths of the given box.
void dGeomVectorToWorld(dGeomID geom, dReal px, dReal py, dReal pz, dVector3 result)
Convert from geom-local to world coordinates.
void dGeomSetRotation(dGeomID geom, const dMatrix3 R)
Set the rotation matrix of a placeable geom.
dGeomID dCreateBox(dSpaceID space, dReal lx, dReal ly, dReal lz)
Create a box geom with the provided side lengths.
int dGeomGetClass(dGeomID geom)
Given a geom, this returns its class.
void * dGeomGetData(dGeomID geom)
Get the user-defined data pointer stored in the geom.
void dGeomGetAABB(dGeomID geom, dReal aabb[6])
Return the axis-aligned bounding box.
int dGeomIsEnabled(dGeomID geom)
Check to see if a geom is enabled.
void dGeomVectorFromWorld(dGeomID geom, dReal px, dReal py, dReal pz, dVector3 result)
Convert from world to geom-local coordinates.
void dGeomDestroy(dGeomID geom)
Destroy a geom, removing it from any space.