1 /*************************************************************************
3 * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
4 * All rights reserved. Email: russ@q12.org Web: www.q12.org *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of EITHER: *
8 * (1) The GNU Lesser General Public License as published by the Free *
9 * Software Foundation; either version 2.1 of the License, or (at *
10 * your option) any later version. The text of the GNU Lesser *
11 * General Public License is included with this library in the *
13 * (2) The BSD-style license that is included with this library in *
14 * the file LICENSE-BSD.TXT. *
16 * This library is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
19 * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
21 *************************************************************************/
23 #ifndef _ODE_COLLISION_H_
24 #define _ODE_COLLISION_H_
26 #include <ode/common.h>
27 #include <ode/collision_space.h>
28 #include <ode/contact.h>
35 * @defgroup collide Collision Detection
37 * ODE has two main components: a dynamics simulation engine and a collision
38 * detection engine. The collision engine is given information about the
39 * shape of each body. At each time step it figures out which bodies touch
40 * each other and passes the resulting contact point information to the user.
41 * The user in turn creates contact joints between bodies.
43 * Using ODE's collision detection is optional - an alternative collision
44 * detection system can be used as long as it can supply the right kinds of
45 * contact information.
49 /* ************************************************************************ */
50 /* general functions */
53 * @brief Destroy a geom, removing it from any space.
55 * Destroy a geom, removing it from any space it is in first. This one
56 * function destroys a geom of any type, but to create a geom you must call
57 * a creation function for that type.
59 * When a space is destroyed, if its cleanup mode is 1 (the default) then all
60 * the geoms in that space are automatically destroyed as well.
62 * @param geom the geom to be destroyed.
65 ODE_API void dGeomDestroy (dGeomID geom);
69 * @brief Set the user-defined data pointer stored in the geom.
71 * @param geom the geom to hold the data
72 * @param data the data pointer to be stored
75 ODE_API void dGeomSetData (dGeomID geom, void* data);
79 * @brief Get the user-defined data pointer stored in the geom.
81 * @param geom the geom containing the data
84 ODE_API void *dGeomGetData (dGeomID geom);
88 * @brief Set the body associated with a placeable geom.
90 * Setting a body on a geom automatically combines the position vector and
91 * rotation matrix of the body and geom, so that setting the position or
92 * orientation of one will set the value for both objects. Setting a body
93 * ID of zero gives the geom its own position and rotation, independent
94 * from any body. If the geom was previously connected to a body then its
95 * new independent position/rotation is set to the current position/rotation
98 * Calling these functions on a non-placeable geom results in a runtime
99 * error in the debug build of ODE.
101 * @param geom the geom to connect
102 * @param body the body to attach to the geom
105 ODE_API void dGeomSetBody (dGeomID geom, dBodyID body);
109 * @brief Get the body associated with a placeable geom.
110 * @param geom the geom to query.
114 ODE_API dBodyID dGeomGetBody (dGeomID geom);
118 * @brief Set the position vector of a placeable geom.
120 * If the geom is attached to a body, the body's position will also be changed.
121 * Calling this function on a non-placeable geom results in a runtime error in
122 * the debug build of ODE.
124 * @param geom the geom to set.
125 * @param x the new X coordinate.
126 * @param y the new Y coordinate.
127 * @param z the new Z coordinate.
128 * @sa dBodySetPosition
131 ODE_API void dGeomSetPosition (dGeomID geom, dReal x, dReal y, dReal z);
135 * @brief Set the rotation matrix of a placeable geom.
137 * If the geom is attached to a body, the body's rotation will also be changed.
138 * Calling this function on a non-placeable geom results in a runtime error in
139 * the debug build of ODE.
141 * @param geom the geom to set.
142 * @param R the new rotation matrix.
143 * @sa dBodySetRotation
146 ODE_API void dGeomSetRotation (dGeomID geom, const dMatrix3 R);
150 * @brief Set the rotation of a placeable geom.
152 * If the geom is attached to a body, the body's rotation will also be changed.
154 * Calling this function on a non-placeable geom results in a runtime error in
155 * the debug build of ODE.
157 * @param geom the geom to set.
158 * @param Q the new rotation.
159 * @sa dBodySetQuaternion
162 ODE_API void dGeomSetQuaternion (dGeomID geom, const dQuaternion Q);
166 * @brief Get the position vector of a placeable geom.
168 * If the geom is attached to a body, the body's position will be returned.
170 * Calling this function on a non-placeable geom results in a runtime error in
171 * the debug build of ODE.
173 * @param geom the geom to query.
174 * @returns A pointer to the geom's position vector.
175 * @remarks The returned value is a pointer to the geom's internal
176 * data structure. It is valid until any changes are made
178 * @sa dBodyGetPosition
181 ODE_API const dReal * dGeomGetPosition (dGeomID geom);
185 * @brief Copy the position of a geom into a vector.
187 * @param geom the geom to query
188 * @param pos a copy of the geom position
189 * @sa dGeomGetPosition
191 ODE_API void dGeomCopyPosition (dGeomID geom, dVector3 pos);
195 * @brief Get the rotation matrix of a placeable geom.
197 * If the geom is attached to a body, the body's rotation will be returned.
199 * Calling this function on a non-placeable geom results in a runtime error in
200 * the debug build of ODE.
202 * @param geom the geom to query.
203 * @returns A pointer to the geom's rotation matrix.
204 * @remarks The returned value is a pointer to the geom's internal
205 * data structure. It is valid until any changes are made
207 * @sa dBodyGetRotation
210 ODE_API const dReal * dGeomGetRotation (dGeomID geom);
214 * @brief Get the rotation matrix of a placeable geom.
216 * If the geom is attached to a body, the body's rotation will be returned.
218 * Calling this function on a non-placeable geom results in a runtime error in
219 * the debug build of ODE.
221 * @param geom the geom to query.
222 * @param R a copy of the geom rotation
223 * @sa dGeomGetRotation
226 ODE_API void dGeomCopyRotation(dGeomID geom, dMatrix3 R);
230 * @brief Get the rotation quaternion of a placeable geom.
232 * If the geom is attached to a body, the body's quaternion will be returned.
234 * Calling this function on a non-placeable geom results in a runtime error in
235 * the debug build of ODE.
237 * @param geom the geom to query.
238 * @param result a copy of the rotation quaternion.
239 * @sa dBodyGetQuaternion
242 ODE_API void dGeomGetQuaternion (dGeomID geom, dQuaternion result);
246 * @brief Return the axis-aligned bounding box.
248 * Return in aabb an axis aligned bounding box that surrounds the given geom.
249 * The aabb array has elements (minx, maxx, miny, maxy, minz, maxz). If the
250 * geom is a space, a bounding box that surrounds all contained geoms is
253 * This function may return a pre-computed cached bounding box, if it can
254 * determine that the geom has not moved since the last time the bounding
257 * @param geom the geom to query
258 * @param aabb the returned bounding box
261 ODE_API void dGeomGetAABB (dGeomID geom, dReal aabb[6]);
265 * @brief Determing if a geom is a space.
266 * @param geom the geom to query
267 * @returns Non-zero if the geom is a space, zero otherwise.
270 ODE_API int dGeomIsSpace (dGeomID geom);
274 * @brief Query for the space containing a particular geom.
275 * @param geom the geom to query
276 * @returns The space that contains the geom, or NULL if the geom is
277 * not contained by a space.
280 ODE_API dSpaceID dGeomGetSpace (dGeomID);
284 * @brief Given a geom, this returns its class.
286 * The ODE classes are:
293 * @li dGeomTransformClass
295 * @li dSimpleSpaceClass
296 * @li dHashSpaceClass
297 * @li dQuadTreeSpaceClass
298 * @li dFirstUserClass
301 * User-defined class will return their own number.
303 * @param geom the geom to query
304 * @returns The geom class ID.
307 ODE_API int dGeomGetClass (dGeomID geom);
311 * @brief Set the "category" bitfield for the given geom.
313 * The category bitfield is used by spaces to govern which geoms will
314 * interact with each other. The bitfield is guaranteed to be at least
315 * 32 bits wide. The default category values for newly created geoms
318 * @param geom the geom to set
319 * @param bits the new bitfield value
322 ODE_API void dGeomSetCategoryBits (dGeomID geom, unsigned long bits);
326 * @brief Set the "collide" bitfield for the given geom.
328 * The collide bitfield is used by spaces to govern which geoms will
329 * interact with each other. The bitfield is guaranteed to be at least
330 * 32 bits wide. The default category values for newly created geoms
333 * @param geom the geom to set
334 * @param bits the new bitfield value
337 ODE_API void dGeomSetCollideBits (dGeomID geom, unsigned long bits);
341 * @brief Get the "category" bitfield for the given geom.
343 * @param geom the geom to set
344 * @param bits the new bitfield value
345 * @sa dGeomSetCategoryBits
348 ODE_API unsigned long dGeomGetCategoryBits (dGeomID);
352 * @brief Get the "collide" bitfield for the given geom.
354 * @param geom the geom to set
355 * @param bits the new bitfield value
356 * @sa dGeomSetCollideBits
359 ODE_API unsigned long dGeomGetCollideBits (dGeomID);
363 * @brief Enable a geom.
365 * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
366 * although they can still be members of a space. New geoms are created in
369 * @param geom the geom to enable
374 ODE_API void dGeomEnable (dGeomID geom);
378 * @brief Disable a geom.
380 * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
381 * although they can still be members of a space. New geoms are created in
384 * @param geom the geom to disable
389 ODE_API void dGeomDisable (dGeomID geom);
393 * @brief Check to see if a geom is enabled.
395 * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
396 * although they can still be members of a space. New geoms are created in
399 * @param geom the geom to query
400 * @returns Non-zero if the geom is enabled, zero otherwise.
405 ODE_API int dGeomIsEnabled (dGeomID geom);
410 dGeomCommonControlClass = 0,
411 dGeomColliderControlClass = 1
416 dGeomCommonAnyControlCode = 0,
418 dGeomColliderSetMergeSphereContactsControlCode = 1,
419 dGeomColliderGetMergeSphereContactsControlCode = 2
424 dGeomColliderMergeContactsValue__Default = 0, /* Used with Set... to restore default value*/
425 dGeomColliderMergeContactsValue_None = 1,
426 dGeomColliderMergeContactsValue_Normals = 2,
427 dGeomColliderMergeContactsValue_Full = 3
431 * @brief Execute low level control operation for geometry.
433 * The variable the dataSize points to must be initialized before the call.
434 * If the size does not match the one expected for the control class/code function
435 * changes it to the size expected and returns failure. This implies the function
436 * can be called with NULL data and zero size to test if control class/code is supported
437 * and obtain required data size for it.
439 * dGeomCommonAnyControlCode applies to any control class and returns success if
440 * at least one control code is available for the given class with given geom.
442 * Currently there are the folliwing control classes supported:
443 * @li dGeomColliderControlClass
445 * For dGeomColliderControlClass there are the following codes available:
446 * @li dGeomColliderSetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
447 * @li dGeomColliderGetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
449 * @param geom the geom to control
450 * @param controlClass the control class
451 * @param controlCode the control code for the class
452 * @param dataValue the control argument pointer
453 * @param dataSize the control argument size provided or expected
454 * @returns Boolean execution status
457 ODE_API int dGeomLowLevelControl (dGeomID geom, int controlClass, int controlCode, void *dataValue, int *dataSize);
461 * @brief Get world position of a relative point on geom.
463 * Calling this function on a non-placeable geom results in the same point being
467 * @param result will contain the result.
469 ODE_API void dGeomGetRelPointPos
471 dGeomID geom, dReal px, dReal py, dReal pz,
476 * @brief takes a point in global coordinates and returns
477 * the point's position in geom-relative coordinates.
479 * Calling this function on a non-placeable geom results in the same point being
483 * This is the inverse of dGeomGetRelPointPos()
485 * @param result will contain the result.
487 ODE_API void dGeomGetPosRelPoint
489 dGeomID geom, dReal px, dReal py, dReal pz,
494 * @brief Convert from geom-local to world coordinates.
496 * Calling this function on a non-placeable geom results in the same vector being
500 * @param result will contain the result.
502 ODE_API void dGeomVectorToWorld
504 dGeomID geom, dReal px, dReal py, dReal pz,
509 * @brief Convert from world to geom-local coordinates.
511 * Calling this function on a non-placeable geom results in the same vector being
515 * @param result will contain the result.
517 ODE_API void dGeomVectorFromWorld
519 dGeomID geom, dReal px, dReal py, dReal pz,
524 /* ************************************************************************ */
525 /* geom offset from body */
528 * @brief Set the local offset position of a geom from its body.
530 * Sets the geom's positional offset in local coordinates.
531 * After this call, the geom will be at a new position determined from the
532 * body's position and the offset.
533 * The geom must be attached to a body.
534 * If the geom did not have an offset, it is automatically created.
536 * @param geom the geom to set.
537 * @param x the new X coordinate.
538 * @param y the new Y coordinate.
539 * @param z the new Z coordinate.
542 ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
546 * @brief Set the local offset rotation matrix of a geom from its body.
548 * Sets the geom's rotational offset in local coordinates.
549 * After this call, the geom will be at a new position determined from the
550 * body's position and the offset.
551 * The geom must be attached to a body.
552 * If the geom did not have an offset, it is automatically created.
554 * @param geom the geom to set.
555 * @param R the new rotation matrix.
558 ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
562 * @brief Set the local offset rotation of a geom from its body.
564 * Sets the geom's rotational offset in local coordinates.
565 * After this call, the geom will be at a new position determined from the
566 * body's position and the offset.
567 * The geom must be attached to a body.
568 * If the geom did not have an offset, it is automatically created.
570 * @param geom the geom to set.
571 * @param Q the new rotation.
574 ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
578 * @brief Set the offset position of a geom from its body.
580 * Sets the geom's positional offset to move it to the new world
582 * After this call, the geom will be at the world position passed in,
583 * and the offset will be the difference from the current body position.
584 * The geom must be attached to a body.
585 * If the geom did not have an offset, it is automatically created.
587 * @param geom the geom to set.
588 * @param x the new X coordinate.
589 * @param y the new Y coordinate.
590 * @param z the new Z coordinate.
593 ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
597 * @brief Set the offset rotation of a geom from its body.
599 * Sets the geom's rotational offset to orient it to the new world
601 * After this call, the geom will be at the world orientation passed in,
602 * and the offset will be the difference from the current body orientation.
603 * The geom must be attached to a body.
604 * If the geom did not have an offset, it is automatically created.
606 * @param geom the geom to set.
607 * @param R the new rotation matrix.
610 ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
614 * @brief Set the offset rotation of a geom from its body.
616 * Sets the geom's rotational offset to orient it to the new world
618 * After this call, the geom will be at the world orientation passed in,
619 * and the offset will be the difference from the current body orientation.
620 * The geom must be attached to a body.
621 * If the geom did not have an offset, it is automatically created.
623 * @param geom the geom to set.
624 * @param Q the new rotation.
627 ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
631 * @brief Clear any offset from the geom.
633 * If the geom has an offset, it is eliminated and the geom is
634 * repositioned at the body's position. If the geom has no offset,
635 * this function does nothing.
636 * This is more efficient than calling dGeomSetOffsetPosition(zero)
637 * and dGeomSetOffsetRotation(identiy), because this function actually
638 * eliminates the offset, rather than leaving it as the identity transform.
640 * @param geom the geom to have its offset destroyed.
643 ODE_API void dGeomClearOffset(dGeomID geom);
647 * @brief Check to see whether the geom has an offset.
649 * This function will return non-zero if the offset has been created.
650 * Note that there is a difference between a geom with no offset,
651 * and a geom with an offset that is the identity transform.
652 * In the latter case, although the observed behaviour is identical,
653 * there is a unnecessary computation involved because the geom will
654 * be applying the transform whenever it needs to recalculate its world
657 * @param geom the geom to query.
658 * @returns Non-zero if the geom has an offset, zero otherwise.
661 ODE_API int dGeomIsOffset(dGeomID geom);
665 * @brief Get the offset position vector of a geom.
667 * Returns the positional offset of the geom in local coordinates.
668 * If the geom has no offset, this function returns the zero vector.
670 * @param geom the geom to query.
671 * @returns A pointer to the geom's offset vector.
672 * @remarks The returned value is a pointer to the geom's internal
673 * data structure. It is valid until any changes are made
677 ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
681 * @brief Copy the offset position vector of a geom.
683 * Returns the positional offset of the geom in local coordinates.
684 * If the geom has no offset, this function returns the zero vector.
686 * @param geom the geom to query.
687 * @param pos returns the offset position
690 ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos);
694 * @brief Get the offset rotation matrix of a geom.
696 * Returns the rotational offset of the geom in local coordinates.
697 * If the geom has no offset, this function returns the identity
700 * @param geom the geom to query.
701 * @returns A pointer to the geom's offset rotation matrix.
702 * @remarks The returned value is a pointer to the geom's internal
703 * data structure. It is valid until any changes are made
707 ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
711 * @brief Copy the offset rotation matrix of a geom.
713 * Returns the rotational offset of the geom in local coordinates.
714 * If the geom has no offset, this function returns the identity
717 * @param geom the geom to query.
718 * @param R returns the rotation matrix.
721 ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R);
725 * @brief Get the offset rotation quaternion of a geom.
727 * Returns the rotation offset of the geom as a quaternion.
728 * If the geom has no offset, the identity quaternion is returned.
730 * @param geom the geom to query.
731 * @param result a copy of the rotation quaternion.
734 ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
737 /* ************************************************************************ */
738 /* collision detection */
741 * Just generate any contacts (disables any contact refining).
743 #define CONTACTS_UNIMPORTANT 0x80000000
747 * @brief Given two geoms o1 and o2 that potentially intersect,
748 * generate contact information for them.
750 * Internally, this just calls the correct class-specific collision
751 * functions for o1 and o2.
753 * @param o1 The first geom to test.
754 * @param o2 The second geom to test.
756 * @param flags The flags specify how contacts should be generated if
757 * the geoms touch. The lower 16 bits of flags is an integer that
758 * specifies the maximum number of contact points to generate. You must
759 * ask for at least one contact.
760 * Additionally, following bits may be set:
761 * CONTACTS_UNIMPORTANT -- just generate any contacts (skip contact refining).
762 * All other bits in flags must be set to zero. In the future the other bits
763 * may be used to select from different contact generation strategies.
765 * @param contact Points to an array of dContactGeom structures. The array
766 * must be able to hold at least the maximum number of contacts. These
767 * dContactGeom structures may be embedded within larger structures in the
768 * array -- the skip parameter is the byte offset from one dContactGeom to
769 * the next in the array. If skip is sizeof(dContactGeom) then contact
770 * points to a normal (C-style) array. It is an error for skip to be smaller
771 * than sizeof(dContactGeom).
773 * @returns If the geoms intersect, this function returns the number of contact
774 * points generated (and updates the contact array), otherwise it returns 0
775 * (and the contact array is not touched).
777 * @remarks If a space is passed as o1 or o2 then this function will collide
778 * all objects contained in o1 with all objects contained in o2, and return
779 * the resulting contact points. This method for colliding spaces with geoms
780 * (or spaces with spaces) provides no user control over the individual
781 * collisions. To get that control, use dSpaceCollide or dSpaceCollide2 instead.
783 * @remarks If o1 and o2 are the same geom then this function will do nothing
784 * and return 0. Technically speaking an object intersects with itself, but it
785 * is not useful to find contact points in this case.
787 * @remarks This function does not care if o1 and o2 are in the same space or not
788 * (or indeed if they are in any space at all).
792 ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
796 * @brief Determines which pairs of geoms in a space may potentially intersect,
797 * and calls the callback function for each candidate pair.
799 * @param space The space to test.
801 * @param data Passed from dSpaceCollide directly to the callback
802 * function. Its meaning is user defined. The o1 and o2 arguments are the
803 * geoms that may be near each other.
805 * @param callback A callback function is of type @ref dNearCallback.
807 * @remarks Other spaces that are contained within the colliding space are
808 * not treated specially, i.e. they are not recursed into. The callback
809 * function may be passed these contained spaces as one or both geom
812 * @remarks dSpaceCollide() is guaranteed to pass all intersecting geom
813 * pairs to the callback function, but may also pass close but
814 * non-intersecting pairs. The number of these calls depends on the
815 * internal algorithms used by the space. Thus you should not expect
816 * that dCollide will return contacts for every pair passed to the
822 ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
826 * @brief Determines which geoms from one space may potentially intersect with
827 * geoms from another space, and calls the callback function for each candidate
830 * @param space1 The first space to test.
832 * @param space2 The second space to test.
834 * @param data Passed from dSpaceCollide directly to the callback
835 * function. Its meaning is user defined. The o1 and o2 arguments are the
836 * geoms that may be near each other.
838 * @param callback A callback function is of type @ref dNearCallback.
840 * @remarks This function can also test a single non-space geom against a
841 * space. This function is useful when there is a collision hierarchy, i.e.
842 * when there are spaces that contain other spaces.
844 * @remarks Other spaces that are contained within the colliding space are
845 * not treated specially, i.e. they are not recursed into. The callback
846 * function may be passed these contained spaces as one or both geom
849 * @remarks Sublevel value of space affects how the spaces are iterated.
850 * Both spaces are recursed only if their sublevels match. Otherwise, only
851 * the space with greater sublevel is recursed and the one with lesser sublevel
852 * is used as a geom itself.
854 * @remarks dSpaceCollide2() is guaranteed to pass all intersecting geom
855 * pairs to the callback function, but may also pass close but
856 * non-intersecting pairs. The number of these calls depends on the
857 * internal algorithms used by the space. Thus you should not expect
858 * that dCollide will return contacts for every pair passed to the
862 * @sa dSpaceSetSublevel
865 ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
868 /* ************************************************************************ */
869 /* standard classes */
871 /* the maximum number of user classes that are supported */
876 /* class numbers - each geometry object needs a unique number */
890 dSimpleSpaceClass = dFirstSpaceClass,
892 dSweepAndPruneSpaceClass, /* SAP */
894 dLastSpaceClass = dQuadTreeSpaceClass,
897 dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
903 * @defgroup collide_sphere Sphere Class
908 * @brief Create a sphere geom of the given radius, and return its ID.
910 * @param space a space to contain the new geom. May be null.
911 * @param radius the radius of the sphere.
913 * @returns A new sphere geom.
915 * @remarks The point of reference for a sphere is its center.
918 * @sa dGeomSphereSetRadius
919 * @ingroup collide_sphere
921 ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
925 * @brief Set the radius of a sphere geom.
927 * @param sphere the sphere to set.
928 * @param radius the new radius.
930 * @sa dGeomSphereGetRadius
931 * @ingroup collide_sphere
933 ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
937 * @brief Retrieves the radius of a sphere geom.
939 * @param sphere the sphere to query.
941 * @sa dGeomSphereSetRadius
942 * @ingroup collide_sphere
944 ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
948 * @brief Calculate the depth of the a given point within a sphere.
950 * @param sphere the sphere to query.
951 * @param x the X coordinate of the point.
952 * @param y the Y coordinate of the point.
953 * @param z the Z coordinate of the point.
955 * @returns The depth of the point. Points inside the sphere will have a
956 * positive depth, points outside it will have a negative depth, and points
957 * on the surface will have a depth of zero.
959 * @ingroup collide_sphere
961 ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
964 /*--> Convex Functions*/
965 ODE_API dGeomID dCreateConvex (dSpaceID space,
966 const dReal *_planes,
967 unsigned int _planecount,
968 const dReal *_points,
969 unsigned int _pointcount,
970 const unsigned int *_polygons);
972 ODE_API void dGeomSetConvex (dGeomID g,
973 const dReal *_planes,
975 const dReal *_points,
976 unsigned int _pointcount,
977 const unsigned int *_polygons);
978 /*<-- Convex Functions*/
981 * @defgroup collide_box Box Class
986 * @brief Create a box geom with the provided side lengths.
988 * @param space a space to contain the new geom. May be null.
989 * @param lx the length of the box along the X axis
990 * @param ly the length of the box along the Y axis
991 * @param lz the length of the box along the Z axis
993 * @returns A new box geom.
995 * @remarks The point of reference for a box is its center.
998 * @sa dGeomBoxSetLengths
999 * @ingroup collide_box
1001 ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
1005 * @brief Set the side lengths of the given box.
1007 * @param box the box to set
1008 * @param lx the length of the box along the X axis
1009 * @param ly the length of the box along the Y axis
1010 * @param lz the length of the box along the Z axis
1012 * @sa dGeomBoxGetLengths
1013 * @ingroup collide_box
1015 ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
1019 * @brief Get the side lengths of a box.
1021 * @param box the box to query
1022 * @param result the returned side lengths
1024 * @sa dGeomBoxSetLengths
1025 * @ingroup collide_box
1027 ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
1031 * @brief Return the depth of a point in a box.
1033 * @param box the box to query
1034 * @param x the X coordinate of the point to test.
1035 * @param y the Y coordinate of the point to test.
1036 * @param z the Z coordinate of the point to test.
1038 * @returns The depth of the point. Points inside the box will have a
1039 * positive depth, points outside it will have a negative depth, and points
1040 * on the surface will have a depth of zero.
1042 ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
1045 ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
1046 ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
1047 ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
1048 ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
1050 ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
1051 ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
1052 ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
1053 ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
1055 /* For now we want to have a backwards compatible C-API, note: C++ API is not.*/
1056 #define dCreateCCylinder dCreateCapsule
1057 #define dGeomCCylinderSetParams dGeomCapsuleSetParams
1058 #define dGeomCCylinderGetParams dGeomCapsuleGetParams
1059 #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
1060 #define dCCylinderClass dCapsuleClass
1062 ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
1063 ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
1064 ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
1066 ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
1067 ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
1068 ODE_API dReal dGeomRayGetLength (dGeomID ray);
1069 ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
1070 dReal dx, dReal dy, dReal dz);
1071 ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
1074 * Set/get ray flags that influence ray collision detection.
1075 * These flags are currently only noticed by the trimesh collider, because
1076 * they can make a major differences there.
1078 ODE_API_DEPRECATED ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
1079 ODE_API_DEPRECATED ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
1080 ODE_API void dGeomRaySetFirstContact (dGeomID g, int firstContact);
1081 ODE_API int dGeomRayGetFirstContact (dGeomID g);
1082 ODE_API void dGeomRaySetBackfaceCull (dGeomID g, int backfaceCull);
1083 ODE_API int dGeomRayGetBackfaceCull (dGeomID g);
1084 ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
1085 ODE_API int dGeomRayGetClosestHit (dGeomID g);
1087 #include "collision_trimesh.h"
1089 ODE_API_DEPRECATED ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
1090 ODE_API_DEPRECATED ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
1091 ODE_API_DEPRECATED ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
1092 ODE_API_DEPRECATED ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
1093 ODE_API_DEPRECATED ODE_API int dGeomTransformGetCleanup (dGeomID g);
1094 ODE_API_DEPRECATED ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
1095 ODE_API_DEPRECATED ODE_API int dGeomTransformGetInfo (dGeomID g);
1098 /* ************************************************************************ */
1099 /* heightfield functions */
1102 /* Data storage for heightfield data.*/
1103 struct dxHeightfieldData;
1104 typedef struct dxHeightfieldData* dHeightfieldDataID;
1108 * @brief Callback prototype
1110 * Used by the callback heightfield data type to sample a height for a
1111 * given cell position.
1113 * @param p_user_data User data specified when creating the dHeightfieldDataID
1114 * @param x The index of a sample in the local x axis. It is a value
1115 * in the range zero to ( nWidthSamples - 1 ).
1116 * @param x The index of a sample in the local z axis. It is a value
1117 * in the range zero to ( nDepthSamples - 1 ).
1119 * @return The sample height which is then scaled and offset using the
1120 * values specified when the heightfield data was created.
1124 typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
1129 * @brief Creates a heightfield geom.
1131 * Uses the information in the given dHeightfieldDataID to construct
1132 * a geom representing a heightfield in a collision space.
1134 * @param space The space to add the geom to.
1135 * @param data The dHeightfieldDataID created by dGeomHeightfieldDataCreate and
1136 * setup by dGeomHeightfieldDataBuildCallback, dGeomHeightfieldDataBuildByte,
1137 * dGeomHeightfieldDataBuildShort or dGeomHeightfieldDataBuildFloat.
1138 * @param bPlaceable If non-zero this geom can be transformed in the world using the
1139 * usual functions such as dGeomSetPosition and dGeomSetRotation. If the geom is
1140 * not set as placeable, then it uses a fixed orientation where the global y axis
1141 * represents the dynamic 'height' of the heightfield.
1143 * @return A geom id to reference this geom in other calls.
1147 ODE_API dGeomID dCreateHeightfield( dSpaceID space,
1148 dHeightfieldDataID data, int bPlaceable );
1152 * @brief Creates a new empty dHeightfieldDataID.
1154 * Allocates a new dHeightfieldDataID and returns it. You must call
1155 * dGeomHeightfieldDataDestroy to destroy it after the geom has been removed.
1156 * The dHeightfieldDataID value is used when specifying a data format type.
1158 * @return A dHeightfieldDataID for use with dGeomHeightfieldDataBuildCallback,
1159 * dGeomHeightfieldDataBuildByte, dGeomHeightfieldDataBuildShort or
1160 * dGeomHeightfieldDataBuildFloat.
1163 ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void);
1167 * @brief Destroys a dHeightfieldDataID.
1169 * Deallocates a given dHeightfieldDataID and all managed resources.
1171 * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
1174 ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
1179 * @brief Configures a dHeightfieldDataID to use a callback to
1180 * retrieve height data.
1182 * Before a dHeightfieldDataID can be used by a geom it must be
1183 * configured to specify the format of the height data.
1184 * This call specifies that the heightfield data is computed by
1185 * the user and it should use the given callback when determining
1186 * the height of a given element of it's shape.
1188 * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
1190 * @param width Specifies the total 'width' of the heightfield along
1191 * the geom's local x axis.
1192 * @param depth Specifies the total 'depth' of the heightfield along
1193 * the geom's local z axis.
1195 * @param widthSamples Specifies the number of vertices to sample
1196 * along the width of the heightfield. Each vertex has a corresponding
1197 * height value which forms the overall shape.
1198 * Naturally this value must be at least two or more.
1199 * @param depthSamples Specifies the number of vertices to sample
1200 * along the depth of the heightfield.
1202 * @param scale A uniform scale applied to all raw height data.
1203 * @param offset An offset applied to the scaled height data.
1205 * @param thickness A value subtracted from the lowest height
1206 * value which in effect adds an additional cuboid to the base of the
1207 * heightfield. This is used to prevent geoms from looping under the
1208 * desired terrain and not registering as a collision. Note that the
1209 * thickness is not affected by the scale or offset parameters.
1211 * @param bWrap If non-zero the heightfield will infinitely tile in both
1212 * directions along the local x and z axes. If zero the heightfield is
1213 * bounded from zero to width in the local x axis, and zero to depth in
1218 ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
1219 void* pUserData, dHeightfieldGetHeight* pCallback,
1220 dReal width, dReal depth, int widthSamples, int depthSamples,
1221 dReal scale, dReal offset, dReal thickness, int bWrap );
1224 * @brief Configures a dHeightfieldDataID to use height data in byte format.
1226 * Before a dHeightfieldDataID can be used by a geom it must be
1227 * configured to specify the format of the height data.
1228 * This call specifies that the heightfield data is stored as a rectangular
1229 * array of bytes (8 bit unsigned) representing the height at each sample point.
1231 * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
1233 * @param pHeightData A pointer to the height data.
1234 * @param bCopyHeightData When non-zero the height data is copied to an
1235 * internal store. When zero the height data is accessed by reference and
1236 * so must persist throughout the lifetime of the heightfield.
1238 * @param width Specifies the total 'width' of the heightfield along
1239 * the geom's local x axis.
1240 * @param depth Specifies the total 'depth' of the heightfield along
1241 * the geom's local z axis.
1243 * @param widthSamples Specifies the number of vertices to sample
1244 * along the width of the heightfield. Each vertex has a corresponding
1245 * height value which forms the overall shape.
1246 * Naturally this value must be at least two or more.
1247 * @param depthSamples Specifies the number of vertices to sample
1248 * along the depth of the heightfield.
1250 * @param scale A uniform scale applied to all raw height data.
1251 * @param offset An offset applied to the scaled height data.
1253 * @param thickness A value subtracted from the lowest height
1254 * value which in effect adds an additional cuboid to the base of the
1255 * heightfield. This is used to prevent geoms from looping under the
1256 * desired terrain and not registering as a collision. Note that the
1257 * thickness is not affected by the scale or offset parameters.
1259 * @param bWrap If non-zero the heightfield will infinitely tile in both
1260 * directions along the local x and z axes. If zero the heightfield is
1261 * bounded from zero to width in the local x axis, and zero to depth in
1266 ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
1267 const unsigned char* pHeightData, int bCopyHeightData,
1268 dReal width, dReal depth, int widthSamples, int depthSamples,
1269 dReal scale, dReal offset, dReal thickness, int bWrap );
1272 * @brief Configures a dHeightfieldDataID to use height data in short format.
1274 * Before a dHeightfieldDataID can be used by a geom it must be
1275 * configured to specify the format of the height data.
1276 * This call specifies that the heightfield data is stored as a rectangular
1277 * array of shorts (16 bit signed) representing the height at each sample point.
1279 * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
1281 * @param pHeightData A pointer to the height data.
1282 * @param bCopyHeightData When non-zero the height data is copied to an
1283 * internal store. When zero the height data is accessed by reference and
1284 * so must persist throughout the lifetime of the heightfield.
1286 * @param width Specifies the total 'width' of the heightfield along
1287 * the geom's local x axis.
1288 * @param depth Specifies the total 'depth' of the heightfield along
1289 * the geom's local z axis.
1291 * @param widthSamples Specifies the number of vertices to sample
1292 * along the width of the heightfield. Each vertex has a corresponding
1293 * height value which forms the overall shape.
1294 * Naturally this value must be at least two or more.
1295 * @param depthSamples Specifies the number of vertices to sample
1296 * along the depth of the heightfield.
1298 * @param scale A uniform scale applied to all raw height data.
1299 * @param offset An offset applied to the scaled height data.
1301 * @param thickness A value subtracted from the lowest height
1302 * value which in effect adds an additional cuboid to the base of the
1303 * heightfield. This is used to prevent geoms from looping under the
1304 * desired terrain and not registering as a collision. Note that the
1305 * thickness is not affected by the scale or offset parameters.
1307 * @param bWrap If non-zero the heightfield will infinitely tile in both
1308 * directions along the local x and z axes. If zero the heightfield is
1309 * bounded from zero to width in the local x axis, and zero to depth in
1314 ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
1315 const short* pHeightData, int bCopyHeightData,
1316 dReal width, dReal depth, int widthSamples, int depthSamples,
1317 dReal scale, dReal offset, dReal thickness, int bWrap );
1320 * @brief Configures a dHeightfieldDataID to use height data in
1321 * single precision floating point format.
1323 * Before a dHeightfieldDataID can be used by a geom it must be
1324 * configured to specify the format of the height data.
1325 * This call specifies that the heightfield data is stored as a rectangular
1326 * array of single precision floats representing the height at each
1329 * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
1331 * @param pHeightData A pointer to the height data.
1332 * @param bCopyHeightData When non-zero the height data is copied to an
1333 * internal store. When zero the height data is accessed by reference and
1334 * so must persist throughout the lifetime of the heightfield.
1336 * @param width Specifies the total 'width' of the heightfield along
1337 * the geom's local x axis.
1338 * @param depth Specifies the total 'depth' of the heightfield along
1339 * the geom's local z axis.
1341 * @param widthSamples Specifies the number of vertices to sample
1342 * along the width of the heightfield. Each vertex has a corresponding
1343 * height value which forms the overall shape.
1344 * Naturally this value must be at least two or more.
1345 * @param depthSamples Specifies the number of vertices to sample
1346 * along the depth of the heightfield.
1348 * @param scale A uniform scale applied to all raw height data.
1349 * @param offset An offset applied to the scaled height data.
1351 * @param thickness A value subtracted from the lowest height
1352 * value which in effect adds an additional cuboid to the base of the
1353 * heightfield. This is used to prevent geoms from looping under the
1354 * desired terrain and not registering as a collision. Note that the
1355 * thickness is not affected by the scale or offset parameters.
1357 * @param bWrap If non-zero the heightfield will infinitely tile in both
1358 * directions along the local x and z axes. If zero the heightfield is
1359 * bounded from zero to width in the local x axis, and zero to depth in
1364 ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
1365 const float* pHeightData, int bCopyHeightData,
1366 dReal width, dReal depth, int widthSamples, int depthSamples,
1367 dReal scale, dReal offset, dReal thickness, int bWrap );
1370 * @brief Configures a dHeightfieldDataID to use height data in
1371 * double precision floating point format.
1373 * Before a dHeightfieldDataID can be used by a geom it must be
1374 * configured to specify the format of the height data.
1375 * This call specifies that the heightfield data is stored as a rectangular
1376 * array of double precision floats representing the height at each
1379 * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
1381 * @param pHeightData A pointer to the height data.
1382 * @param bCopyHeightData When non-zero the height data is copied to an
1383 * internal store. When zero the height data is accessed by reference and
1384 * so must persist throughout the lifetime of the heightfield.
1386 * @param width Specifies the total 'width' of the heightfield along
1387 * the geom's local x axis.
1388 * @param depth Specifies the total 'depth' of the heightfield along
1389 * the geom's local z axis.
1391 * @param widthSamples Specifies the number of vertices to sample
1392 * along the width of the heightfield. Each vertex has a corresponding
1393 * height value which forms the overall shape.
1394 * Naturally this value must be at least two or more.
1395 * @param depthSamples Specifies the number of vertices to sample
1396 * along the depth of the heightfield.
1398 * @param scale A uniform scale applied to all raw height data.
1399 * @param offset An offset applied to the scaled height data.
1401 * @param thickness A value subtracted from the lowest height
1402 * value which in effect adds an additional cuboid to the base of the
1403 * heightfield. This is used to prevent geoms from looping under the
1404 * desired terrain and not registering as a collision. Note that the
1405 * thickness is not affected by the scale or offset parameters.
1407 * @param bWrap If non-zero the heightfield will infinitely tile in both
1408 * directions along the local x and z axes. If zero the heightfield is
1409 * bounded from zero to width in the local x axis, and zero to depth in
1414 ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
1415 const double* pHeightData, int bCopyHeightData,
1416 dReal width, dReal depth, int widthSamples, int depthSamples,
1417 dReal scale, dReal offset, dReal thickness, int bWrap );
1420 * @brief Manually set the minimum and maximum height bounds.
1422 * This call allows you to set explicit min / max values after initial
1423 * creation typically for callback heightfields which default to +/- infinity,
1424 * or those whose data has changed. This must be set prior to binding with a
1425 * geom, as the the AABB is not recomputed after it's first generation.
1427 * @remarks The minimum and maximum values are used to compute the AABB
1428 * for the heightfield which is used for early rejection of collisions.
1429 * A close fit will yield a more efficient collision check.
1431 * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
1432 * @param min_height The new minimum height value. Scale, offset and thickness is then applied.
1433 * @param max_height The new maximum height value. Scale and offset is then applied.
1436 ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
1437 dReal minHeight, dReal maxHeight );
1441 * @brief Assigns a dHeightfieldDataID to a heightfield geom.
1443 * Associates the given dHeightfieldDataID with a heightfield geom.
1444 * This is done without affecting the GEOM_PLACEABLE flag.
1446 * @param g A geom created by dCreateHeightfield
1447 * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
1450 ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
1454 * @brief Gets the dHeightfieldDataID bound to a heightfield geom.
1456 * Returns the dHeightfieldDataID associated with a heightfield geom.
1458 * @param g A geom created by dCreateHeightfield
1459 * @return The dHeightfieldDataID which may be NULL if none was assigned.
1462 ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
1466 /* ************************************************************************ */
1467 /* utility functions */
1469 ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
1470 const dVector3 b1, const dVector3 b2,
1471 dVector3 cp1, dVector3 cp2);
1473 ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
1474 const dVector3 side1, const dVector3 _p2,
1475 const dMatrix3 R2, const dVector3 side2);
1477 /* The meaning of flags parameter is the same as in dCollide()*/
1478 ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
1479 const dVector3 side1, const dVector3 p2,
1480 const dMatrix3 R2, const dVector3 side2,
1481 dVector3 normal, dReal *depth, int *return_code,
1482 int flags, dContactGeom *contact, int skip);
1484 ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
1487 /* ************************************************************************ */
1488 /* custom classes */
1490 typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
1491 typedef int dColliderFn (dGeomID o1, dGeomID o2,
1492 int flags, dContactGeom *contact, int skip);
1493 typedef dColliderFn * dGetColliderFnFn (int num);
1494 typedef void dGeomDtorFn (dGeomID o);
1495 typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
1497 typedef struct dGeomClass {
1499 dGetColliderFnFn *collider;
1501 dAABBTestFn *aabb_test;
1505 ODE_API int dCreateGeomClass (const dGeomClass *classptr);
1506 ODE_API void * dGeomGetClassData (dGeomID);
1507 ODE_API dGeomID dCreateGeom (int classnum);
1510 * @brief Sets a custom collider function for two geom classes.
1512 * @param i The first geom class handled by this collider
1513 * @param j The second geom class handled by this collider
1514 * @param fn The collider function to use to determine collisions.
1517 ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn);
1520 /* ************************************************************************ */