collision.h 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001-2003 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  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 *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  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. *
  20. * *
  21. *************************************************************************/
  22. #ifndef _ODE_COLLISION_H_
  23. #define _ODE_COLLISION_H_
  24. #include <ode/common.h>
  25. #include <ode/collision_space.h>
  26. #include <ode/contact.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * @defgroup collide Collision Detection
  32. *
  33. * ODE has two main components: a dynamics simulation engine and a collision
  34. * detection engine. The collision engine is given information about the
  35. * shape of each body. At each time step it figures out which bodies touch
  36. * each other and passes the resulting contact point information to the user.
  37. * The user in turn creates contact joints between bodies.
  38. *
  39. * Using ODE's collision detection is optional - an alternative collision
  40. * detection system can be used as long as it can supply the right kinds of
  41. * contact information.
  42. */
  43. /* ************************************************************************ */
  44. /* general functions */
  45. /**
  46. * @brief Destroy a geom, removing it from any space.
  47. *
  48. * Destroy a geom, removing it from any space it is in first. This one
  49. * function destroys a geom of any type, but to create a geom you must call
  50. * a creation function for that type.
  51. *
  52. * When a space is destroyed, if its cleanup mode is 1 (the default) then all
  53. * the geoms in that space are automatically destroyed as well.
  54. *
  55. * @param geom the geom to be destroyed.
  56. * @ingroup collide
  57. */
  58. ODE_API void dGeomDestroy (dGeomID geom);
  59. /**
  60. * @brief Set the user-defined data pointer stored in the geom.
  61. *
  62. * @param geom the geom to hold the data
  63. * @param data the data pointer to be stored
  64. * @ingroup collide
  65. */
  66. ODE_API void dGeomSetData (dGeomID geom, void* data);
  67. /**
  68. * @brief Get the user-defined data pointer stored in the geom.
  69. *
  70. * @param geom the geom containing the data
  71. * @ingroup collide
  72. */
  73. ODE_API void *dGeomGetData (dGeomID geom);
  74. /**
  75. * @brief Set the body associated with a placeable geom.
  76. *
  77. * Setting a body on a geom automatically combines the position vector and
  78. * rotation matrix of the body and geom, so that setting the position or
  79. * orientation of one will set the value for both objects. Setting a body
  80. * ID of zero gives the geom its own position and rotation, independent
  81. * from any body. If the geom was previously connected to a body then its
  82. * new independent position/rotation is set to the current position/rotation
  83. * of the body.
  84. *
  85. * Calling these functions on a non-placeable geom results in a runtime
  86. * error in the debug build of ODE.
  87. *
  88. * @param geom the geom to connect
  89. * @param body the body to attach to the geom
  90. * @ingroup collide
  91. */
  92. ODE_API void dGeomSetBody (dGeomID geom, dBodyID body);
  93. /**
  94. * @brief Get the body associated with a placeable geom.
  95. * @param geom the geom to query.
  96. * @sa dGeomSetBody
  97. * @ingroup collide
  98. */
  99. ODE_API dBodyID dGeomGetBody (dGeomID geom);
  100. /**
  101. * @brief Set the position vector of a placeable geom.
  102. *
  103. * If the geom is attached to a body, the body's position will also be changed.
  104. * Calling this function on a non-placeable geom results in a runtime error in
  105. * the debug build of ODE.
  106. *
  107. * @param geom the geom to set.
  108. * @param x the new X coordinate.
  109. * @param y the new Y coordinate.
  110. * @param z the new Z coordinate.
  111. * @sa dBodySetPosition
  112. * @ingroup collide
  113. */
  114. ODE_API void dGeomSetPosition (dGeomID geom, dReal x, dReal y, dReal z);
  115. /**
  116. * @brief Set the rotation matrix of a placeable geom.
  117. *
  118. * If the geom is attached to a body, the body's rotation will also be changed.
  119. * Calling this function on a non-placeable geom results in a runtime error in
  120. * the debug build of ODE.
  121. *
  122. * @param geom the geom to set.
  123. * @param R the new rotation matrix.
  124. * @sa dBodySetRotation
  125. * @ingroup collide
  126. */
  127. ODE_API void dGeomSetRotation (dGeomID geom, const dMatrix3 R);
  128. /**
  129. * @brief Set the rotation of a placeable geom.
  130. *
  131. * If the geom is attached to a body, the body's rotation will also be changed.
  132. *
  133. * Calling this function on a non-placeable geom results in a runtime error in
  134. * the debug build of ODE.
  135. *
  136. * @param geom the geom to set.
  137. * @param Q the new rotation.
  138. * @sa dBodySetQuaternion
  139. * @ingroup collide
  140. */
  141. ODE_API void dGeomSetQuaternion (dGeomID geom, const dQuaternion Q);
  142. /**
  143. * @brief Get the position vector of a placeable geom.
  144. *
  145. * If the geom is attached to a body, the body's position will be returned.
  146. *
  147. * Calling this function on a non-placeable geom results in a runtime error in
  148. * the debug build of ODE.
  149. *
  150. * @param geom the geom to query.
  151. * @returns A pointer to the geom's position vector.
  152. * @remarks The returned value is a pointer to the geom's internal
  153. * data structure. It is valid until any changes are made
  154. * to the geom.
  155. * @sa dBodyGetPosition
  156. * @ingroup collide
  157. */
  158. ODE_API const dReal * dGeomGetPosition (dGeomID geom);
  159. /**
  160. * @brief Copy the position of a geom into a vector.
  161. * @ingroup collide
  162. * @param geom the geom to query
  163. * @param pos a copy of the geom position
  164. * @sa dGeomGetPosition
  165. */
  166. ODE_API void dGeomCopyPosition (dGeomID geom, dVector3 pos);
  167. /**
  168. * @brief Get the rotation matrix of a placeable geom.
  169. *
  170. * If the geom is attached to a body, the body's rotation will be returned.
  171. *
  172. * Calling this function on a non-placeable geom results in a runtime error in
  173. * the debug build of ODE.
  174. *
  175. * @param geom the geom to query.
  176. * @returns A pointer to the geom's rotation matrix.
  177. * @remarks The returned value is a pointer to the geom's internal
  178. * data structure. It is valid until any changes are made
  179. * to the geom.
  180. * @sa dBodyGetRotation
  181. * @ingroup collide
  182. */
  183. ODE_API const dReal * dGeomGetRotation (dGeomID geom);
  184. /**
  185. * @brief Get the rotation matrix of a placeable geom.
  186. *
  187. * If the geom is attached to a body, the body's rotation will be returned.
  188. *
  189. * Calling this function on a non-placeable geom results in a runtime error in
  190. * the debug build of ODE.
  191. *
  192. * @param geom the geom to query.
  193. * @param R a copy of the geom rotation
  194. * @sa dGeomGetRotation
  195. * @ingroup collide
  196. */
  197. ODE_API void dGeomCopyRotation(dGeomID geom, dMatrix3 R);
  198. /**
  199. * @brief Get the rotation quaternion of a placeable geom.
  200. *
  201. * If the geom is attached to a body, the body's quaternion will be returned.
  202. *
  203. * Calling this function on a non-placeable geom results in a runtime error in
  204. * the debug build of ODE.
  205. *
  206. * @param geom the geom to query.
  207. * @param result a copy of the rotation quaternion.
  208. * @sa dBodyGetQuaternion
  209. * @ingroup collide
  210. */
  211. ODE_API void dGeomGetQuaternion (dGeomID geom, dQuaternion result);
  212. /**
  213. * @brief Return the axis-aligned bounding box.
  214. *
  215. * Return in aabb an axis aligned bounding box that surrounds the given geom.
  216. * The aabb array has elements (minx, maxx, miny, maxy, minz, maxz). If the
  217. * geom is a space, a bounding box that surrounds all contained geoms is
  218. * returned.
  219. *
  220. * This function may return a pre-computed cached bounding box, if it can
  221. * determine that the geom has not moved since the last time the bounding
  222. * box was computed.
  223. *
  224. * @param geom the geom to query
  225. * @param aabb the returned bounding box
  226. * @ingroup collide
  227. */
  228. ODE_API void dGeomGetAABB (dGeomID geom, dReal aabb[6]);
  229. /**
  230. * @brief Determing if a geom is a space.
  231. * @param geom the geom to query
  232. * @returns Non-zero if the geom is a space, zero otherwise.
  233. * @ingroup collide
  234. */
  235. ODE_API int dGeomIsSpace (dGeomID geom);
  236. /**
  237. * @brief Query for the space containing a particular geom.
  238. * @param geom the geom to query
  239. * @returns The space that contains the geom, or NULL if the geom is
  240. * not contained by a space.
  241. * @ingroup collide
  242. */
  243. ODE_API dSpaceID dGeomGetSpace (dGeomID);
  244. /**
  245. * @brief Given a geom, this returns its class.
  246. *
  247. * The ODE classes are:
  248. * @li dSphereClass
  249. * @li dBoxClass
  250. * @li dCylinderClass
  251. * @li dPlaneClass
  252. * @li dRayClass
  253. * @li dConvexClass
  254. * @li dGeomTransformClass
  255. * @li dTriMeshClass
  256. * @li dSimpleSpaceClass
  257. * @li dHashSpaceClass
  258. * @li dQuadTreeSpaceClass
  259. * @li dFirstUserClass
  260. * @li dLastUserClass
  261. *
  262. * User-defined class will return their own number.
  263. *
  264. * @param geom the geom to query
  265. * @returns The geom class ID.
  266. * @ingroup collide
  267. */
  268. ODE_API int dGeomGetClass (dGeomID geom);
  269. /**
  270. * @brief Set the "category" bitfield for the given geom.
  271. *
  272. * The category bitfield is used by spaces to govern which geoms will
  273. * interact with each other. The bitfield is guaranteed to be at least
  274. * 32 bits wide. The default category values for newly created geoms
  275. * have all bits set.
  276. *
  277. * @param geom the geom to set
  278. * @param bits the new bitfield value
  279. * @ingroup collide
  280. */
  281. ODE_API void dGeomSetCategoryBits (dGeomID geom, unsigned long bits);
  282. /**
  283. * @brief Set the "collide" bitfield for the given geom.
  284. *
  285. * The collide bitfield is used by spaces to govern which geoms will
  286. * interact with each other. The bitfield is guaranteed to be at least
  287. * 32 bits wide. The default category values for newly created geoms
  288. * have all bits set.
  289. *
  290. * @param geom the geom to set
  291. * @param bits the new bitfield value
  292. * @ingroup collide
  293. */
  294. ODE_API void dGeomSetCollideBits (dGeomID geom, unsigned long bits);
  295. /**
  296. * @brief Get the "category" bitfield for the given geom.
  297. *
  298. * @param geom the geom to set
  299. * @param bits the new bitfield value
  300. * @sa dGeomSetCategoryBits
  301. * @ingroup collide
  302. */
  303. ODE_API unsigned long dGeomGetCategoryBits (dGeomID);
  304. /**
  305. * @brief Get the "collide" bitfield for the given geom.
  306. *
  307. * @param geom the geom to set
  308. * @param bits the new bitfield value
  309. * @sa dGeomSetCollideBits
  310. * @ingroup collide
  311. */
  312. ODE_API unsigned long dGeomGetCollideBits (dGeomID);
  313. /**
  314. * @brief Enable a geom.
  315. *
  316. * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
  317. * although they can still be members of a space. New geoms are created in
  318. * the enabled state.
  319. *
  320. * @param geom the geom to enable
  321. * @sa dGeomDisable
  322. * @sa dGeomIsEnabled
  323. * @ingroup collide
  324. */
  325. ODE_API void dGeomEnable (dGeomID geom);
  326. /**
  327. * @brief Disable a geom.
  328. *
  329. * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
  330. * although they can still be members of a space. New geoms are created in
  331. * the enabled state.
  332. *
  333. * @param geom the geom to disable
  334. * @sa dGeomDisable
  335. * @sa dGeomIsEnabled
  336. * @ingroup collide
  337. */
  338. ODE_API void dGeomDisable (dGeomID geom);
  339. /**
  340. * @brief Check to see if a geom is enabled.
  341. *
  342. * Disabled geoms are completely ignored by dSpaceCollide and dSpaceCollide2,
  343. * although they can still be members of a space. New geoms are created in
  344. * the enabled state.
  345. *
  346. * @param geom the geom to query
  347. * @returns Non-zero if the geom is enabled, zero otherwise.
  348. * @sa dGeomDisable
  349. * @sa dGeomIsEnabled
  350. * @ingroup collide
  351. */
  352. ODE_API int dGeomIsEnabled (dGeomID geom);
  353. enum
  354. {
  355. dGeomCommonControlClass = 0,
  356. dGeomColliderControlClass = 1
  357. };
  358. enum
  359. {
  360. dGeomCommonAnyControlCode = 0,
  361. dGeomColliderSetMergeSphereContactsControlCode = 1,
  362. dGeomColliderGetMergeSphereContactsControlCode = 2
  363. };
  364. enum
  365. {
  366. dGeomColliderMergeContactsValue__Default = 0, /* Used with Set... to restore default value*/
  367. dGeomColliderMergeContactsValue_None = 1,
  368. dGeomColliderMergeContactsValue_Normals = 2,
  369. dGeomColliderMergeContactsValue_Full = 3
  370. };
  371. /**
  372. * @brief Execute low level control operation for geometry.
  373. *
  374. * The variable the dataSize points to must be initialized before the call.
  375. * If the size does not match the one expected for the control class/code function
  376. * changes it to the size expected and returns failure. This implies the function
  377. * can be called with NULL data and zero size to test if control class/code is supported
  378. * and obtain required data size for it.
  379. *
  380. * dGeomCommonAnyControlCode applies to any control class and returns success if
  381. * at least one control code is available for the given class with given geom.
  382. *
  383. * Currently there are the folliwing control classes supported:
  384. * @li dGeomColliderControlClass
  385. *
  386. * For dGeomColliderControlClass there are the following codes available:
  387. * @li dGeomColliderSetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
  388. * @li dGeomColliderGetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
  389. *
  390. * @param geom the geom to control
  391. * @param controlClass the control class
  392. * @param controlCode the control code for the class
  393. * @param dataValue the control argument pointer
  394. * @param dataSize the control argument size provided or expected
  395. * @returns Boolean execution status
  396. * @ingroup collide
  397. */
  398. ODE_API int dGeomLowLevelControl (dGeomID geom, int controlClass, int controlCode, void *dataValue, int *dataSize);
  399. /**
  400. * @brief Get world position of a relative point on geom.
  401. *
  402. * Calling this function on a non-placeable geom results in the same point being
  403. * returned.
  404. *
  405. * @ingroup collide
  406. * @param result will contain the result.
  407. */
  408. ODE_API void dGeomGetRelPointPos
  409. (
  410. dGeomID geom, dReal px, dReal py, dReal pz,
  411. dVector3 result
  412. );
  413. /**
  414. * @brief takes a point in global coordinates and returns
  415. * the point's position in geom-relative coordinates.
  416. *
  417. * Calling this function on a non-placeable geom results in the same point being
  418. * returned.
  419. *
  420. * @remarks
  421. * This is the inverse of dGeomGetRelPointPos()
  422. * @ingroup collide
  423. * @param result will contain the result.
  424. */
  425. ODE_API void dGeomGetPosRelPoint
  426. (
  427. dGeomID geom, dReal px, dReal py, dReal pz,
  428. dVector3 result
  429. );
  430. /**
  431. * @brief Convert from geom-local to world coordinates.
  432. *
  433. * Calling this function on a non-placeable geom results in the same vector being
  434. * returned.
  435. *
  436. * @ingroup collide
  437. * @param result will contain the result.
  438. */
  439. ODE_API void dGeomVectorToWorld
  440. (
  441. dGeomID geom, dReal px, dReal py, dReal pz,
  442. dVector3 result
  443. );
  444. /**
  445. * @brief Convert from world to geom-local coordinates.
  446. *
  447. * Calling this function on a non-placeable geom results in the same vector being
  448. * returned.
  449. *
  450. * @ingroup collide
  451. * @param result will contain the result.
  452. */
  453. ODE_API void dGeomVectorFromWorld
  454. (
  455. dGeomID geom, dReal px, dReal py, dReal pz,
  456. dVector3 result
  457. );
  458. /* ************************************************************************ */
  459. /* geom offset from body */
  460. /**
  461. * @brief Set the local offset position of a geom from its body.
  462. *
  463. * Sets the geom's positional offset in local coordinates.
  464. * After this call, the geom will be at a new position determined from the
  465. * body's position and the offset.
  466. * The geom must be attached to a body.
  467. * If the geom did not have an offset, it is automatically created.
  468. *
  469. * @param geom the geom to set.
  470. * @param x the new X coordinate.
  471. * @param y the new Y coordinate.
  472. * @param z the new Z coordinate.
  473. * @ingroup collide
  474. */
  475. ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
  476. /**
  477. * @brief Set the local offset rotation matrix of a geom from its body.
  478. *
  479. * Sets the geom's rotational offset in local coordinates.
  480. * After this call, the geom will be at a new position determined from the
  481. * body's position and the offset.
  482. * The geom must be attached to a body.
  483. * If the geom did not have an offset, it is automatically created.
  484. *
  485. * @param geom the geom to set.
  486. * @param R the new rotation matrix.
  487. * @ingroup collide
  488. */
  489. ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
  490. /**
  491. * @brief Set the local offset rotation of a geom from its body.
  492. *
  493. * Sets the geom's rotational offset in local coordinates.
  494. * After this call, the geom will be at a new position determined from the
  495. * body's position and the offset.
  496. * The geom must be attached to a body.
  497. * If the geom did not have an offset, it is automatically created.
  498. *
  499. * @param geom the geom to set.
  500. * @param Q the new rotation.
  501. * @ingroup collide
  502. */
  503. ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
  504. /**
  505. * @brief Set the offset position of a geom from its body.
  506. *
  507. * Sets the geom's positional offset to move it to the new world
  508. * coordinates.
  509. * After this call, the geom will be at the world position passed in,
  510. * and the offset will be the difference from the current body position.
  511. * The geom must be attached to a body.
  512. * If the geom did not have an offset, it is automatically created.
  513. *
  514. * @param geom the geom to set.
  515. * @param x the new X coordinate.
  516. * @param y the new Y coordinate.
  517. * @param z the new Z coordinate.
  518. * @ingroup collide
  519. */
  520. ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
  521. /**
  522. * @brief Set the offset rotation of a geom from its body.
  523. *
  524. * Sets the geom's rotational offset to orient it to the new world
  525. * rotation matrix.
  526. * After this call, the geom will be at the world orientation passed in,
  527. * and the offset will be the difference from the current body orientation.
  528. * The geom must be attached to a body.
  529. * If the geom did not have an offset, it is automatically created.
  530. *
  531. * @param geom the geom to set.
  532. * @param R the new rotation matrix.
  533. * @ingroup collide
  534. */
  535. ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
  536. /**
  537. * @brief Set the offset rotation of a geom from its body.
  538. *
  539. * Sets the geom's rotational offset to orient it to the new world
  540. * rotation matrix.
  541. * After this call, the geom will be at the world orientation passed in,
  542. * and the offset will be the difference from the current body orientation.
  543. * The geom must be attached to a body.
  544. * If the geom did not have an offset, it is automatically created.
  545. *
  546. * @param geom the geom to set.
  547. * @param Q the new rotation.
  548. * @ingroup collide
  549. */
  550. ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
  551. /**
  552. * @brief Clear any offset from the geom.
  553. *
  554. * If the geom has an offset, it is eliminated and the geom is
  555. * repositioned at the body's position. If the geom has no offset,
  556. * this function does nothing.
  557. * This is more efficient than calling dGeomSetOffsetPosition(zero)
  558. * and dGeomSetOffsetRotation(identiy), because this function actually
  559. * eliminates the offset, rather than leaving it as the identity transform.
  560. *
  561. * @param geom the geom to have its offset destroyed.
  562. * @ingroup collide
  563. */
  564. ODE_API void dGeomClearOffset(dGeomID geom);
  565. /**
  566. * @brief Check to see whether the geom has an offset.
  567. *
  568. * This function will return non-zero if the offset has been created.
  569. * Note that there is a difference between a geom with no offset,
  570. * and a geom with an offset that is the identity transform.
  571. * In the latter case, although the observed behaviour is identical,
  572. * there is a unnecessary computation involved because the geom will
  573. * be applying the transform whenever it needs to recalculate its world
  574. * position.
  575. *
  576. * @param geom the geom to query.
  577. * @returns Non-zero if the geom has an offset, zero otherwise.
  578. * @ingroup collide
  579. */
  580. ODE_API int dGeomIsOffset(dGeomID geom);
  581. /**
  582. * @brief Get the offset position vector of a geom.
  583. *
  584. * Returns the positional offset of the geom in local coordinates.
  585. * If the geom has no offset, this function returns the zero vector.
  586. *
  587. * @param geom the geom to query.
  588. * @returns A pointer to the geom's offset vector.
  589. * @remarks The returned value is a pointer to the geom's internal
  590. * data structure. It is valid until any changes are made
  591. * to the geom.
  592. * @ingroup collide
  593. */
  594. ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
  595. /**
  596. * @brief Copy the offset position vector of a geom.
  597. *
  598. * Returns the positional offset of the geom in local coordinates.
  599. * If the geom has no offset, this function returns the zero vector.
  600. *
  601. * @param geom the geom to query.
  602. * @param pos returns the offset position
  603. * @ingroup collide
  604. */
  605. ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos);
  606. /**
  607. * @brief Get the offset rotation matrix of a geom.
  608. *
  609. * Returns the rotational offset of the geom in local coordinates.
  610. * If the geom has no offset, this function returns the identity
  611. * matrix.
  612. *
  613. * @param geom the geom to query.
  614. * @returns A pointer to the geom's offset rotation matrix.
  615. * @remarks The returned value is a pointer to the geom's internal
  616. * data structure. It is valid until any changes are made
  617. * to the geom.
  618. * @ingroup collide
  619. */
  620. ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
  621. /**
  622. * @brief Copy the offset rotation matrix of a geom.
  623. *
  624. * Returns the rotational offset of the geom in local coordinates.
  625. * If the geom has no offset, this function returns the identity
  626. * matrix.
  627. *
  628. * @param geom the geom to query.
  629. * @param R returns the rotation matrix.
  630. * @ingroup collide
  631. */
  632. ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R);
  633. /**
  634. * @brief Get the offset rotation quaternion of a geom.
  635. *
  636. * Returns the rotation offset of the geom as a quaternion.
  637. * If the geom has no offset, the identity quaternion is returned.
  638. *
  639. * @param geom the geom to query.
  640. * @param result a copy of the rotation quaternion.
  641. * @ingroup collide
  642. */
  643. ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
  644. /* ************************************************************************ */
  645. /* collision detection */
  646. /*
  647. * Just generate any contacts (disables any contact refining).
  648. */
  649. #define CONTACTS_UNIMPORTANT 0x80000000
  650. /**
  651. *
  652. * @brief Given two geoms o1 and o2 that potentially intersect,
  653. * generate contact information for them.
  654. *
  655. * Internally, this just calls the correct class-specific collision
  656. * functions for o1 and o2.
  657. *
  658. * @param o1 The first geom to test.
  659. * @param o2 The second geom to test.
  660. *
  661. * @param flags The flags specify how contacts should be generated if
  662. * the geoms touch. The lower 16 bits of flags is an integer that
  663. * specifies the maximum number of contact points to generate. You must
  664. * ask for at least one contact.
  665. * Additionally, following bits may be set:
  666. * CONTACTS_UNIMPORTANT -- just generate any contacts (skip contact refining).
  667. * All other bits in flags must be set to zero. In the future the other bits
  668. * may be used to select from different contact generation strategies.
  669. *
  670. * @param contact Points to an array of dContactGeom structures. The array
  671. * must be able to hold at least the maximum number of contacts. These
  672. * dContactGeom structures may be embedded within larger structures in the
  673. * array -- the skip parameter is the byte offset from one dContactGeom to
  674. * the next in the array. If skip is sizeof(dContactGeom) then contact
  675. * points to a normal (C-style) array. It is an error for skip to be smaller
  676. * than sizeof(dContactGeom).
  677. *
  678. * @returns If the geoms intersect, this function returns the number of contact
  679. * points generated (and updates the contact array), otherwise it returns 0
  680. * (and the contact array is not touched).
  681. *
  682. * @remarks If a space is passed as o1 or o2 then this function will collide
  683. * all objects contained in o1 with all objects contained in o2, and return
  684. * the resulting contact points. This method for colliding spaces with geoms
  685. * (or spaces with spaces) provides no user control over the individual
  686. * collisions. To get that control, use dSpaceCollide or dSpaceCollide2 instead.
  687. *
  688. * @remarks If o1 and o2 are the same geom then this function will do nothing
  689. * and return 0. Technically speaking an object intersects with itself, but it
  690. * is not useful to find contact points in this case.
  691. *
  692. * @remarks This function does not care if o1 and o2 are in the same space or not
  693. * (or indeed if they are in any space at all).
  694. *
  695. * @ingroup collide
  696. */
  697. ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
  698. int skip);
  699. /**
  700. * @brief Determines which pairs of geoms in a space may potentially intersect,
  701. * and calls the callback function for each candidate pair.
  702. *
  703. * @param space The space to test.
  704. *
  705. * @param data Passed from dSpaceCollide directly to the callback
  706. * function. Its meaning is user defined. The o1 and o2 arguments are the
  707. * geoms that may be near each other.
  708. *
  709. * @param callback A callback function is of type @ref dNearCallback.
  710. *
  711. * @remarks Other spaces that are contained within the colliding space are
  712. * not treated specially, i.e. they are not recursed into. The callback
  713. * function may be passed these contained spaces as one or both geom
  714. * arguments.
  715. *
  716. * @remarks dSpaceCollide() is guaranteed to pass all intersecting geom
  717. * pairs to the callback function, but may also pass close but
  718. * non-intersecting pairs. The number of these calls depends on the
  719. * internal algorithms used by the space. Thus you should not expect
  720. * that dCollide will return contacts for every pair passed to the
  721. * callback.
  722. *
  723. * @sa dSpaceCollide2
  724. * @ingroup collide
  725. */
  726. ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
  727. /**
  728. * @brief Determines which geoms from one space may potentially intersect with
  729. * geoms from another space, and calls the callback function for each candidate
  730. * pair.
  731. *
  732. * @param space1 The first space to test.
  733. *
  734. * @param space2 The second space to test.
  735. *
  736. * @param data Passed from dSpaceCollide directly to the callback
  737. * function. Its meaning is user defined. The o1 and o2 arguments are the
  738. * geoms that may be near each other.
  739. *
  740. * @param callback A callback function is of type @ref dNearCallback.
  741. *
  742. * @remarks This function can also test a single non-space geom against a
  743. * space. This function is useful when there is a collision hierarchy, i.e.
  744. * when there are spaces that contain other spaces.
  745. *
  746. * @remarks Other spaces that are contained within the colliding space are
  747. * not treated specially, i.e. they are not recursed into. The callback
  748. * function may be passed these contained spaces as one or both geom
  749. * arguments.
  750. *
  751. * @remarks Sublevel value of space affects how the spaces are iterated.
  752. * Both spaces are recursed only if their sublevels match. Otherwise, only
  753. * the space with greater sublevel is recursed and the one with lesser sublevel
  754. * is used as a geom itself.
  755. *
  756. * @remarks dSpaceCollide2() is guaranteed to pass all intersecting geom
  757. * pairs to the callback function, but may also pass close but
  758. * non-intersecting pairs. The number of these calls depends on the
  759. * internal algorithms used by the space. Thus you should not expect
  760. * that dCollide will return contacts for every pair passed to the
  761. * callback.
  762. *
  763. * @sa dSpaceCollide
  764. * @sa dSpaceSetSublevel
  765. * @ingroup collide
  766. */
  767. ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
  768. /* ************************************************************************ */
  769. /* standard classes */
  770. /* the maximum number of user classes that are supported */
  771. enum {
  772. dMaxUserClasses = 4
  773. };
  774. /* class numbers - each geometry object needs a unique number */
  775. enum {
  776. dSphereClass = 0,
  777. dBoxClass,
  778. dCapsuleClass,
  779. dCylinderClass,
  780. dPlaneClass,
  781. dRayClass,
  782. dConvexClass,
  783. dGeomTransformClass,
  784. dTriMeshClass,
  785. dHeightfieldClass,
  786. dFirstSpaceClass,
  787. dSimpleSpaceClass = dFirstSpaceClass,
  788. dHashSpaceClass,
  789. dSweepAndPruneSpaceClass, /* SAP */
  790. dQuadTreeSpaceClass,
  791. dLastSpaceClass = dQuadTreeSpaceClass,
  792. dFirstUserClass,
  793. dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
  794. dGeomNumClasses
  795. };
  796. /**
  797. * @defgroup collide_sphere Sphere Class
  798. * @ingroup collide
  799. */
  800. /**
  801. * @brief Create a sphere geom of the given radius, and return its ID.
  802. *
  803. * @param space a space to contain the new geom. May be null.
  804. * @param radius the radius of the sphere.
  805. *
  806. * @returns A new sphere geom.
  807. *
  808. * @remarks The point of reference for a sphere is its center.
  809. *
  810. * @sa dGeomDestroy
  811. * @sa dGeomSphereSetRadius
  812. * @ingroup collide_sphere
  813. */
  814. ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
  815. /**
  816. * @brief Set the radius of a sphere geom.
  817. *
  818. * @param sphere the sphere to set.
  819. * @param radius the new radius.
  820. *
  821. * @sa dGeomSphereGetRadius
  822. * @ingroup collide_sphere
  823. */
  824. ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
  825. /**
  826. * @brief Retrieves the radius of a sphere geom.
  827. *
  828. * @param sphere the sphere to query.
  829. *
  830. * @sa dGeomSphereSetRadius
  831. * @ingroup collide_sphere
  832. */
  833. ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
  834. /**
  835. * @brief Calculate the depth of the a given point within a sphere.
  836. *
  837. * @param sphere the sphere to query.
  838. * @param x the X coordinate of the point.
  839. * @param y the Y coordinate of the point.
  840. * @param z the Z coordinate of the point.
  841. *
  842. * @returns The depth of the point. Points inside the sphere will have a
  843. * positive depth, points outside it will have a negative depth, and points
  844. * on the surface will have a depth of zero.
  845. *
  846. * @ingroup collide_sphere
  847. */
  848. ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
  849. /*--> Convex Functions*/
  850. ODE_API dGeomID dCreateConvex (dSpaceID space,
  851. dReal *_planes,
  852. unsigned int _planecount,
  853. dReal *_points,
  854. unsigned int _pointcount,unsigned int *_polygons);
  855. ODE_API void dGeomSetConvex (dGeomID g,
  856. dReal *_planes,
  857. unsigned int _count,
  858. dReal *_points,
  859. unsigned int _pointcount,unsigned int *_polygons);
  860. /*<-- Convex Functions*/
  861. /**
  862. * @defgroup collide_box Box Class
  863. * @ingroup collide
  864. */
  865. /**
  866. * @brief Create a box geom with the provided side lengths.
  867. *
  868. * @param space a space to contain the new geom. May be null.
  869. * @param lx the length of the box along the X axis
  870. * @param ly the length of the box along the Y axis
  871. * @param lz the length of the box along the Z axis
  872. *
  873. * @returns A new box geom.
  874. *
  875. * @remarks The point of reference for a box is its center.
  876. *
  877. * @sa dGeomDestroy
  878. * @sa dGeomBoxSetLengths
  879. * @ingroup collide_box
  880. */
  881. ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
  882. /**
  883. * @brief Set the side lengths of the given box.
  884. *
  885. * @param box the box to set
  886. * @param lx the length of the box along the X axis
  887. * @param ly the length of the box along the Y axis
  888. * @param lz the length of the box along the Z axis
  889. *
  890. * @sa dGeomBoxGetLengths
  891. * @ingroup collide_box
  892. */
  893. ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
  894. /**
  895. * @brief Get the side lengths of a box.
  896. *
  897. * @param box the box to query
  898. * @param result the returned side lengths
  899. *
  900. * @sa dGeomBoxSetLengths
  901. * @ingroup collide_box
  902. */
  903. ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
  904. /**
  905. * @brief Return the depth of a point in a box.
  906. *
  907. * @param box the box to query
  908. * @param x the X coordinate of the point to test.
  909. * @param y the Y coordinate of the point to test.
  910. * @param z the Z coordinate of the point to test.
  911. *
  912. * @returns The depth of the point. Points inside the box will have a
  913. * positive depth, points outside it will have a negative depth, and points
  914. * on the surface will have a depth of zero.
  915. */
  916. ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
  917. ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
  918. ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
  919. ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
  920. ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
  921. ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
  922. ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
  923. ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
  924. ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
  925. /* For now we want to have a backwards compatible C-API, note: C++ API is not.*/
  926. #define dCreateCCylinder dCreateCapsule
  927. #define dGeomCCylinderSetParams dGeomCapsuleSetParams
  928. #define dGeomCCylinderGetParams dGeomCapsuleGetParams
  929. #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
  930. #define dCCylinderClass dCapsuleClass
  931. ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
  932. ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
  933. ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
  934. ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
  935. ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
  936. ODE_API dReal dGeomRayGetLength (dGeomID ray);
  937. ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
  938. dReal dx, dReal dy, dReal dz);
  939. ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
  940. /*
  941. * Set/get ray flags that influence ray collision detection.
  942. * These flags are currently only noticed by the trimesh collider, because
  943. * they can make a major differences there.
  944. */
  945. ODE_API_DEPRECATED ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
  946. ODE_API_DEPRECATED ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
  947. ODE_API void dGeomRaySetFirstContact (dGeomID g, int firstContact);
  948. ODE_API int dGeomRayGetFirstContact (dGeomID g);
  949. ODE_API void dGeomRaySetBackfaceCull (dGeomID g, int backfaceCull);
  950. ODE_API int dGeomRayGetBackfaceCull (dGeomID g);
  951. ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
  952. ODE_API int dGeomRayGetClosestHit (dGeomID g);
  953. #include "collision_trimesh.h"
  954. ODE_API_DEPRECATED ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
  955. ODE_API_DEPRECATED ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
  956. ODE_API_DEPRECATED ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
  957. ODE_API_DEPRECATED ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
  958. ODE_API_DEPRECATED ODE_API int dGeomTransformGetCleanup (dGeomID g);
  959. ODE_API_DEPRECATED ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
  960. ODE_API_DEPRECATED ODE_API int dGeomTransformGetInfo (dGeomID g);
  961. /* ************************************************************************ */
  962. /* heightfield functions */
  963. /* Data storage for heightfield data.*/
  964. struct dxHeightfieldData;
  965. typedef struct dxHeightfieldData* dHeightfieldDataID;
  966. /**
  967. * @brief Callback prototype
  968. *
  969. * Used by the callback heightfield data type to sample a height for a
  970. * given cell position.
  971. *
  972. * @param p_user_data User data specified when creating the dHeightfieldDataID
  973. * @param x The index of a sample in the local x axis. It is a value
  974. * in the range zero to ( nWidthSamples - 1 ).
  975. * @param x The index of a sample in the local z axis. It is a value
  976. * in the range zero to ( nDepthSamples - 1 ).
  977. *
  978. * @return The sample height which is then scaled and offset using the
  979. * values specified when the heightfield data was created.
  980. *
  981. * @ingroup collide
  982. */
  983. typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
  984. /**
  985. * @brief Creates a heightfield geom.
  986. *
  987. * Uses the information in the given dHeightfieldDataID to construct
  988. * a geom representing a heightfield in a collision space.
  989. *
  990. * @param space The space to add the geom to.
  991. * @param data The dHeightfieldDataID created by dGeomHeightfieldDataCreate and
  992. * setup by dGeomHeightfieldDataBuildCallback, dGeomHeightfieldDataBuildByte,
  993. * dGeomHeightfieldDataBuildShort or dGeomHeightfieldDataBuildFloat.
  994. * @param bPlaceable If non-zero this geom can be transformed in the world using the
  995. * usual functions such as dGeomSetPosition and dGeomSetRotation. If the geom is
  996. * not set as placeable, then it uses a fixed orientation where the global y axis
  997. * represents the dynamic 'height' of the heightfield.
  998. *
  999. * @return A geom id to reference this geom in other calls.
  1000. *
  1001. * @ingroup collide
  1002. */
  1003. ODE_API dGeomID dCreateHeightfield( dSpaceID space,
  1004. dHeightfieldDataID data, int bPlaceable );
  1005. /**
  1006. * @brief Creates a new empty dHeightfieldDataID.
  1007. *
  1008. * Allocates a new dHeightfieldDataID and returns it. You must call
  1009. * dGeomHeightfieldDataDestroy to destroy it after the geom has been removed.
  1010. * The dHeightfieldDataID value is used when specifying a data format type.
  1011. *
  1012. * @return A dHeightfieldDataID for use with dGeomHeightfieldDataBuildCallback,
  1013. * dGeomHeightfieldDataBuildByte, dGeomHeightfieldDataBuildShort or
  1014. * dGeomHeightfieldDataBuildFloat.
  1015. * @ingroup collide
  1016. */
  1017. ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void);
  1018. /**
  1019. * @brief Destroys a dHeightfieldDataID.
  1020. *
  1021. * Deallocates a given dHeightfieldDataID and all managed resources.
  1022. *
  1023. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1024. * @ingroup collide
  1025. */
  1026. ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
  1027. /**
  1028. * @brief Configures a dHeightfieldDataID to use a callback to
  1029. * retrieve height data.
  1030. *
  1031. * Before a dHeightfieldDataID can be used by a geom it must be
  1032. * configured to specify the format of the height data.
  1033. * This call specifies that the heightfield data is computed by
  1034. * the user and it should use the given callback when determining
  1035. * the height of a given element of it's shape.
  1036. *
  1037. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1038. *
  1039. * @param width Specifies the total 'width' of the heightfield along
  1040. * the geom's local x axis.
  1041. * @param depth Specifies the total 'depth' of the heightfield along
  1042. * the geom's local z axis.
  1043. *
  1044. * @param widthSamples Specifies the number of vertices to sample
  1045. * along the width of the heightfield. Each vertex has a corresponding
  1046. * height value which forms the overall shape.
  1047. * Naturally this value must be at least two or more.
  1048. * @param depthSamples Specifies the number of vertices to sample
  1049. * along the depth of the heightfield.
  1050. *
  1051. * @param scale A uniform scale applied to all raw height data.
  1052. * @param offset An offset applied to the scaled height data.
  1053. *
  1054. * @param thickness A value subtracted from the lowest height
  1055. * value which in effect adds an additional cuboid to the base of the
  1056. * heightfield. This is used to prevent geoms from looping under the
  1057. * desired terrain and not registering as a collision. Note that the
  1058. * thickness is not affected by the scale or offset parameters.
  1059. *
  1060. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1061. * directions along the local x and z axes. If zero the heightfield is
  1062. * bounded from zero to width in the local x axis, and zero to depth in
  1063. * the local z axis.
  1064. *
  1065. * @ingroup collide
  1066. */
  1067. ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
  1068. void* pUserData, dHeightfieldGetHeight* pCallback,
  1069. dReal width, dReal depth, int widthSamples, int depthSamples,
  1070. dReal scale, dReal offset, dReal thickness, int bWrap );
  1071. /**
  1072. * @brief Configures a dHeightfieldDataID to use height data in byte format.
  1073. *
  1074. * Before a dHeightfieldDataID can be used by a geom it must be
  1075. * configured to specify the format of the height data.
  1076. * This call specifies that the heightfield data is stored as a rectangular
  1077. * array of bytes (8 bit unsigned) representing the height at each sample point.
  1078. *
  1079. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1080. *
  1081. * @param pHeightData A pointer to the height data.
  1082. * @param bCopyHeightData When non-zero the height data is copied to an
  1083. * internal store. When zero the height data is accessed by reference and
  1084. * so must persist throughout the lifetime of the heightfield.
  1085. *
  1086. * @param width Specifies the total 'width' of the heightfield along
  1087. * the geom's local x axis.
  1088. * @param depth Specifies the total 'depth' of the heightfield along
  1089. * the geom's local z axis.
  1090. *
  1091. * @param widthSamples Specifies the number of vertices to sample
  1092. * along the width of the heightfield. Each vertex has a corresponding
  1093. * height value which forms the overall shape.
  1094. * Naturally this value must be at least two or more.
  1095. * @param depthSamples Specifies the number of vertices to sample
  1096. * along the depth of the heightfield.
  1097. *
  1098. * @param scale A uniform scale applied to all raw height data.
  1099. * @param offset An offset applied to the scaled height data.
  1100. *
  1101. * @param thickness A value subtracted from the lowest height
  1102. * value which in effect adds an additional cuboid to the base of the
  1103. * heightfield. This is used to prevent geoms from looping under the
  1104. * desired terrain and not registering as a collision. Note that the
  1105. * thickness is not affected by the scale or offset parameters.
  1106. *
  1107. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1108. * directions along the local x and z axes. If zero the heightfield is
  1109. * bounded from zero to width in the local x axis, and zero to depth in
  1110. * the local z axis.
  1111. *
  1112. * @ingroup collide
  1113. */
  1114. ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
  1115. const unsigned char* pHeightData, int bCopyHeightData,
  1116. dReal width, dReal depth, int widthSamples, int depthSamples,
  1117. dReal scale, dReal offset, dReal thickness, int bWrap );
  1118. /**
  1119. * @brief Configures a dHeightfieldDataID to use height data in short format.
  1120. *
  1121. * Before a dHeightfieldDataID can be used by a geom it must be
  1122. * configured to specify the format of the height data.
  1123. * This call specifies that the heightfield data is stored as a rectangular
  1124. * array of shorts (16 bit signed) representing the height at each sample point.
  1125. *
  1126. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1127. *
  1128. * @param pHeightData A pointer to the height data.
  1129. * @param bCopyHeightData When non-zero the height data is copied to an
  1130. * internal store. When zero the height data is accessed by reference and
  1131. * so must persist throughout the lifetime of the heightfield.
  1132. *
  1133. * @param width Specifies the total 'width' of the heightfield along
  1134. * the geom's local x axis.
  1135. * @param depth Specifies the total 'depth' of the heightfield along
  1136. * the geom's local z axis.
  1137. *
  1138. * @param widthSamples Specifies the number of vertices to sample
  1139. * along the width of the heightfield. Each vertex has a corresponding
  1140. * height value which forms the overall shape.
  1141. * Naturally this value must be at least two or more.
  1142. * @param depthSamples Specifies the number of vertices to sample
  1143. * along the depth of the heightfield.
  1144. *
  1145. * @param scale A uniform scale applied to all raw height data.
  1146. * @param offset An offset applied to the scaled height data.
  1147. *
  1148. * @param thickness A value subtracted from the lowest height
  1149. * value which in effect adds an additional cuboid to the base of the
  1150. * heightfield. This is used to prevent geoms from looping under the
  1151. * desired terrain and not registering as a collision. Note that the
  1152. * thickness is not affected by the scale or offset parameters.
  1153. *
  1154. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1155. * directions along the local x and z axes. If zero the heightfield is
  1156. * bounded from zero to width in the local x axis, and zero to depth in
  1157. * the local z axis.
  1158. *
  1159. * @ingroup collide
  1160. */
  1161. ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
  1162. const short* pHeightData, int bCopyHeightData,
  1163. dReal width, dReal depth, int widthSamples, int depthSamples,
  1164. dReal scale, dReal offset, dReal thickness, int bWrap );
  1165. /**
  1166. * @brief Configures a dHeightfieldDataID to use height data in
  1167. * single precision floating point format.
  1168. *
  1169. * Before a dHeightfieldDataID can be used by a geom it must be
  1170. * configured to specify the format of the height data.
  1171. * This call specifies that the heightfield data is stored as a rectangular
  1172. * array of single precision floats representing the height at each
  1173. * sample point.
  1174. *
  1175. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1176. *
  1177. * @param pHeightData A pointer to the height data.
  1178. * @param bCopyHeightData When non-zero the height data is copied to an
  1179. * internal store. When zero the height data is accessed by reference and
  1180. * so must persist throughout the lifetime of the heightfield.
  1181. *
  1182. * @param width Specifies the total 'width' of the heightfield along
  1183. * the geom's local x axis.
  1184. * @param depth Specifies the total 'depth' of the heightfield along
  1185. * the geom's local z axis.
  1186. *
  1187. * @param widthSamples Specifies the number of vertices to sample
  1188. * along the width of the heightfield. Each vertex has a corresponding
  1189. * height value which forms the overall shape.
  1190. * Naturally this value must be at least two or more.
  1191. * @param depthSamples Specifies the number of vertices to sample
  1192. * along the depth of the heightfield.
  1193. *
  1194. * @param scale A uniform scale applied to all raw height data.
  1195. * @param offset An offset applied to the scaled height data.
  1196. *
  1197. * @param thickness A value subtracted from the lowest height
  1198. * value which in effect adds an additional cuboid to the base of the
  1199. * heightfield. This is used to prevent geoms from looping under the
  1200. * desired terrain and not registering as a collision. Note that the
  1201. * thickness is not affected by the scale or offset parameters.
  1202. *
  1203. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1204. * directions along the local x and z axes. If zero the heightfield is
  1205. * bounded from zero to width in the local x axis, and zero to depth in
  1206. * the local z axis.
  1207. *
  1208. * @ingroup collide
  1209. */
  1210. ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
  1211. const float* pHeightData, int bCopyHeightData,
  1212. dReal width, dReal depth, int widthSamples, int depthSamples,
  1213. dReal scale, dReal offset, dReal thickness, int bWrap );
  1214. /**
  1215. * @brief Configures a dHeightfieldDataID to use height data in
  1216. * double precision floating point format.
  1217. *
  1218. * Before a dHeightfieldDataID can be used by a geom it must be
  1219. * configured to specify the format of the height data.
  1220. * This call specifies that the heightfield data is stored as a rectangular
  1221. * array of double precision floats representing the height at each
  1222. * sample point.
  1223. *
  1224. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1225. *
  1226. * @param pHeightData A pointer to the height data.
  1227. * @param bCopyHeightData When non-zero the height data is copied to an
  1228. * internal store. When zero the height data is accessed by reference and
  1229. * so must persist throughout the lifetime of the heightfield.
  1230. *
  1231. * @param width Specifies the total 'width' of the heightfield along
  1232. * the geom's local x axis.
  1233. * @param depth Specifies the total 'depth' of the heightfield along
  1234. * the geom's local z axis.
  1235. *
  1236. * @param widthSamples Specifies the number of vertices to sample
  1237. * along the width of the heightfield. Each vertex has a corresponding
  1238. * height value which forms the overall shape.
  1239. * Naturally this value must be at least two or more.
  1240. * @param depthSamples Specifies the number of vertices to sample
  1241. * along the depth of the heightfield.
  1242. *
  1243. * @param scale A uniform scale applied to all raw height data.
  1244. * @param offset An offset applied to the scaled height data.
  1245. *
  1246. * @param thickness A value subtracted from the lowest height
  1247. * value which in effect adds an additional cuboid to the base of the
  1248. * heightfield. This is used to prevent geoms from looping under the
  1249. * desired terrain and not registering as a collision. Note that the
  1250. * thickness is not affected by the scale or offset parameters.
  1251. *
  1252. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1253. * directions along the local x and z axes. If zero the heightfield is
  1254. * bounded from zero to width in the local x axis, and zero to depth in
  1255. * the local z axis.
  1256. *
  1257. * @ingroup collide
  1258. */
  1259. ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
  1260. const double* pHeightData, int bCopyHeightData,
  1261. dReal width, dReal depth, int widthSamples, int depthSamples,
  1262. dReal scale, dReal offset, dReal thickness, int bWrap );
  1263. /**
  1264. * @brief Manually set the minimum and maximum height bounds.
  1265. *
  1266. * This call allows you to set explicit min / max values after initial
  1267. * creation typically for callback heightfields which default to +/- infinity,
  1268. * or those whose data has changed. This must be set prior to binding with a
  1269. * geom, as the the AABB is not recomputed after it's first generation.
  1270. *
  1271. * @remarks The minimum and maximum values are used to compute the AABB
  1272. * for the heightfield which is used for early rejection of collisions.
  1273. * A close fit will yield a more efficient collision check.
  1274. *
  1275. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1276. * @param min_height The new minimum height value. Scale, offset and thickness is then applied.
  1277. * @param max_height The new maximum height value. Scale and offset is then applied.
  1278. * @ingroup collide
  1279. */
  1280. ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
  1281. dReal minHeight, dReal maxHeight );
  1282. /**
  1283. * @brief Assigns a dHeightfieldDataID to a heightfield geom.
  1284. *
  1285. * Associates the given dHeightfieldDataID with a heightfield geom.
  1286. * This is done without affecting the GEOM_PLACEABLE flag.
  1287. *
  1288. * @param g A geom created by dCreateHeightfield
  1289. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1290. * @ingroup collide
  1291. */
  1292. ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
  1293. /**
  1294. * @brief Gets the dHeightfieldDataID bound to a heightfield geom.
  1295. *
  1296. * Returns the dHeightfieldDataID associated with a heightfield geom.
  1297. *
  1298. * @param g A geom created by dCreateHeightfield
  1299. * @return The dHeightfieldDataID which may be NULL if none was assigned.
  1300. * @ingroup collide
  1301. */
  1302. ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
  1303. /* ************************************************************************ */
  1304. /* utility functions */
  1305. ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
  1306. const dVector3 b1, const dVector3 b2,
  1307. dVector3 cp1, dVector3 cp2);
  1308. ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
  1309. const dVector3 side1, const dVector3 _p2,
  1310. const dMatrix3 R2, const dVector3 side2);
  1311. /* The meaning of flags parameter is the same as in dCollide()*/
  1312. ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
  1313. const dVector3 side1, const dVector3 p2,
  1314. const dMatrix3 R2, const dVector3 side2,
  1315. dVector3 normal, dReal *depth, int *return_code,
  1316. int flags, dContactGeom *contact, int skip);
  1317. ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
  1318. /* ************************************************************************ */
  1319. /* custom classes */
  1320. typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
  1321. typedef int dColliderFn (dGeomID o1, dGeomID o2,
  1322. int flags, dContactGeom *contact, int skip);
  1323. typedef dColliderFn * dGetColliderFnFn (int num);
  1324. typedef void dGeomDtorFn (dGeomID o);
  1325. typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
  1326. typedef struct dGeomClass {
  1327. int bytes;
  1328. dGetColliderFnFn *collider;
  1329. dGetAABBFn *aabb;
  1330. dAABBTestFn *aabb_test;
  1331. dGeomDtorFn *dtor;
  1332. } dGeomClass;
  1333. ODE_API int dCreateGeomClass (const dGeomClass *classptr);
  1334. ODE_API void * dGeomGetClassData (dGeomID);
  1335. ODE_API dGeomID dCreateGeom (int classnum);
  1336. /**
  1337. * @brief Sets a custom collider function for two geom classes.
  1338. *
  1339. * @param i The first geom class handled by this collider
  1340. * @param j The second geom class handled by this collider
  1341. * @param fn The collider function to use to determine collisions.
  1342. * @ingroup collide
  1343. */
  1344. ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn);
  1345. /* ************************************************************************ */
  1346. #ifdef __cplusplus
  1347. }
  1348. #endif
  1349. #endif