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 
00384 ODE_API void dGeomSetOffsetPosition (dGeomID, dReal x, dReal y, dReal z);
00385 ODE_API void dGeomSetOffsetRotation (dGeomID, const dMatrix3 R);
00386 ODE_API void dGeomSetOffsetQuaternion (dGeomID, const dQuaternion);
00387 ODE_API void dGeomSetOffsetWorldPosition (dGeomID, dReal x, dReal y, dReal z);
00388 ODE_API void dGeomSetOffsetWorldRotation (dGeomID, const dMatrix3 R);
00389 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID, const dQuaternion);
00390 ODE_API void dGeomClearOffset(dGeomID);
00391 ODE_API int dGeomIsOffset(dGeomID);
00392 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID);
00393 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID);
00394 ODE_API void dGeomGetOffsetQuaternion (dGeomID, dQuaternion result);
00395 
00396 /* ************************************************************************ */
00397 /* collision detection */
00398 
00399 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
00400          int skip);
00401 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
00402 ODE_API void dSpaceCollide2 (dGeomID o1, dGeomID o2, void *data,
00403            dNearCallback *callback);
00404 
00405 /* ************************************************************************ */
00406 /* standard classes */
00407 
00408 /* the maximum number of user classes that are supported */
00409 enum {
00410   dMaxUserClasses = 4
00411 };
00412 
00413 /* class numbers - each geometry object needs a unique number */
00414 enum {
00415   dSphereClass = 0,
00416   dBoxClass,
00417   dCapsuleClass,
00418   dCylinderClass,
00419   dPlaneClass,
00420   dRayClass,
00421   dConvexClass,
00422   dGeomTransformClass,
00423   dTriMeshClass,
00424 
00425   dFirstSpaceClass,
00426   dSimpleSpaceClass = dFirstSpaceClass,
00427   dHashSpaceClass,
00428   dQuadTreeSpaceClass,
00429   dLastSpaceClass = dQuadTreeSpaceClass,
00430 
00431   dFirstUserClass,
00432   dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
00433   dGeomNumClasses
00434 };
00435 
00436 
00437 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
00438 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
00439 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
00440 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
00441 
00442 //--> Convex Functions
00443 ODE_API dGeomID dCreateConvex (dSpaceID space,
00444                 dReal *_planes,
00445                 unsigned int _planecount,
00446                 dReal *_points,
00447                 unsigned int _pointcount,unsigned int *_polygons);
00448   
00449 ODE_API void dGeomSetConvex (dGeomID g,
00450               dReal *_planes,
00451               unsigned int _count,
00452               dReal *_points,
00453               unsigned int _pointcount,unsigned int *_polygons);
00454 //<-- Convex Functions
00455 
00456 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
00457 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
00458 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
00459 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
00460 
00461 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
00462 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
00463 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
00464 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
00465 
00466 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
00467 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
00468 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
00469 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
00470 
00471 // For now we want to have a backwards compatible C-API, note: C++ API is not.
00472 #define dCreateCCylinder dCreateCapsule
00473 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
00474 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
00475 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
00476 #define dCCylinderClass dCapsuleClass
00477 
00478 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
00479 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
00480 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
00481 
00482 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
00483 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
00484 ODE_API dReal dGeomRayGetLength (dGeomID ray);
00485 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
00486         dReal dx, dReal dy, dReal dz);
00487 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
00488 
00489 /*
00490  * Set/get ray flags that influence ray collision detection.
00491  * These flags are currently only noticed by the trimesh collider, because
00492  * they can make a major differences there.
00493  */
00494 ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
00495 ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
00496 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
00497 ODE_API int dGeomRayGetClosestHit (dGeomID g);
00498 
00499 #include "collision_trimesh.h"
00500 
00501 ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
00502 ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
00503 ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
00504 ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
00505 ODE_API int dGeomTransformGetCleanup (dGeomID g);
00506 ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
00507 ODE_API int dGeomTransformGetInfo (dGeomID g);
00508 
00509 /* ************************************************************************ */
00510 /* utility functions */
00511 
00512 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
00513             const dVector3 b1, const dVector3 b2,
00514             dVector3 cp1, dVector3 cp2);
00515 
00516 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
00517           const dVector3 side1, const dVector3 _p2,
00518           const dMatrix3 R2, const dVector3 side2);
00519 
00520 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
00521         const dVector3 side1, const dVector3 p2,
00522         const dMatrix3 R2, const dVector3 side2,
00523         dVector3 normal, dReal *depth, int *return_code,
00524         int maxc, dContactGeom *contact, int skip);
00525 
00526 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
00527 ODE_API void dCloseODE(void);
00528 
00529 /* ************************************************************************ */
00530 /* custom classes */
00531 
00532 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
00533 typedef int dColliderFn (dGeomID o1, dGeomID o2,
00534           int flags, dContactGeom *contact, int skip);
00535 typedef dColliderFn * dGetColliderFnFn (int num);
00536 typedef void dGeomDtorFn (dGeomID o);
00537 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
00538 
00539 typedef struct dGeomClass {
00540   int bytes;
00541   dGetColliderFnFn *collider;
00542   dGetAABBFn *aabb;
00543   dAABBTestFn *aabb_test;
00544   dGeomDtorFn *dtor;
00545 } dGeomClass;
00546 
00547 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
00548 ODE_API void * dGeomGetClassData (dGeomID);
00549 ODE_API dGeomID dCreateGeom (int classnum);
00550 
00551 /* ************************************************************************ */
00552 
00553 #ifdef __cplusplus
00554 }
00555 #endif
00556 
00557 #endif

Generated on Sun Jun 4 09:55:41 2006 for Open Dynamics Engine by  doxygen 1.4.6