collision.h 48 KB

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