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 
00200 ODE_API const dReal * dGeomGetRotation (dGeomID geom);
00201 
00202 
00216 ODE_API void dGeomGetQuaternion (dGeomID geom, dQuaternion result);
00217 
00218 
00235 ODE_API void dGeomGetAABB (dGeomID geom, dReal aabb[6]);
00236 
00237 
00244 ODE_API int dGeomIsSpace (dGeomID geom);
00245 
00246 
00254 ODE_API dSpaceID dGeomGetSpace (dGeomID);
00255 
00256 
00281 ODE_API int dGeomGetClass (dGeomID geom);
00282 
00283 
00296 ODE_API void dGeomSetCategoryBits (dGeomID geom, unsigned long bits);
00297 
00298 
00311 ODE_API void dGeomSetCollideBits (dGeomID geom, unsigned long bits);
00312 
00313 
00322 ODE_API unsigned long dGeomGetCategoryBits (dGeomID);
00323 
00324 
00333 ODE_API unsigned long dGeomGetCollideBits (dGeomID);
00334 
00335 
00348 ODE_API void dGeomEnable (dGeomID geom);
00349 
00350 
00363 ODE_API void dGeomDisable (dGeomID geom);
00364 
00365 
00379 ODE_API int dGeomIsEnabled (dGeomID geom);
00380 
00381 /* ************************************************************************ */
00382 /* geom offset from body */
00383 
00399 ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
00400 
00401 
00415 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
00416 
00417 
00431 ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
00432 
00433 
00450 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
00451 
00452 
00467 ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
00468 
00469 
00484 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
00485 
00486 
00500 ODE_API void dGeomClearOffset(dGeomID geom);
00501 
00502 
00518 ODE_API int dGeomIsOffset(dGeomID geom);
00519 
00520 
00534 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
00535 
00536 
00550 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
00551 
00552 
00563 ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
00564 
00565 /* ************************************************************************ */
00566 /* collision detection */
00567 
00614 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
00615          int skip);
00616 
00644 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
00645 
00646 
00681 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
00682 
00683 
00684 /* ************************************************************************ */
00685 /* standard classes */
00686 
00687 /* the maximum number of user classes that are supported */
00688 enum {
00689   dMaxUserClasses = 4
00690 };
00691 
00692 /* class numbers - each geometry object needs a unique number */
00693 enum {
00694   dSphereClass = 0,
00695   dBoxClass,
00696   dCapsuleClass,
00697   dCylinderClass,
00698   dPlaneClass,
00699   dRayClass,
00700   dConvexClass,
00701   dGeomTransformClass,
00702   dTriMeshClass,
00703   dHeightfieldClass,
00704 
00705   dFirstSpaceClass,
00706   dSimpleSpaceClass = dFirstSpaceClass,
00707   dHashSpaceClass,
00708   dQuadTreeSpaceClass,
00709   dLastSpaceClass = dQuadTreeSpaceClass,
00710 
00711   dFirstUserClass,
00712   dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
00713   dGeomNumClasses
00714 };
00715 
00716 
00736 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
00737 
00738 
00748 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
00749 
00750 
00759 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
00760 
00761 
00776 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
00777 
00778 
00779 //--> Convex Functions
00780 ODE_API dGeomID dCreateConvex (dSpaceID space,
00781                 dReal *_planes,
00782                 unsigned int _planecount,
00783                 dReal *_points,
00784                 unsigned int _pointcount,unsigned int *_polygons);
00785 
00786 ODE_API void dGeomSetConvex (dGeomID g,
00787               dReal *_planes,
00788               unsigned int _count,
00789               dReal *_points,
00790               unsigned int _pointcount,unsigned int *_polygons);
00791 //<-- Convex Functions
00792 
00814 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
00815 
00816 
00828 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
00829 
00830 
00840 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
00841 
00842 
00855 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
00856 
00857 
00858 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
00859 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
00860 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
00861 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
00862 
00863 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
00864 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
00865 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
00866 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
00867 
00868 // For now we want to have a backwards compatible C-API, note: C++ API is not.
00869 #define dCreateCCylinder dCreateCapsule
00870 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
00871 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
00872 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
00873 #define dCCylinderClass dCapsuleClass
00874 
00875 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
00876 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
00877 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
00878 
00879 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
00880 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
00881 ODE_API dReal dGeomRayGetLength (dGeomID ray);
00882 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
00883         dReal dx, dReal dy, dReal dz);
00884 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
00885 
00886 /*
00887  * Set/get ray flags that influence ray collision detection.
00888  * These flags are currently only noticed by the trimesh collider, because
00889  * they can make a major differences there.
00890  */
00891 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
00892 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
00893 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
00894 ODE_API int dGeomRayGetClosestHit (dGeomID g);
00895 
00896 #include "collision_trimesh.h"
00897 
00898 ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
00899 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
00900 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
00901 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
00902 ODE_API int dGeomTransformGetCleanup (dGeomID g);
00903 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
00904 ODE_API int dGeomTransformGetInfo (dGeomID g);
00905 
00906 
00907 /* ************************************************************************ */
00908 /* heightfield functions */
00909 
00910 
00911 // Data storage for heightfield data.
00912 struct dxHeightfieldData;
00913 typedef struct dxHeightfieldData* dHeightfieldDataID;
00914 
00915 
00933 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
00934 
00935 
00936 
00956 ODE_API dGeomID dCreateHeightfield( dSpaceID space,
00957                dHeightfieldDataID data, int bPlaceable );
00958 
00959 
00972 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate();
00973 
00974 
00983 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
00984 
00985 
00986 
01027 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
01028             void* pUserData, dHeightfieldGetHeight* pCallback,
01029             dReal width, dReal depth, int widthSamples, int depthSamples,
01030             dReal scale, dReal offset, dReal thickness, int bWrap );
01031 
01075 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
01076             const unsigned char* pHeightData, int bCopyHeightData,
01077             dReal width, dReal depth, int widthSamples, int depthSamples,
01078             dReal scale, dReal offset, dReal thickness,  int bWrap );
01079 
01123 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
01124             const short* pHeightData, int bCopyHeightData,
01125             dReal width, dReal depth, int widthSamples, int depthSamples,
01126             dReal scale, dReal offset, dReal thickness, int bWrap );
01127 
01173 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
01174             const float* pHeightData, int bCopyHeightData,
01175             dReal width, dReal depth, int widthSamples, int depthSamples,
01176             dReal scale, dReal offset, dReal thickness, int bWrap );
01177 
01223 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
01224             const double* pHeightData, int bCopyHeightData,
01225             dReal width, dReal depth, int widthSamples, int depthSamples,
01226             dReal scale, dReal offset, dReal thickness, int bWrap );
01227 
01245 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
01246             dReal minHeight, dReal maxHeight );
01247 
01248 
01259 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
01260 
01261 
01271 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
01272 
01273 
01274 
01275 /* ************************************************************************ */
01276 /* utility functions */
01277 
01278 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
01279             const dVector3 b1, const dVector3 b2,
01280             dVector3 cp1, dVector3 cp2);
01281 
01282 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
01283           const dVector3 side1, const dVector3 _p2,
01284           const dMatrix3 R2, const dVector3 side2);
01285 
01286 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
01287         const dVector3 side1, const dVector3 p2,
01288         const dMatrix3 R2, const dVector3 side2,
01289         dVector3 normal, dReal *depth, int *return_code,
01290         int maxc, dContactGeom *contact, int skip);
01291 
01292 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
01293 ODE_API void dCloseODE(void);
01294 
01295 /* ************************************************************************ */
01296 /* custom classes */
01297 
01298 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
01299 typedef int dColliderFn (dGeomID o1, dGeomID o2,
01300           int flags, dContactGeom *contact, int skip);
01301 typedef dColliderFn * dGetColliderFnFn (int num);
01302 typedef void dGeomDtorFn (dGeomID o);
01303 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
01304 
01305 typedef struct dGeomClass {
01306   int bytes;
01307   dGetColliderFnFn *collider;
01308   dGetAABBFn *aabb;
01309   dAABBTestFn *aabb_test;
01310   dGeomDtorFn *dtor;
01311 } dGeomClass;
01312 
01313 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
01314 ODE_API void * dGeomGetClassData (dGeomID);
01315 ODE_API dGeomID dCreateGeom (int classnum);
01316 
01317 /* ************************************************************************ */
01318 
01319 #ifdef __cplusplus
01320 }
01321 #endif
01322 
01323 #endif

Generated on Fri Sep 8 21:34:08 2006 for Open Dynamics Engine by  doxygen 1.4.6