- Main Page
- Modules
- Data Structures
- Files

# 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
    00033 class dGeom {
    00034   // intentionally undefined, don't use these
    00035   dGeom (dGeom &);
    00036   void operator= (dGeom &);
    00037
    00038 protected:
    00039   dGeomID _id;
    00040
    00041 public:
    00042   dGeom()
    00043     { _id = 0; }
    00044   ~dGeom()
    00045     { if (_id) dGeomDestroy (_id); }
    00046
    00047   dGeomID id() const
    00048     { return _id; }
    00049   operator dGeomID() const
    00050     { return _id; }
    00051
    00052   void destroy() {
    00053     if (_id) dGeomDestroy (_id);
    00054     _id = 0;
    00055   }
    00056
    00057   int getClass() const
    00058     { return dGeomGetClass (_id); }
    00059
    00060   dSpaceID getSpace() const
    00061     { return dGeomGetSpace (_id); }
    00062
    00063   void setData (void *data)
    00064     { dGeomSetData (_id,data); }
    00065   void *getData() const
    00066     { return dGeomGetData (_id); }
    00067
    00068   void setBody (dBodyID b)
    00069     { dGeomSetBody (_id,b); }
    00070   dBodyID getBody() const
    00071     { return dGeomGetBody (_id); }
    00072
    00073   void setPosition (dReal x, dReal y, dReal z)
    00074     { dGeomSetPosition (_id,x,y,z); }
    00075   const dReal * getPosition() const
    00076     { return dGeomGetPosition (_id); }
    00077
    00078   void setRotation (const dMatrix3 R)
    00079     { dGeomSetRotation (_id,R); }
    00080   const dReal * getRotation() const
    00081     { return dGeomGetRotation (_id); }
    00082
    00083   void setQuaternion (const dQuaternion quat)
    00084     { dGeomSetQuaternion (_id,quat); }
    00085   void getQuaternion (dQuaternion quat) const
    00086     { dGeomGetQuaternion (_id,quat); }
    00087
    00088   void getAABB (dReal aabb[6]) const
    00089     { dGeomGetAABB (_id, aabb); }
    00090
    00091   int isSpace()
    00092     { return dGeomIsSpace (_id); }
    00093
    00094   void setCategoryBits (unsigned long bits)
    00095     { dGeomSetCategoryBits (_id, bits); }
    00096   void setCollideBits (unsigned long bits)
    00097     { dGeomSetCollideBits (_id, bits); }
    00098   unsigned long getCategoryBits()
    00099     { return dGeomGetCategoryBits (_id); }
    00100   unsigned long getCollideBits()
    00101     { return dGeomGetCollideBits (_id); }
    00102
    00103   void enable()
    00104     { dGeomEnable (_id); }
    00105   void disable()
    00106     { dGeomDisable (_id); }
    00107   int isEnabled()
    00108     { return dGeomIsEnabled (_id); }
    00109
    00110   void collide2 (dGeomID g, void *data, dNearCallback *callback)
    00111     { dSpaceCollide2 (_id,g,data,callback); }
    00112 };
    00113
    00114
    00115 class dSpace : public dGeom {
    00116   // intentionally undefined, don't use these
    00117   dSpace (dSpace &);
    00118   void operator= (dSpace &);
    00119
    00120 protected:
    00121   // the default constructor is protected so that you
    00122   // can't instance this class. you must instance one
    00123   // of its subclasses instead.
    00124   dSpace () { _id = 0; }
    00125
    00126 public:
    00127   dSpaceID id() const
    00128     { return (dSpaceID) _id; }
    00129   operator dSpaceID() const
    00130     { return (dSpaceID) _id; }
    00131
    00132   void setCleanup (int mode)
    00133     { dSpaceSetCleanup (id(), mode); }
    00134   int getCleanup()
    00135     { return dSpaceGetCleanup (id()); }
    00136
    00137   void add (dGeomID x)
    00138     { dSpaceAdd (id(), x); }
    00139   void remove (dGeomID x)
    00140     { dSpaceRemove (id(), x); }
    00141   int query (dGeomID x)
    00142     { return dSpaceQuery (id(),x); }
    00143
    00144   int getNumGeoms()
    00145     { return dSpaceGetNumGeoms (id()); }
    00146   dGeomID getGeom (int i)
    00147     { return dSpaceGetGeom (id(),i); }
    00148
    00149   void collide (void *data, dNearCallback *callback)
    00150     { dSpaceCollide (id(),data,callback); }
    00151 };
    00152
    00153
    00154 class dSimpleSpace : public dSpace {
    00155   // intentionally undefined, don't use these
    00156   dSimpleSpace (dSimpleSpace &);
    00157   void operator= (dSimpleSpace &);
    00158
    00159 public:
    00160   dSimpleSpace (dSpaceID space)
    00161     { _id = (dGeomID) dSimpleSpaceCreate (space); }
    00162 };
    00163
    00164
    00165 class dHashSpace : public dSpace {
    00166   // intentionally undefined, don't use these
    00167   dHashSpace (dHashSpace &);
    00168   void operator= (dHashSpace &);
    00169
    00170 public:
    00171   dHashSpace (dSpaceID space)
    00172     { _id = (dGeomID) dHashSpaceCreate (space); }
    00173   void setLevels (int minlevel, int maxlevel)
    00174     { dHashSpaceSetLevels (id(),minlevel,maxlevel); }
    00175 };
    00176
    00177
    00178 class dQuadTreeSpace : public dSpace {
    00179   // intentionally undefined, don't use these
    00180   dQuadTreeSpace (dQuadTreeSpace &);
    00181   void operator= (dQuadTreeSpace &);
    00182
    00183 public:
    00184   dQuadTreeSpace (dSpaceID space, dVector3 center, dVector3 extents, int depth)
    00185     { _id = (dGeomID) dQuadTreeSpaceCreate (space,center,extents,depth); }
    00186 };
    00187
    00188
    00189 class dSphere : public dGeom {
    00190   // intentionally undefined, don't use these
    00191   dSphere (dSphere &);
    00192   void operator= (dSphere &);
    00193
    00194 public:
    00195   dSphere () { }
    00196   dSphere (dSpaceID space, dReal radius)
    00197     { _id = dCreateSphere (space, radius); }
    00198
    00199   void create (dSpaceID space, dReal radius) {
    00200     if (_id) dGeomDestroy (_id);
    00201     _id = dCreateSphere (space, radius);
    00202   }
    00203
    00204   void setRadius (dReal radius)
    00205     { dGeomSphereSetRadius (_id, radius); }
    00206   dReal getRadius() const
    00207     { return dGeomSphereGetRadius (_id); }
    00208 };
    00209
    00210
    00211 class dBox : public dGeom {
    00212   // intentionally undefined, don't use these
    00213   dBox (dBox &);
    00214   void operator= (dBox &);
    00215
    00216 public:
    00217   dBox () { }
    00218   dBox (dSpaceID space, dReal lx, dReal ly, dReal lz)
    00219     { _id = dCreateBox (space,lx,ly,lz); }
    00220
    00221   void create (dSpaceID space, dReal lx, dReal ly, dReal lz) {
    00222     if (_id) dGeomDestroy (_id);
    00223     _id = dCreateBox (space,lx,ly,lz);
    00224   }
    00225
    00226   void setLengths (dReal lx, dReal ly, dReal lz)
    00227     { dGeomBoxSetLengths (_id, lx, ly, lz); }
    00228   void getLengths (dVector3 result) const
    00229     { dGeomBoxGetLengths (_id,result); }
    00230 };
    00231
    00232
    00233 class dPlane : public dGeom {
    00234   // intentionally undefined, don't use these
    00235   dPlane (dPlane &);
    00236   void operator= (dPlane &);
    00237
    00238 public:
    00239   dPlane() { }
    00240   dPlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d)
    00241     { _id = dCreatePlane (space,a,b,c,d); }
    00242
    00243   void create (dSpaceID space, dReal a, dReal b, dReal c, dReal d) {
    00244     if (_id) dGeomDestroy (_id);
    00245     _id = dCreatePlane (space,a,b,c,d);
    00246   }
    00247
    00248   void setParams (dReal a, dReal b, dReal c, dReal d)
    00249     { dGeomPlaneSetParams (_id, a, b, c, d); }
    00250   void getParams (dVector4 result) const
    00251     { dGeomPlaneGetParams (_id,result); }
    00252 };
    00253
    00254
    00255 class dCapsule : public dGeom {
    00256   // intentionally undefined, don't use these
    00257   dCapsule (dCapsule &);
    00258   void operator= (dCapsule &);
    00259
    00260 public:
    00261   dCapsule() { }
    00262   dCapsule (dSpaceID space, dReal radius, dReal length)
    00263     { _id = dCreateCapsule (space,radius,length); }
    00264
    00265   void create (dSpaceID space, dReal radius, dReal length) {
    00266     if (_id) dGeomDestroy (_id);
    00267     _id = dCreateCapsule (space,radius,length);
    00268   }
    00269
    00270   void setParams (dReal radius, dReal length)
    00271     { dGeomCapsuleSetParams (_id, radius, length); }
    00272   void getParams (dReal *radius, dReal *length) const
    00273     { dGeomCapsuleGetParams (_id,radius,length); }
    00274 };
    00275
    00276
    00277 class dRay : public dGeom {
    00278   // intentionally undefined, don't use these
    00279   dRay (dRay &);
    00280   void operator= (dRay &);
    00281
    00282 public:
    00283   dRay() { }
    00284   dRay (dSpaceID space, dReal length)
    00285     { _id = dCreateRay (space,length); }
    00286
    00287   void create (dSpaceID space, dReal length) {
    00288     if (_id) dGeomDestroy (_id);
    00289     _id = dCreateRay (space,length);
    00290   }
    00291
    00292   void setLength (dReal length)
    00293     { dGeomRaySetLength (_id, length); }
    00294   dReal getLength()
    00295     { return dGeomRayGetLength (_id); }
    00296
    00297   void set (dReal px, dReal py, dReal pz, dReal dx, dReal dy, dReal dz)
    00298     { dGeomRaySet (_id, px, py, pz, dx, dy, dz); }
    00299   void get (dVector3 start, dVector3 dir)
    00300     { dGeomRayGet (_id, start, dir); }
    00301
    00302   void setParams (int firstContact, int backfaceCull)
    00303     { dGeomRaySetParams (_id, firstContact, backfaceCull); }
    00304   void getParams (int *firstContact, int *backfaceCull)
    00305     { dGeomRayGetParams (_id, firstContact, backfaceCull); }
    00306   void setClosestHit (int closestHit)
    00307     { dGeomRaySetClosestHit (_id, closestHit); }
    00308   int getClosestHit()
    00309     { return dGeomRayGetClosestHit (_id); }
    00310 };
    00311
    00312
    00313 class dGeomTransform : public dGeom {
    00314   // intentionally undefined, don't use these
    00315   dGeomTransform (dGeomTransform &);
    00316   void operator= (dGeomTransform &);
    00317
    00318 public:
    00319   dGeomTransform() { }
    00320   dGeomTransform (dSpaceID space)
    00321     { _id = dCreateGeomTransform (space); }
    00322
    00323   void create (dSpaceID space=0) {
    00324     if (_id) dGeomDestroy (_id);
    00325     _id = dCreateGeomTransform (space);
    00326   }
    00327
    00328   void setGeom (dGeomID geom)
    00329     { dGeomTransformSetGeom (_id, geom); }
    00330   dGeomID getGeom() const
    00331     { return dGeomTransformGetGeom (_id); }
    00332
    00333   void setCleanup (int mode)
    00334     { dGeomTransformSetCleanup (_id,mode); }
    00335   int getCleanup ()
    00336     { return dGeomTransformGetCleanup (_id); }
    00337
    00338   void setInfo (int mode)
    00339     { dGeomTransformSetInfo (_id,mode); }
    00340   int getInfo()
    00341     { return dGeomTransformGetInfo (_id); }
    00342 };
    00343
    00344
    00345 #endif
    00346 #endif