- Main Page
- Modules
- Data Structures
- Files

# collision.h

    00001 /*************************************************************************
    00002  *                                                                       *
    00003  * Open Dynamics Engine, Copyright (C) 2001-2003 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 #ifndef _ODE_COLLISION_H_
    00024 #define _ODE_COLLISION_H_
    00025
    00026 #include <ode/common.h>
    00027 #include <ode/collision_space.h>
    00028 #include <ode/contact.h>
    00029
    00030 #ifdef __cplusplus
    00031 extern "C" {
    00032 #endif
    00033
    00049 /* ************************************************************************ */
    00050 /* general functions */
    00051
    00065 ODE_API void dGeomDestroy (dGeomID geom);
    00066
    00067
    00075 ODE_API void dGeomSetData (dGeomID geom, void* data);
    00076
    00077
    00084 ODE_API void *dGeomGetData (dGeomID geom);
    00085
    00086
    00105 ODE_API void dGeomSetBody (dGeomID geom, dBodyID body);
    00106
    00107
    00114 ODE_API dBodyID dGeomGetBody (dGeomID geom);
    00115
    00116
    00131 ODE_API void dGeomSetPosition (dGeomID geom, dReal x, dReal y, dReal z);
    00132
    00133
    00146 ODE_API void dGeomSetRotation (dGeomID geom, const dMatrix3 R);
    00147
    00148
    00162 ODE_API void dGeomSetQuaternion (dGeomID geom, const dQuaternion Q);
    00163
    00164
    00181 ODE_API const dReal * dGeomGetPosition (dGeomID geom);
    00182
    00183
    00191 ODE_API void dGeomCopyPosition (dGeomID geom, dVector3 pos);
    00192
    00193
    00210 ODE_API const dReal * dGeomGetRotation (dGeomID geom);
    00211
    00212
    00226 ODE_API void dGeomCopyRotation(dGeomID geom, dMatrix3 R);
    00227
    00228
    00242 ODE_API void dGeomGetQuaternion (dGeomID geom, dQuaternion result);
    00243
    00244
    00261 ODE_API void dGeomGetAABB (dGeomID geom, dReal aabb[6]);
    00262
    00263
    00270 ODE_API int dGeomIsSpace (dGeomID geom);
    00271
    00272
    00280 ODE_API dSpaceID dGeomGetSpace (dGeomID);
    00281
    00282
    00307 ODE_API int dGeomGetClass (dGeomID geom);
    00308
    00309
    00322 ODE_API void dGeomSetCategoryBits (dGeomID geom, unsigned long bits);
    00323
    00324
    00337 ODE_API void dGeomSetCollideBits (dGeomID geom, unsigned long bits);
    00338
    00339
    00348 ODE_API unsigned long dGeomGetCategoryBits (dGeomID);
    00349
    00350
    00359 ODE_API unsigned long dGeomGetCollideBits (dGeomID);
    00360
    00361
    00374 ODE_API void dGeomEnable (dGeomID geom);
    00375
    00376
    00389 ODE_API void dGeomDisable (dGeomID geom);
    00390
    00391
    00405 ODE_API int dGeomIsEnabled (dGeomID geom);
    00406
    00407 /* ************************************************************************ */
    00408 /* geom offset from body */
    00409
    00425 ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
    00426
    00427
    00441 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
    00442
    00443
    00457 ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
    00458
    00459
    00476 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
    00477
    00478
    00493 ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
    00494
    00495
    00510 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
    00511
    00512
    00526 ODE_API void dGeomClearOffset(dGeomID geom);
    00527
    00528
    00544 ODE_API int dGeomIsOffset(dGeomID geom);
    00545
    00546
    00560 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
    00561
    00562
    00573 ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos);
    00574
    00575
    00590 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
    00591
    00592
    00604 ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R);
    00605
    00606
    00617 ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
    00618
    00619
    00620 /* ************************************************************************ */
    00621 /* collision detection */
    00622
    00669 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
    00670          int skip);
    00671
    00699 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
    00700
    00701
    00736 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
    00737
    00738
    00739 /* ************************************************************************ */
    00740 /* standard classes */
    00741
    00742 /* the maximum number of user classes that are supported */
    00743 enum {
    00744   dMaxUserClasses = 4
    00745 };
    00746
    00747 /* class numbers - each geometry object needs a unique number */
    00748 enum {
    00749   dSphereClass = 0,
    00750   dBoxClass,
    00751   dCapsuleClass,
    00752   dCylinderClass,
    00753   dPlaneClass,
    00754   dRayClass,
    00755   dConvexClass,
    00756   dGeomTransformClass,
    00757   dTriMeshClass,
    00758   dHeightfieldClass,
    00759
    00760   dFirstSpaceClass,
    00761   dSimpleSpaceClass = dFirstSpaceClass,
    00762   dHashSpaceClass,
    00763   dQuadTreeSpaceClass,
    00764   dLastSpaceClass = dQuadTreeSpaceClass,
    00765
    00766   dFirstUserClass,
    00767   dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
    00768   dGeomNumClasses
    00769 };
    00770
    00771
    00791 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
    00792
    00793
    00803 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
    00804
    00805
    00814 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
    00815
    00816
    00831 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
    00832
    00833
    00834 //--> Convex Functions
    00835 ODE_API dGeomID dCreateConvex (dSpaceID space,
    00836                 dReal *_planes,
    00837                 unsigned int _planecount,
    00838                 dReal *_points,
    00839                 unsigned int _pointcount,unsigned int *_polygons);
    00840
    00841 ODE_API void dGeomSetConvex (dGeomID g,
    00842               dReal *_planes,
    00843               unsigned int _count,
    00844               dReal *_points,
    00845               unsigned int _pointcount,unsigned int *_polygons);
    00846 //<-- Convex Functions
    00847
    00869 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
    00870
    00871
    00883 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
    00884
    00885
    00895 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
    00896
    00897
    00910 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
    00911
    00912
    00913 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
    00914 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
    00915 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
    00916 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
    00917
    00918 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
    00919 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
    00920 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
    00921 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
    00922
    00923 // For now we want to have a backwards compatible C-API, note: C++ API is not.
    00924 #define dCreateCCylinder dCreateCapsule
    00925 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
    00926 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
    00927 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
    00928 #define dCCylinderClass dCapsuleClass
    00929
    00930 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
    00931 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
    00932 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
    00933
    00934 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
    00935 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
    00936 ODE_API dReal dGeomRayGetLength (dGeomID ray);
    00937 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
    00938         dReal dx, dReal dy, dReal dz);
    00939 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
    00940
    00941 /*
    00942  * Set/get ray flags that influence ray collision detection.
    00943  * These flags are currently only noticed by the trimesh collider, because
    00944  * they can make a major differences there.
    00945  */
    00946 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
    00947 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
    00948 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
    00949 ODE_API int dGeomRayGetClosestHit (dGeomID g);
    00950
    00951 #include "collision_trimesh.h"
    00952
    00953 ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
    00954 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
    00955 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
    00956 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
    00957 ODE_API int dGeomTransformGetCleanup (dGeomID g);
    00958 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
    00959 ODE_API int dGeomTransformGetInfo (dGeomID g);
    00960
    00961
    00962 /* ************************************************************************ */
    00963 /* heightfield functions */
    00964
    00965
    00966 // Data storage for heightfield data.
    00967 struct dxHeightfieldData;
    00968 typedef struct dxHeightfieldData* dHeightfieldDataID;
    00969
    00970
    00988 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
    00989
    00990
    00991
    01011 ODE_API dGeomID dCreateHeightfield( dSpaceID space,
    01012                dHeightfieldDataID data, int bPlaceable );
    01013
    01014
    01027 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate();
    01028
    01029
    01038 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
    01039
    01040
    01041
    01082 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
    01083             void* pUserData, dHeightfieldGetHeight* pCallback,
    01084             dReal width, dReal depth, int widthSamples, int depthSamples,
    01085             dReal scale, dReal offset, dReal thickness, int bWrap );
    01086
    01130 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
    01131             const unsigned char* pHeightData, int bCopyHeightData,
    01132             dReal width, dReal depth, int widthSamples, int depthSamples,
    01133             dReal scale, dReal offset, dReal thickness,  int bWrap );
    01134
    01178 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
    01179             const short* pHeightData, int bCopyHeightData,
    01180             dReal width, dReal depth, int widthSamples, int depthSamples,
    01181             dReal scale, dReal offset, dReal thickness, int bWrap );
    01182
    01228 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
    01229             const float* pHeightData, int bCopyHeightData,
    01230             dReal width, dReal depth, int widthSamples, int depthSamples,
    01231             dReal scale, dReal offset, dReal thickness, int bWrap );
    01232
    01278 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
    01279             const double* pHeightData, int bCopyHeightData,
    01280             dReal width, dReal depth, int widthSamples, int depthSamples,
    01281             dReal scale, dReal offset, dReal thickness, int bWrap );
    01282
    01300 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
    01301             dReal minHeight, dReal maxHeight );
    01302
    01303
    01314 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
    01315
    01316
    01326 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
    01327
    01328
    01329
    01330 /* ************************************************************************ */
    01331 /* utility functions */
    01332
    01333 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
    01334             const dVector3 b1, const dVector3 b2,
    01335             dVector3 cp1, dVector3 cp2);
    01336
    01337 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
    01338           const dVector3 side1, const dVector3 _p2,
    01339           const dMatrix3 R2, const dVector3 side2);
    01340
    01341 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
    01342         const dVector3 side1, const dVector3 p2,
    01343         const dMatrix3 R2, const dVector3 side2,
    01344         dVector3 normal, dReal *depth, int *return_code,
    01345         int maxc, dContactGeom *contact, int skip);
    01346
    01347 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
    01348 ODE_API void dInitODE(void);
    01349 ODE_API void dCloseODE(void);
    01350
    01351 /* ************************************************************************ */
    01352 /* custom classes */
    01353
    01354 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
    01355 typedef int dColliderFn (dGeomID o1, dGeomID o2,
    01356           int flags, dContactGeom *contact, int skip);
    01357 typedef dColliderFn * dGetColliderFnFn (int num);
    01358 typedef void dGeomDtorFn (dGeomID o);
    01359 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
    01360
    01361 typedef struct dGeomClass {
    01362   int bytes;
    01363   dGetColliderFnFn *collider;
    01364   dGetAABBFn *aabb;
    01365   dAABBTestFn *aabb_test;
    01366   dGeomDtorFn *dtor;
    01367 } dGeomClass;
    01368
    01369 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
    01370 ODE_API void * dGeomGetClassData (dGeomID);
    01371 ODE_API dGeomID dCreateGeom (int classnum);
    01372
    01373 /* ************************************************************************ */
    01374
    01375 #ifdef __cplusplus
    01376 }
    01377 #endif
    01378
    01379 #endif