Open Dynamics Engine

odecpp_collision.h

00001 /*************************************************************************
00002  *                          *
00003  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.    *
00004  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org    *
00005  *                          *
00006  * This library is free software; you can redistribute it and/or   *
00007  * modify it under the terms of EITHER:             *
00008  *   (1) The GNU Lesser General Public License as published by the Free  *
00009  *  Software Foundation; either version 2.1 of the License, or (at  *
00010  *  your option) any later version. The text of the GNU Lesser  *
00011  *  General Public License is included with this library in the    *
00012  *  file LICENSE.TXT.                   *
00013  *   (2) The BSD-style license that is included with this library in  *
00014  *  the file LICENSE-BSD.TXT.              *
00015  *                          *
00016  * This library is distributed in the hope that it will be useful,    *
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of  *
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00019  * LICENSE.TXT and LICENSE-BSD.TXT for more details.         *
00020  *                          *
00021  *************************************************************************/
00022 
00023 /* C++ interface for new collision API */
00024 
00025 
00026 #ifndef _ODE_ODECPP_COLLISION_H_
00027 #define _ODE_ODECPP_COLLISION_H_
00028 #ifdef __cplusplus
00029 
00030 //#include <ode/error.h>
00031 
00032 //namespace ode {
00033 
00034 class dGeom {
00035   // intentionally undefined, don't use these
00036   dGeom (dGeom &);
00037   void operator= (dGeom &);
00038 
00039 protected:
00040   dGeomID _id;
00041 
00042   dGeom()
00043     { _id = 0; }
00044 public:
00045   ~dGeom()
00046     { if (_id) dGeomDestroy (_id); }
00047 
00048   dGeomID id() const
00049     { return _id; }
00050   operator dGeomID() const
00051     { return _id; }
00052 
00053   void destroy() {
00054     if (_id) dGeomDestroy (_id);
00055     _id = 0;
00056   }
00057 
00058   int getClass() const
00059     { return dGeomGetClass (_id); }
00060 
00061   dSpaceID getSpace() const
00062     { return dGeomGetSpace (_id); }
00063 
00064   void setData (void *data)
00065     { dGeomSetData (_id,data); }
00066   void *getData() const
00067     { return dGeomGetData (_id); }
00068 
00069   void setBody (dBodyID b)
00070     { dGeomSetBody (_id,b); }
00071   dBodyID getBody() const
00072     { return dGeomGetBody (_id); }
00073 
00074   void setPosition (dReal x, dReal y, dReal z)
00075     { dGeomSetPosition (_id,x,y,z); }
00076   const dReal * getPosition() const
00077     { return dGeomGetPosition (_id); }
00078 
00079   void setRotation (const dMatrix3 R)
00080     { dGeomSetRotation (_id,R); }
00081   const dReal * getRotation() const
00082     { return dGeomGetRotation (_id); }
00083     
00084   void setQuaternion (const dQuaternion quat)
00085     { dGeomSetQuaternion (_id,quat); }
00086   void getQuaternion (dQuaternion quat) const
00087     { dGeomGetQuaternion (_id,quat); }
00088 
00089   void getAABB (dReal aabb[6]) const
00090     { dGeomGetAABB (_id, aabb); }
00091 
00092   int isSpace()
00093     { return dGeomIsSpace (_id); }
00094 
00095   void setCategoryBits (unsigned long bits)
00096     { dGeomSetCategoryBits (_id, bits); }
00097   void setCollideBits (unsigned long bits)
00098     { dGeomSetCollideBits (_id, bits); }
00099   unsigned long getCategoryBits()
00100     { return dGeomGetCategoryBits (_id); }
00101   unsigned long getCollideBits()
00102     { return dGeomGetCollideBits (_id); }
00103 
00104   void enable()
00105     { dGeomEnable (_id); }
00106   void disable()
00107     { dGeomDisable (_id); }
00108   int isEnabled()
00109     { return dGeomIsEnabled (_id); }
00110 
00111   void collide2 (dGeomID g, void *data, dNearCallback *callback)
00112     { dSpaceCollide2 (_id,g,data,callback); }
00113 };
00114 
00115 
00116 class dSpace : public dGeom {
00117   // intentionally undefined, don't use these
00118   dSpace (dSpace &);
00119   void operator= (dSpace &);
00120 
00121 protected:
00122   // the default constructor is protected so that you
00123   // can't instance this class. you must instance one
00124   // of its subclasses instead.
00125   dSpace () { _id = 0; }
00126 
00127 public:
00128   dSpaceID id() const
00129     { return (dSpaceID) _id; }
00130   operator dSpaceID() const
00131     { return (dSpaceID) _id; }
00132 
00133   void setCleanup (int mode)
00134     { dSpaceSetCleanup (id(), mode); }
00135   int getCleanup()
00136     { return dSpaceGetCleanup (id()); }
00137 
00138   void add (dGeomID x)
00139     { dSpaceAdd (id(), x); }
00140   void remove (dGeomID x)
00141     { dSpaceRemove (id(), x); }
00142   int query (dGeomID x)
00143     { return dSpaceQuery (id(),x); }
00144 
00145   int getNumGeoms()
00146     { return dSpaceGetNumGeoms (id()); }
00147   dGeomID getGeom (int i)
00148     { return dSpaceGetGeom (id(),i); }
00149 
00150   void collide (void *data, dNearCallback *callback)
00151     { dSpaceCollide (id(),data,callback); }
00152 };
00153 
00154 
00155 class dSimpleSpace : public dSpace {
00156   // intentionally undefined, don't use these
00157   dSimpleSpace (dSimpleSpace &);
00158   void operator= (dSimpleSpace &);
00159 
00160 public:
00161   dSimpleSpace ()
00162     { _id = (dGeomID) dSimpleSpaceCreate (0); }
00163   dSimpleSpace (dSpace &space)
00164     { _id = (dGeomID) dSimpleSpaceCreate (space.id()); }
00165   dSimpleSpace (dSpaceID space)
00166     { _id = (dGeomID) dSimpleSpaceCreate (space); }
00167 };
00168 
00169 
00170 class dHashSpace : public dSpace {
00171   // intentionally undefined, don't use these
00172   dHashSpace (dHashSpace &);
00173   void operator= (dHashSpace &);
00174 
00175 public:
00176   dHashSpace ()
00177     { _id = (dGeomID) dHashSpaceCreate (0); }
00178   dHashSpace (dSpace &space)
00179     { _id = (dGeomID) dHashSpaceCreate (space.id()); }
00180   dHashSpace (dSpaceID space)
00181     { _id = (dGeomID) dHashSpaceCreate (space); }
00182 
00183   void setLevels (int minlevel, int maxlevel)
00184     { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
00185 };
00186 
00187 
00188 class dQuadTreeSpace : public dSpace {
00189   // intentionally undefined, don't use these
00190   dQuadTreeSpace (dQuadTreeSpace &);
00191   void operator= (dQuadTreeSpace &);
00192 
00193 public:
00194   dQuadTreeSpace (const dVector3 center, const dVector3 extents, int depth)
00195     { _id = (dGeomID) dQuadTreeSpaceCreate (0,center,extents,depth); }
00196   dQuadTreeSpace (dSpace &space, const dVector3 center, const dVector3 extents, int depth)
00197     { _id = (dGeomID) dQuadTreeSpaceCreate (space.id(),center,extents,depth); }
00198   dQuadTreeSpace (dSpaceID space, const dVector3 center, const dVector3 extents, int depth)
00199     { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
00200 };
00201 
00202 
00203 class dSphere : public dGeom {
00204   // intentionally undefined, don't use these
00205   dSphere (dSphere &);
00206   void operator= (dSphere &);
00207 
00208 public:
00209   dSphere () { }
00210   dSphere (dReal radius)
00211     { _id = dCreateSphere (0, radius); }
00212   dSphere (dSpace &space, dReal radius)
00213     { _id = dCreateSphere (space.id(), radius); }
00214   dSphere (dSpaceID space, dReal radius)
00215     { _id = dCreateSphere (space, radius); }
00216 
00217   void create (dSpaceID space, dReal radius) {
00218     if (_id) dGeomDestroy (_id);
00219     _id = dCreateSphere (space, radius);
00220   }
00221 
00222   void setRadius (dReal radius)
00223     { dGeomSphereSetRadius (_id, radius); }
00224   dReal getRadius() const
00225     { return dGeomSphereGetRadius (_id); }
00226 };
00227 
00228 
00229 class dBox : public dGeom {
00230   // intentionally undefined, don't use these
00231   dBox (dBox &);
00232   void operator= (dBox &);
00233 
00234 public:
00235   dBox () { }
00236   dBox (dReal lx, dReal ly, dReal lz)
00237     { _id = dCreateBox (0,lx,ly,lz); }
00238   dBox (dSpace &space, dReal lx, dReal ly, dReal lz)
00239     { _id = dCreateBox (space,lx,ly,lz); }
00240   dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
00241     { _id = dCreateBox (space,lx,ly,lz); }
00242 
00243   void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
00244     if (_id) dGeomDestroy (_id);
00245     _id = dCreateBox (space,lx,ly,lz);
00246   }
00247 
00248   void setLengths (dReal lx, dReal ly, dReal lz)
00249     { dGeomBoxSetLengths (_id, lx, ly, lz); }
00250   void getLengths (dVector3 result) const
00251     { dGeomBoxGetLengths (_id,result); }
00252 };
00253 
00254 
00255 class dPlane : public dGeom {
00256   // intentionally undefined, don't use these
00257   dPlane (dPlane &);
00258   void operator= (dPlane &);
00259 
00260 public:
00261   dPlane() { }
00262   dPlane (dReal a, dReal b, dReal c, dReal d)
00263     { _id = dCreatePlane (0,a,b,c,d); }
00264   dPlane (dSpace &space, dReal a, dReal b, dReal c, dReal d)
00265     { _id = dCreatePlane (space.id(),a,b,c,d); }
00266   dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
00267     { _id = dCreatePlane (space,a,b,c,d); }
00268 
00269   void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
00270     if (_id) dGeomDestroy (_id);
00271     _id = dCreatePlane (space,a,b,c,d);
00272   }
00273 
00274   void setParams (dReal a, dReal b, dReal c, dReal d)
00275     { dGeomPlaneSetParams (_id, a, b, c, d); }
00276   void getParams (dVector4 result) const
00277     { dGeomPlaneGetParams (_id,result); }
00278 };
00279 
00280 
00281 class dCapsule : public dGeom {
00282   // intentionally undefined, don't use these
00283   dCapsule (dCapsule &);
00284   void operator= (dCapsule &);
00285 
00286 public:
00287   dCapsule() { }
00288   dCapsule (dReal radius, dReal length)
00289     { _id = dCreateCapsule (0,radius,length); }
00290   dCapsule (dSpace &space, dReal radius, dReal length)
00291     { _id = dCreateCapsule (space.id(),radius,length); }
00292   dCapsule (dSpaceID space, dReal radius, dReal length)
00293     { _id = dCreateCapsule (space,radius,length); }
00294 
00295   void create (dSpaceID space, dReal radius, dReal length) {
00296     if (_id) dGeomDestroy (_id);
00297     _id = dCreateCapsule (space,radius,length);
00298   }
00299 
00300   void setParams (dReal radius, dReal length)
00301     { dGeomCapsuleSetParams (_id, radius, length); }
00302   void getParams (dReal *radius, dReal *length) const
00303     { dGeomCapsuleGetParams (_id,radius,length); }
00304 };
00305 
00306 
00307 class dCylinder : public dGeom {
00308   // intentionally undefined, don't use these
00309   dCylinder (dCylinder &);
00310   void operator= (dCylinder &);
00311 
00312 public:
00313   dCylinder() { }
00314   dCylinder (dReal radius, dReal length)
00315     { _id = dCreateCylinder (0,radius,length); }
00316   dCylinder (dSpace &space, dReal radius, dReal length)
00317     { _id = dCreateCylinder (space.id(),radius,length); }
00318   dCylinder (dSpaceID space, dReal radius, dReal length)
00319     { _id = dCreateCylinder (space,radius,length); }
00320 
00321   void create (dSpaceID space, dReal radius, dReal length) {
00322     if (_id) dGeomDestroy (_id);
00323     _id = dCreateCylinder (space,radius,length);
00324   }
00325 
00326   void setParams (dReal radius, dReal length)
00327     { dGeomCylinderSetParams (_id, radius, length); }
00328   void getParams (dReal *radius, dReal *length) const
00329     { dGeomCylinderGetParams (_id,radius,length); }
00330 };
00331 
00332 
00333 class dRay : public dGeom {
00334   // intentionally undefined, don't use these
00335   dRay (dRay &);
00336   void operator= (dRay &);
00337 
00338 public:
00339   dRay() { }
00340   dRay (dReal length)
00341     { _id = dCreateRay (0,length); }
00342   dRay (dSpace &space, dReal length)
00343     { _id = dCreateRay (space.id(),length); }
00344   dRay (dSpaceID space, dReal length)
00345     { _id = dCreateRay (space,length); }
00346 
00347   void create (dSpaceID space, dReal length) {
00348     if (_id) dGeomDestroy (_id);
00349     _id = dCreateRay (space,length);
00350   }
00351 
00352   void setLength (dReal length)
00353     { dGeomRaySetLength (_id, length); }
00354   dReal getLength()
00355     { return dGeomRayGetLength (_id); }
00356 
00357   void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
00358     { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
00359   void get (dVector3 start, dVector3 dir)
00360     { dGeomRayGet (_id, start, dir); }
00361 
00362   void setParams (int firstContact, int backfaceCull)
00363     { dGeomRaySetParams (_id, firstContact, backfaceCull); }
00364   void getParams (int *firstContact, int *backfaceCull)
00365     { dGeomRayGetParams (_id, firstContact, backfaceCull); }
00366   void setClosestHit (int closestHit)
00367     { dGeomRaySetClosestHit (_id, closestHit); }
00368   int getClosestHit()
00369     { return dGeomRayGetClosestHit (_id); }
00370 };
00371 
00372 
00373 class dGeomTransform : public dGeom {
00374   // intentionally undefined, don't use these
00375   dGeomTransform (dGeomTransform &);
00376   void operator= (dGeomTransform &);
00377 
00378 public:
00379   dGeomTransform() { }
00380   dGeomTransform (dSpace &space)
00381     { _id = dCreateGeomTransform (space.id()); }
00382   dGeomTransform (dSpaceID space)
00383     { _id = dCreateGeomTransform (space); }
00384 
00385   void create (dSpaceID space=0) {
00386     if (_id) dGeomDestroy (_id);
00387     _id = dCreateGeomTransform (space);
00388   }
00389 
00390   void setGeom (dGeomID geom)
00391     { dGeomTransformSetGeom (_id, geom); }
00392   dGeomID getGeom() const
00393     { return dGeomTransformGetGeom (_id); }
00394 
00395   void setCleanup (int mode)
00396     { dGeomTransformSetCleanup (_id,mode); }
00397   int getCleanup ()
00398     { return dGeomTransformGetCleanup (_id); }
00399 
00400   void setInfo (int mode)
00401     { dGeomTransformSetInfo (_id,mode); }
00402   int getInfo()
00403     { return dGeomTransformGetInfo (_id); }
00404 };
00405 
00406 //}
00407 
00408 #endif
00409 #endif