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 
00668 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
00669          int skip);
00670 
00698 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
00699 
00700 
00735 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
00736 
00737 
00738 /* ************************************************************************ */
00739 /* standard classes */
00740 
00741 /* the maximum number of user classes that are supported */
00742 enum {
00743   dMaxUserClasses = 4
00744 };
00745 
00746 /* class numbers - each geometry object needs a unique number */
00747 enum {
00748   dSphereClass = 0,
00749   dBoxClass,
00750   dCapsuleClass,
00751   dCylinderClass,
00752   dPlaneClass,
00753   dRayClass,
00754   dConvexClass,
00755   dGeomTransformClass,
00756   dTriMeshClass,
00757   dHeightfieldClass,
00758 
00759   dFirstSpaceClass,
00760   dSimpleSpaceClass = dFirstSpaceClass,
00761   dHashSpaceClass,
00762   dQuadTreeSpaceClass,
00763   dLastSpaceClass = dQuadTreeSpaceClass,
00764 
00765   dFirstUserClass,
00766   dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
00767   dGeomNumClasses
00768 };
00769 
00770 
00790 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
00791 
00792 
00802 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
00803 
00804 
00813 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
00814 
00815 
00830 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
00831 
00832 
00833 //--> Convex Functions
00834 ODE_API dGeomID dCreateConvex (dSpaceID space,
00835                 dReal *_planes,
00836                 unsigned int _planecount,
00837                 dReal *_points,
00838                 unsigned int _pointcount,unsigned int *_polygons);
00839 
00840 ODE_API void dGeomSetConvex (dGeomID g,
00841               dReal *_planes,
00842               unsigned int _count,
00843               dReal *_points,
00844               unsigned int _pointcount,unsigned int *_polygons);
00845 //<-- Convex Functions
00846 
00868 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
00869 
00870 
00882 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
00883 
00884 
00894 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
00895 
00896 
00909 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
00910 
00911 
00912 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
00913 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
00914 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
00915 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
00916 
00917 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
00918 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
00919 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
00920 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
00921 
00922 // For now we want to have a backwards compatible C-API, note: C++ API is not.
00923 #define dCreateCCylinder dCreateCapsule
00924 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
00925 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
00926 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
00927 #define dCCylinderClass dCapsuleClass
00928 
00929 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
00930 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
00931 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
00932 
00933 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
00934 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
00935 ODE_API dReal dGeomRayGetLength (dGeomID ray);
00936 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
00937         dReal dx, dReal dy, dReal dz);
00938 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
00939 
00940 /*
00941  * Set/get ray flags that influence ray collision detection.
00942  * These flags are currently only noticed by the trimesh collider, because
00943  * they can make a major differences there.
00944  */
00945 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
00946 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
00947 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
00948 ODE_API int dGeomRayGetClosestHit (dGeomID g);
00949 
00950 #include "collision_trimesh.h"
00951 
00952 ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
00953 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
00954 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
00955 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
00956 ODE_API int dGeomTransformGetCleanup (dGeomID g);
00957 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
00958 ODE_API int dGeomTransformGetInfo (dGeomID g);
00959 
00960 
00961 /* ************************************************************************ */
00962 /* heightfield functions */
00963 
00964 
00965 // Data storage for heightfield data.
00966 struct dxHeightfieldData;
00967 typedef struct dxHeightfieldData* dHeightfieldDataID;
00968 
00969 
00987 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
00988 
00989 
00990 
01010 ODE_API dGeomID dCreateHeightfield( dSpaceID space,
01011                dHeightfieldDataID data, int bPlaceable );
01012 
01013 
01026 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate();
01027 
01028 
01037 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
01038 
01039 
01040 
01081 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
01082             void* pUserData, dHeightfieldGetHeight* pCallback,
01083             dReal width, dReal depth, int widthSamples, int depthSamples,
01084             dReal scale, dReal offset, dReal thickness, int bWrap );
01085 
01129 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
01130             const unsigned char* pHeightData, int bCopyHeightData,
01131             dReal width, dReal depth, int widthSamples, int depthSamples,
01132             dReal scale, dReal offset, dReal thickness,  int bWrap );
01133 
01177 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
01178             const short* pHeightData, int bCopyHeightData,
01179             dReal width, dReal depth, int widthSamples, int depthSamples,
01180             dReal scale, dReal offset, dReal thickness, int bWrap );
01181 
01227 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
01228             const float* pHeightData, int bCopyHeightData,
01229             dReal width, dReal depth, int widthSamples, int depthSamples,
01230             dReal scale, dReal offset, dReal thickness, int bWrap );
01231 
01277 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
01278             const double* pHeightData, int bCopyHeightData,
01279             dReal width, dReal depth, int widthSamples, int depthSamples,
01280             dReal scale, dReal offset, dReal thickness, int bWrap );
01281 
01299 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
01300             dReal minHeight, dReal maxHeight );
01301 
01302 
01313 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
01314 
01315 
01325 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
01326 
01327 
01328 
01329 /* ************************************************************************ */
01330 /* utility functions */
01331 
01332 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
01333             const dVector3 b1, const dVector3 b2,
01334             dVector3 cp1, dVector3 cp2);
01335 
01336 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
01337           const dVector3 side1, const dVector3 _p2,
01338           const dMatrix3 R2, const dVector3 side2);
01339 
01340 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
01341         const dVector3 side1, const dVector3 p2,
01342         const dMatrix3 R2, const dVector3 side2,
01343         dVector3 normal, dReal *depth, int *return_code,
01344         int maxc, dContactGeom *contact, int skip);
01345 
01346 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
01347 ODE_API void dInitODE(void);
01348 ODE_API void dCloseODE(void);
01349 
01350 /* ************************************************************************ */
01351 /* custom classes */
01352 
01353 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
01354 typedef int dColliderFn (dGeomID o1, dGeomID o2,
01355           int flags, dContactGeom *contact, int skip);
01356 typedef dColliderFn * dGetColliderFnFn (int num);
01357 typedef void dGeomDtorFn (dGeomID o);
01358 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
01359 
01360 typedef struct dGeomClass {
01361   int bytes;
01362   dGetColliderFnFn *collider;
01363   dGetAABBFn *aabb;
01364   dAABBTestFn *aabb_test;
01365   dGeomDtorFn *dtor;
01366 } dGeomClass;
01367 
01368 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
01369 ODE_API void * dGeomGetClassData (dGeomID);
01370 ODE_API dGeomID dCreateGeom (int classnum);
01371 
01372 /* ************************************************************************ */
01373 
01374 #ifdef __cplusplus
01375 }
01376 #endif
01377 
01378 #endif

Generated on Tue Sep 4 10:05:19 2007 for Open Dynamics Engine by  doxygen 1.5.3