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 getRelPointPos (dReal px, dReal py, dReal pz, dVector3 result) const
00112     { dGeomGetRelPointPos (_id, px, py, pz, result); }
00113   void getRelPointPos (const dVector3 p, dVector3 result) const
00114     { getRelPointPos (p[0], p[1], p[2], result); }
00115 
00116   void getPosRelPoint (dReal px, dReal py, dReal pz, dVector3 result) const
00117     { dGeomGetPosRelPoint (_id, px, py, pz, result); }
00118   void getPosRelPoint (const dVector3 p, dVector3 result) const
00119     { getPosRelPoint (p[0], p[1], p[2], result); }
00120 
00121   void vectorToWorld (dReal px, dReal py, dReal pz, dVector3 result) const
00122     { dGeomVectorToWorld (_id, px, py, pz, result); }
00123   void vectorToWorld (const dVector3 p, dVector3 result) const
00124     { vectorToWorld (p[0], p[1], p[2], result); }
00125 
00126   void vectorFromWorld (dReal px, dReal py, dReal pz, dVector3 result) const
00127     { dGeomVectorFromWorld (_id, px, py, pz, result); }
00128   void vectorFromWorld (const dVector3 p, dVector3 result) const
00129     { vectorFromWorld (p[0], p[1], p[2], result); }
00130   
00131   void collide2 (dGeomID g, void *data, dNearCallback *callback)
00132     { dSpaceCollide2 (_id,g,data,callback); }
00133 };
00134 
00135 
00136 class dSpace : public dGeom {
00137   // intentionally undefined, don't use these
00138   dSpace (dSpace &);
00139   void operator= (dSpace &);
00140 
00141 protected:
00142   // the default constructor is protected so that you
00143   // can't instance this class. you must instance one
00144   // of its subclasses instead.
00145   dSpace () { _id = 0; }
00146 
00147 public:
00148   dSpaceID id() const
00149     { return (dSpaceID) _id; }
00150   operator dSpaceID() const
00151     { return (dSpaceID) _id; }
00152 
00153   void setCleanup (int mode)
00154     { dSpaceSetCleanup (id(), mode); }
00155   int getCleanup()
00156     { return dSpaceGetCleanup (id()); }
00157 
00158   void add (dGeomID x)
00159     { dSpaceAdd (id(), x); }
00160   void remove (dGeomID x)
00161     { dSpaceRemove (id(), x); }
00162   int query (dGeomID x)
00163     { return dSpaceQuery (id(),x); }
00164 
00165   int getNumGeoms()
00166     { return dSpaceGetNumGeoms (id()); }
00167   dGeomID getGeom (int i)
00168     { return dSpaceGetGeom (id(),i); }
00169 
00170   void collide (void *data, dNearCallback *callback)
00171     { dSpaceCollide (id(),data,callback); }
00172 };
00173 
00174 
00175 class dSimpleSpace : public dSpace {
00176   // intentionally undefined, don't use these
00177   dSimpleSpace (dSimpleSpace &);
00178   void operator= (dSimpleSpace &);
00179 
00180 public:
00181   dSimpleSpace ()
00182     { _id = (dGeomID) dSimpleSpaceCreate (0); }
00183   dSimpleSpace (dSpace &space)
00184     { _id = (dGeomID) dSimpleSpaceCreate (space.id()); }
00185   dSimpleSpace (dSpaceID space)
00186     { _id = (dGeomID) dSimpleSpaceCreate (space); }
00187 };
00188 
00189 
00190 class dHashSpace : public dSpace {
00191   // intentionally undefined, don't use these
00192   dHashSpace (dHashSpace &);
00193   void operator= (dHashSpace &);
00194 
00195 public:
00196   dHashSpace ()
00197     { _id = (dGeomID) dHashSpaceCreate (0); }
00198   dHashSpace (dSpace &space)
00199     { _id = (dGeomID) dHashSpaceCreate (space.id()); }
00200   dHashSpace (dSpaceID space)
00201     { _id = (dGeomID) dHashSpaceCreate (space); }
00202 
00203   void setLevels (int minlevel, int maxlevel)
00204     { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
00205 };
00206 
00207 
00208 class dQuadTreeSpace : public dSpace {
00209   // intentionally undefined, don't use these
00210   dQuadTreeSpace (dQuadTreeSpace &);
00211   void operator= (dQuadTreeSpace &);
00212 
00213 public:
00214   dQuadTreeSpace (const dVector3 center, const dVector3 extents, int depth)
00215     { _id = (dGeomID) dQuadTreeSpaceCreate (0,center,extents,depth); }
00216   dQuadTreeSpace (dSpace &space, const dVector3 center, const dVector3 extents, int depth)
00217     { _id = (dGeomID) dQuadTreeSpaceCreate (space.id(),center,extents,depth); }
00218   dQuadTreeSpace (dSpaceID space, const dVector3 center, const dVector3 extents, int depth)
00219     { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
00220 };
00221 
00222 
00223 class dSphere : public dGeom {
00224   // intentionally undefined, don't use these
00225   dSphere (dSphere &);
00226   void operator= (dSphere &);
00227 
00228 public:
00229   dSphere () { }
00230   dSphere (dReal radius)
00231     { _id = dCreateSphere (0, radius); }
00232   dSphere (dSpace &space, dReal radius)
00233     { _id = dCreateSphere (space.id(), radius); }
00234   dSphere (dSpaceID space, dReal radius)
00235     { _id = dCreateSphere (space, radius); }
00236 
00237   void create (dSpaceID space, dReal radius) {
00238     if (_id) dGeomDestroy (_id);
00239     _id = dCreateSphere (space, radius);
00240   }
00241 
00242   void setRadius (dReal radius)
00243     { dGeomSphereSetRadius (_id, radius); }
00244   dReal getRadius() const
00245     { return dGeomSphereGetRadius (_id); }
00246 };
00247 
00248 
00249 class dBox : public dGeom {
00250   // intentionally undefined, don't use these
00251   dBox (dBox &);
00252   void operator= (dBox &);
00253 
00254 public:
00255   dBox () { }
00256   dBox (dReal lx, dReal ly, dReal lz)
00257     { _id = dCreateBox (0,lx,ly,lz); }
00258   dBox (dSpace &space, dReal lx, dReal ly, dReal lz)
00259     { _id = dCreateBox (space,lx,ly,lz); }
00260   dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
00261     { _id = dCreateBox (space,lx,ly,lz); }
00262 
00263   void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
00264     if (_id) dGeomDestroy (_id);
00265     _id = dCreateBox (space,lx,ly,lz);
00266   }
00267 
00268   void setLengths (dReal lx, dReal ly, dReal lz)
00269     { dGeomBoxSetLengths (_id, lx, ly, lz); }
00270   void getLengths (dVector3 result) const
00271     { dGeomBoxGetLengths (_id,result); }
00272 };
00273 
00274 
00275 class dPlane : public dGeom {
00276   // intentionally undefined, don't use these
00277   dPlane (dPlane &);
00278   void operator= (dPlane &);
00279 
00280 public:
00281   dPlane() { }
00282   dPlane (dReal a, dReal b, dReal c, dReal d)
00283     { _id = dCreatePlane (0,a,b,c,d); }
00284   dPlane (dSpace &space, dReal a, dReal b, dReal c, dReal d)
00285     { _id = dCreatePlane (space.id(),a,b,c,d); }
00286   dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
00287     { _id = dCreatePlane (space,a,b,c,d); }
00288 
00289   void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
00290     if (_id) dGeomDestroy (_id);
00291     _id = dCreatePlane (space,a,b,c,d);
00292   }
00293 
00294   void setParams (dReal a, dReal b, dReal c, dReal d)
00295     { dGeomPlaneSetParams (_id, a, b, c, d); }
00296   void getParams (dVector4 result) const
00297     { dGeomPlaneGetParams (_id,result); }
00298 };
00299 
00300 
00301 class dCapsule : public dGeom {
00302   // intentionally undefined, don't use these
00303   dCapsule (dCapsule &);
00304   void operator= (dCapsule &);
00305 
00306 public:
00307   dCapsule() { }
00308   dCapsule (dReal radius, dReal length)
00309     { _id = dCreateCapsule (0,radius,length); }
00310   dCapsule (dSpace &space, dReal radius, dReal length)
00311     { _id = dCreateCapsule (space.id(),radius,length); }
00312   dCapsule (dSpaceID space, dReal radius, dReal length)
00313     { _id = dCreateCapsule (space,radius,length); }
00314 
00315   void create (dSpaceID space, dReal radius, dReal length) {
00316     if (_id) dGeomDestroy (_id);
00317     _id = dCreateCapsule (space,radius,length);
00318   }
00319 
00320   void setParams (dReal radius, dReal length)
00321     { dGeomCapsuleSetParams (_id, radius, length); }
00322   void getParams (dReal *radius, dReal *length) const
00323     { dGeomCapsuleGetParams (_id,radius,length); }
00324 };
00325 
00326 
00327 class dCylinder : public dGeom {
00328   // intentionally undefined, don't use these
00329   dCylinder (dCylinder &);
00330   void operator= (dCylinder &);
00331 
00332 public:
00333   dCylinder() { }
00334   dCylinder (dReal radius, dReal length)
00335     { _id = dCreateCylinder (0,radius,length); }
00336   dCylinder (dSpace &space, dReal radius, dReal length)
00337     { _id = dCreateCylinder (space.id(),radius,length); }
00338   dCylinder (dSpaceID space, dReal radius, dReal length)
00339     { _id = dCreateCylinder (space,radius,length); }
00340 
00341   void create (dSpaceID space, dReal radius, dReal length) {
00342     if (_id) dGeomDestroy (_id);
00343     _id = dCreateCylinder (space,radius,length);
00344   }
00345 
00346   void setParams (dReal radius, dReal length)
00347     { dGeomCylinderSetParams (_id, radius, length); }
00348   void getParams (dReal *radius, dReal *length) const
00349     { dGeomCylinderGetParams (_id,radius,length); }
00350 };
00351 
00352 
00353 class dRay : public dGeom {
00354   // intentionally undefined, don't use these
00355   dRay (dRay &);
00356   void operator= (dRay &);
00357 
00358 public:
00359   dRay() { }
00360   dRay (dReal length)
00361     { _id = dCreateRay (0,length); }
00362   dRay (dSpace &space, dReal length)
00363     { _id = dCreateRay (space.id(),length); }
00364   dRay (dSpaceID space, dReal length)
00365     { _id = dCreateRay (space,length); }
00366 
00367   void create (dSpaceID space, dReal length) {
00368     if (_id) dGeomDestroy (_id);
00369     _id = dCreateRay (space,length);
00370   }
00371 
00372   void setLength (dReal length)
00373     { dGeomRaySetLength (_id, length); }
00374   dReal getLength()
00375     { return dGeomRayGetLength (_id); }
00376 
00377   void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
00378     { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
00379   void get (dVector3 start, dVector3 dir)
00380     { dGeomRayGet (_id, start, dir); }
00381 
00382   void setParams (int firstContact, int backfaceCull)
00383     { dGeomRaySetParams (_id, firstContact, backfaceCull); }
00384   void getParams (int *firstContact, int *backfaceCull)
00385     { dGeomRayGetParams (_id, firstContact, backfaceCull); }
00386   void setClosestHit (int closestHit)
00387     { dGeomRaySetClosestHit (_id, closestHit); }
00388   int getClosestHit()
00389     { return dGeomRayGetClosestHit (_id); }
00390 };
00391 
00392 
00393 class dGeomTransform : public dGeom {
00394   // intentionally undefined, don't use these
00395   dGeomTransform (dGeomTransform &);
00396   void operator= (dGeomTransform &);
00397 
00398 public:
00399   dGeomTransform() { }
00400   dGeomTransform (dSpace &space)
00401     { _id = dCreateGeomTransform (space.id()); }
00402   dGeomTransform (dSpaceID space)
00403     { _id = dCreateGeomTransform (space); }
00404 
00405   void create (dSpaceID space=0) {
00406     if (_id) dGeomDestroy (_id);
00407     _id = dCreateGeomTransform (space);
00408   }
00409 
00410   void setGeom (dGeomID geom)
00411     { dGeomTransformSetGeom (_id, geom); }
00412   dGeomID getGeom() const
00413     { return dGeomTransformGetGeom (_id); }
00414 
00415   void setCleanup (int mode)
00416     { dGeomTransformSetCleanup (_id,mode); }
00417   int getCleanup ()
00418     { return dGeomTransformGetCleanup (_id); }
00419 
00420   void setInfo (int mode)
00421     { dGeomTransformSetInfo (_id,mode); }
00422   int getInfo()
00423     { return dGeomTransformGetInfo (_id); }
00424 };
00425 
00426 //}
00427 
00428 #endif
00429 #endif