Open Dynamics Engine

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 // Include odeinit.h for backward compatibility as some of initialization APIs 
00030 // were initally declared in current header.
00031 #include <ode/odeinit.h>
00032 
00033 #ifdef __cplusplus
00034 extern "C" {
00035 #endif
00036 
00052 /* ************************************************************************ */
00053 /* general functions */
00054 
00068 ODE_API void dGeomDestroy (dGeomID geom);
00069 
00070 
00078 ODE_API void dGeomSetData (dGeomID geom, void* data);
00079 
00080 
00087 ODE_API void *dGeomGetData (dGeomID geom);
00088 
00089 
00108 ODE_API void dGeomSetBody (dGeomID geom, dBodyID body);
00109 
00110 
00117 ODE_API dBodyID dGeomGetBody (dGeomID geom);
00118 
00119 
00134 ODE_API void dGeomSetPosition (dGeomID geom, dReal x, dReal y, dReal z);
00135 
00136 
00149 ODE_API void dGeomSetRotation (dGeomID geom, const dMatrix3 R);
00150 
00151 
00165 ODE_API void dGeomSetQuaternion (dGeomID geom, const dQuaternion Q);
00166 
00167 
00184 ODE_API const dReal * dGeomGetPosition (dGeomID geom);
00185 
00186 
00194 ODE_API void dGeomCopyPosition (dGeomID geom, dVector3 pos);
00195 
00196 
00213 ODE_API const dReal * dGeomGetRotation (dGeomID geom);
00214 
00215 
00229 ODE_API void dGeomCopyRotation(dGeomID geom, dMatrix3 R);
00230 
00231 
00245 ODE_API void dGeomGetQuaternion (dGeomID geom, dQuaternion result);
00246 
00247 
00264 ODE_API void dGeomGetAABB (dGeomID geom, dReal aabb[6]);
00265 
00266 
00273 ODE_API int dGeomIsSpace (dGeomID geom);
00274 
00275 
00283 ODE_API dSpaceID dGeomGetSpace (dGeomID);
00284 
00285 
00310 ODE_API int dGeomGetClass (dGeomID geom);
00311 
00312 
00325 ODE_API void dGeomSetCategoryBits (dGeomID geom, unsigned long bits);
00326 
00327 
00340 ODE_API void dGeomSetCollideBits (dGeomID geom, unsigned long bits);
00341 
00342 
00351 ODE_API unsigned long dGeomGetCategoryBits (dGeomID);
00352 
00353 
00362 ODE_API unsigned long dGeomGetCollideBits (dGeomID);
00363 
00364 
00377 ODE_API void dGeomEnable (dGeomID geom);
00378 
00379 
00392 ODE_API void dGeomDisable (dGeomID geom);
00393 
00394 
00408 ODE_API int dGeomIsEnabled (dGeomID geom);
00409 
00410 
00411 enum
00412 {
00413    dGeomCommonControlClass = 0,
00414    dGeomColliderControlClass = 1
00415 };
00416 
00417 enum
00418 {
00419    dGeomCommonAnyControlCode = 0,
00420 
00421    dGeomColliderSetMergeSphereContactsControlCode = 1,
00422    dGeomColliderGetMergeSphereContactsControlCode = 2
00423 };
00424 
00425 enum
00426 {
00427    dGeomColliderMergeContactsValue__Default = 0, // Used with Set... to restore default value
00428    dGeomColliderMergeContactsValue_None = 1,
00429    dGeomColliderMergeContactsValue_Normals = 2,
00430    dGeomColliderMergeContactsValue_Full = 3
00431 };
00432 
00460 ODE_API int dGeomLowLevelControl (dGeomID geom, int controlClass, int controlCode, void *dataValue, int *dataSize);
00461 
00462 
00472 ODE_API void dGeomGetRelPointPos
00473 (
00474   dGeomID geom, dReal px, dReal py, dReal pz,
00475   dVector3 result
00476 );
00477 
00490 ODE_API void dGeomGetPosRelPoint
00491 (
00492   dGeomID geom, dReal px, dReal py, dReal pz,
00493   dVector3 result
00494 );
00495 
00505 ODE_API void dGeomVectorToWorld
00506 (
00507   dGeomID geom, dReal px, dReal py, dReal pz,
00508   dVector3 result
00509 );
00510 
00520 ODE_API void dGeomVectorFromWorld
00521 (
00522   dGeomID geom, dReal px, dReal py, dReal pz,
00523   dVector3 result
00524 );
00525 
00526 
00527 /* ************************************************************************ */
00528 /* geom offset from body */
00529 
00545 ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
00546 
00547 
00561 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
00562 
00563 
00577 ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
00578 
00579 
00596 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
00597 
00598 
00613 ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
00614 
00615 
00630 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
00631 
00632 
00646 ODE_API void dGeomClearOffset(dGeomID geom);
00647 
00648 
00664 ODE_API int dGeomIsOffset(dGeomID geom);
00665 
00666 
00680 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
00681 
00682 
00693 ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos);
00694 
00695 
00710 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
00711 
00712 
00724 ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R);
00725 
00726 
00737 ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
00738 
00739 
00740 /* ************************************************************************ */
00741 /* collision detection */
00742 
00743 /*
00744  * Just generate any contacts (disables any contact refining).
00745  */
00746 #define CONTACTS_UNIMPORTANT        0x80000000
00747 
00795 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
00796          int skip);
00797 
00825 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
00826 
00827 
00868 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
00869 
00870 
00871 /* ************************************************************************ */
00872 /* standard classes */
00873 
00874 /* the maximum number of user classes that are supported */
00875 enum {
00876   dMaxUserClasses = 4
00877 };
00878 
00879 /* class numbers - each geometry object needs a unique number */
00880 enum {
00881   dSphereClass = 0,
00882   dBoxClass,
00883   dCapsuleClass,
00884   dCylinderClass,
00885   dPlaneClass,
00886   dRayClass,
00887   dConvexClass,
00888   dGeomTransformClass,
00889   dTriMeshClass,
00890   dHeightfieldClass,
00891 
00892   dFirstSpaceClass,
00893   dSimpleSpaceClass = dFirstSpaceClass,
00894   dHashSpaceClass,
00895   dSweepAndPruneSpaceClass, // SAP
00896   dQuadTreeSpaceClass,
00897   dLastSpaceClass = dQuadTreeSpaceClass,
00898 
00899   dFirstUserClass,
00900   dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
00901   dGeomNumClasses
00902 };
00903 
00904 
00924 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
00925 
00926 
00936 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
00937 
00938 
00947 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
00948 
00949 
00964 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
00965 
00966 
00967 //--> Convex Functions
00968 ODE_API dGeomID dCreateConvex (dSpaceID space,
00969                 dReal *_planes,
00970                 unsigned int _planecount,
00971                 dReal *_points,
00972                 unsigned int _pointcount,unsigned int *_polygons);
00973 
00974 ODE_API void dGeomSetConvex (dGeomID g,
00975               dReal *_planes,
00976               unsigned int _count,
00977               dReal *_points,
00978               unsigned int _pointcount,unsigned int *_polygons);
00979 //<-- Convex Functions
00980 
01002 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
01003 
01004 
01016 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
01017 
01018 
01028 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
01029 
01030 
01043 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
01044 
01045 
01046 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
01047 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
01048 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
01049 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
01050 
01051 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
01052 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
01053 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
01054 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
01055 
01056 // For now we want to have a backwards compatible C-API, note: C++ API is not.
01057 #define dCreateCCylinder dCreateCapsule
01058 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
01059 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
01060 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
01061 #define dCCylinderClass dCapsuleClass
01062 
01063 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
01064 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
01065 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
01066 
01067 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
01068 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
01069 ODE_API dReal dGeomRayGetLength (dGeomID ray);
01070 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
01071         dReal dx, dReal dy, dReal dz);
01072 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
01073 
01074 /*
01075  * Set/get ray flags that influence ray collision detection.
01076  * These flags are currently only noticed by the trimesh collider, because
01077  * they can make a major differences there.
01078  */
01079 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
01080 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
01081 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
01082 ODE_API int dGeomRayGetClosestHit (dGeomID g);
01083 
01084 #include "collision_trimesh.h"
01085 
01086 ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
01087 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
01088 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
01089 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
01090 ODE_API int dGeomTransformGetCleanup (dGeomID g);
01091 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
01092 ODE_API int dGeomTransformGetInfo (dGeomID g);
01093 
01094 
01095 /* ************************************************************************ */
01096 /* heightfield functions */
01097 
01098 
01099 // Data storage for heightfield data.
01100 struct dxHeightfieldData;
01101 typedef struct dxHeightfieldData* dHeightfieldDataID;
01102 
01103 
01121 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
01122 
01123 
01124 
01144 ODE_API dGeomID dCreateHeightfield( dSpaceID space,
01145                dHeightfieldDataID data, int bPlaceable );
01146 
01147 
01160 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void);
01161 
01162 
01171 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
01172 
01173 
01174 
01215 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
01216             void* pUserData, dHeightfieldGetHeight* pCallback,
01217             dReal width, dReal depth, int widthSamples, int depthSamples,
01218             dReal scale, dReal offset, dReal thickness, int bWrap );
01219 
01263 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
01264             const unsigned char* pHeightData, int bCopyHeightData,
01265             dReal width, dReal depth, int widthSamples, int depthSamples,
01266             dReal scale, dReal offset, dReal thickness,  int bWrap );
01267 
01311 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
01312             const short* pHeightData, int bCopyHeightData,
01313             dReal width, dReal depth, int widthSamples, int depthSamples,
01314             dReal scale, dReal offset, dReal thickness, int bWrap );
01315 
01361 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
01362             const float* pHeightData, int bCopyHeightData,
01363             dReal width, dReal depth, int widthSamples, int depthSamples,
01364             dReal scale, dReal offset, dReal thickness, int bWrap );
01365 
01411 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
01412             const double* pHeightData, int bCopyHeightData,
01413             dReal width, dReal depth, int widthSamples, int depthSamples,
01414             dReal scale, dReal offset, dReal thickness, int bWrap );
01415 
01433 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
01434             dReal minHeight, dReal maxHeight );
01435 
01436 
01447 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
01448 
01449 
01459 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
01460 
01461 
01462 
01463 /* ************************************************************************ */
01464 /* utility functions */
01465 
01466 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
01467             const dVector3 b1, const dVector3 b2,
01468             dVector3 cp1, dVector3 cp2);
01469 
01470 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
01471           const dVector3 side1, const dVector3 _p2,
01472           const dMatrix3 R2, const dVector3 side2);
01473 
01474 // The meaning of flags parameter is the same as in dCollide()
01475 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
01476         const dVector3 side1, const dVector3 p2,
01477         const dMatrix3 R2, const dVector3 side2,
01478         dVector3 normal, dReal *depth, int *return_code,
01479         int flags, dContactGeom *contact, int skip);
01480 
01481 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
01482 
01483 
01484 /* ************************************************************************ */
01485 /* custom classes */
01486 
01487 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
01488 typedef int dColliderFn (dGeomID o1, dGeomID o2,
01489           int flags, dContactGeom *contact, int skip);
01490 typedef dColliderFn * dGetColliderFnFn (int num);
01491 typedef void dGeomDtorFn (dGeomID o);
01492 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
01493 
01494 typedef struct dGeomClass {
01495   int bytes;
01496   dGetColliderFnFn *collider;
01497   dGetAABBFn *aabb;
01498   dAABBTestFn *aabb_test;
01499   dGeomDtorFn *dtor;
01500 } dGeomClass;
01501 
01502 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
01503 ODE_API void * dGeomGetClassData (dGeomID);
01504 ODE_API dGeomID dCreateGeom (int classnum);
01505 
01514 ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn);
01515 
01516 
01517 /* ************************************************************************ */
01518 
01519 #ifdef __cplusplus
01520 }
01521 #endif
01522 
01523 #endif