|
Open Dynamics Engine
|
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 /* geom offset from body */ 00412 00428 ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z); 00429 00430 00444 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R); 00445 00446 00460 ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q); 00461 00462 00479 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z); 00480 00481 00496 ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R); 00497 00498 00513 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion); 00514 00515 00529 ODE_API void dGeomClearOffset(dGeomID geom); 00530 00531 00547 ODE_API int dGeomIsOffset(dGeomID geom); 00548 00549 00563 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom); 00564 00565 00576 ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos); 00577 00578 00593 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom); 00594 00595 00607 ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R); 00608 00609 00620 ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result); 00621 00622 00623 /* ************************************************************************ */ 00624 /* collision detection */ 00625 00626 /* 00627 * Just generate any contacts (disables any contact refining). 00628 */ 00629 #define CONTACTS_UNIMPORTANT 0x80000000 00630 00678 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact, 00679 int skip); 00680 00708 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback); 00709 00710 00751 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback); 00752 00753 00754 /* ************************************************************************ */ 00755 /* standard classes */ 00756 00757 /* the maximum number of user classes that are supported */ 00758 enum { 00759 dMaxUserClasses = 4 00760 }; 00761 00762 /* class numbers - each geometry object needs a unique number */ 00763 enum { 00764 dSphereClass = 0, 00765 dBoxClass, 00766 dCapsuleClass, 00767 dCylinderClass, 00768 dPlaneClass, 00769 dRayClass, 00770 dConvexClass, 00771 dGeomTransformClass, 00772 dTriMeshClass, 00773 dHeightfieldClass, 00774 00775 dFirstSpaceClass, 00776 dSimpleSpaceClass = dFirstSpaceClass, 00777 dHashSpaceClass, 00778 dSweepAndPruneSpaceClass, // SAP 00779 dQuadTreeSpaceClass, 00780 dLastSpaceClass = dQuadTreeSpaceClass, 00781 00782 dFirstUserClass, 00783 dLastUserClass = dFirstUserClass + dMaxUserClasses - 1, 00784 dGeomNumClasses 00785 }; 00786 00787 00807 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius); 00808 00809 00819 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius); 00820 00821 00830 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere); 00831 00832 00847 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z); 00848 00849 00850 //--> Convex Functions 00851 ODE_API dGeomID dCreateConvex (dSpaceID space, 00852 dReal *_planes, 00853 unsigned int _planecount, 00854 dReal *_points, 00855 unsigned int _pointcount,unsigned int *_polygons); 00856 00857 ODE_API void dGeomSetConvex (dGeomID g, 00858 dReal *_planes, 00859 unsigned int _count, 00860 dReal *_points, 00861 unsigned int _pointcount,unsigned int *_polygons); 00862 //<-- Convex Functions 00863 00885 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz); 00886 00887 00899 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz); 00900 00901 00911 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result); 00912 00913 00926 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z); 00927 00928 00929 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d); 00930 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d); 00931 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result); 00932 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z); 00933 00934 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length); 00935 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length); 00936 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length); 00937 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z); 00938 00939 // For now we want to have a backwards compatible C-API, note: C++ API is not. 00940 #define dCreateCCylinder dCreateCapsule 00941 #define dGeomCCylinderSetParams dGeomCapsuleSetParams 00942 #define dGeomCCylinderGetParams dGeomCapsuleGetParams 00943 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth 00944 #define dCCylinderClass dCapsuleClass 00945 00946 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length); 00947 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length); 00948 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length); 00949 00950 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length); 00951 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length); 00952 ODE_API dReal dGeomRayGetLength (dGeomID ray); 00953 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz, 00954 dReal dx, dReal dy, dReal dz); 00955 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir); 00956 00957 /* 00958 * Set/get ray flags that influence ray collision detection. 00959 * These flags are currently only noticed by the trimesh collider, because 00960 * they can make a major differences there. 00961 */ 00962 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull); 00963 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull); 00964 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit); 00965 ODE_API int dGeomRayGetClosestHit (dGeomID g); 00966 00967 #include "collision_trimesh.h" 00968 00969 ODE_API dGeomID dCreateGeomTransform (dSpaceID space); 00970 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj); 00971 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g); 00972 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode); 00973 ODE_API int dGeomTransformGetCleanup (dGeomID g); 00974 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode); 00975 ODE_API int dGeomTransformGetInfo (dGeomID g); 00976 00977 00978 /* ************************************************************************ */ 00979 /* heightfield functions */ 00980 00981 00982 // Data storage for heightfield data. 00983 struct dxHeightfieldData; 00984 typedef struct dxHeightfieldData* dHeightfieldDataID; 00985 00986 01004 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z ); 01005 01006 01007 01027 ODE_API dGeomID dCreateHeightfield( dSpaceID space, 01028 dHeightfieldDataID data, int bPlaceable ); 01029 01030 01043 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void); 01044 01045 01054 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d ); 01055 01056 01057 01098 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d, 01099 void* pUserData, dHeightfieldGetHeight* pCallback, 01100 dReal width, dReal depth, int widthSamples, int depthSamples, 01101 dReal scale, dReal offset, dReal thickness, int bWrap ); 01102 01146 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d, 01147 const unsigned char* pHeightData, int bCopyHeightData, 01148 dReal width, dReal depth, int widthSamples, int depthSamples, 01149 dReal scale, dReal offset, dReal thickness, int bWrap ); 01150 01194 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d, 01195 const short* pHeightData, int bCopyHeightData, 01196 dReal width, dReal depth, int widthSamples, int depthSamples, 01197 dReal scale, dReal offset, dReal thickness, int bWrap ); 01198 01244 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d, 01245 const float* pHeightData, int bCopyHeightData, 01246 dReal width, dReal depth, int widthSamples, int depthSamples, 01247 dReal scale, dReal offset, dReal thickness, int bWrap ); 01248 01294 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d, 01295 const double* pHeightData, int bCopyHeightData, 01296 dReal width, dReal depth, int widthSamples, int depthSamples, 01297 dReal scale, dReal offset, dReal thickness, int bWrap ); 01298 01316 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d, 01317 dReal minHeight, dReal maxHeight ); 01318 01319 01330 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d ); 01331 01332 01342 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g ); 01343 01344 01345 01346 /* ************************************************************************ */ 01347 /* utility functions */ 01348 01349 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2, 01350 const dVector3 b1, const dVector3 b2, 01351 dVector3 cp1, dVector3 cp2); 01352 01353 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1, 01354 const dVector3 side1, const dVector3 _p2, 01355 const dMatrix3 R2, const dVector3 side2); 01356 01357 // The meaning of flags parameter is the same as in dCollide() 01358 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1, 01359 const dVector3 side1, const dVector3 p2, 01360 const dMatrix3 R2, const dVector3 side2, 01361 dVector3 normal, dReal *depth, int *return_code, 01362 int flags, dContactGeom *contact, int skip); 01363 01364 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]); 01365 01366 01367 /* ************************************************************************ */ 01368 /* custom classes */ 01369 01370 typedef void dGetAABBFn (dGeomID, dReal aabb[6]); 01371 typedef int dColliderFn (dGeomID o1, dGeomID o2, 01372 int flags, dContactGeom *contact, int skip); 01373 typedef dColliderFn * dGetColliderFnFn (int num); 01374 typedef void dGeomDtorFn (dGeomID o); 01375 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]); 01376 01377 typedef struct dGeomClass { 01378 int bytes; 01379 dGetColliderFnFn *collider; 01380 dGetAABBFn *aabb; 01381 dAABBTestFn *aabb_test; 01382 dGeomDtorFn *dtor; 01383 } dGeomClass; 01384 01385 ODE_API int dCreateGeomClass (const dGeomClass *classptr); 01386 ODE_API void * dGeomGetClassData (dGeomID); 01387 ODE_API dGeomID dCreateGeom (int classnum); 01388 01397 ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn); 01398 01399 01400 /* ************************************************************************ */ 01401 01402 #ifdef __cplusplus 01403 } 01404 #endif 01405 01406 #endif
1.7.3