collision.h 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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. const dReal *_planes,
  852. unsigned int _planecount,
  853. const dReal *_points,
  854. unsigned int _pointcount,
  855. const unsigned int *_polygons);
  856. ODE_API void dGeomSetConvex (dGeomID g,
  857. const dReal *_planes,
  858. unsigned int _count,
  859. const dReal *_points,
  860. unsigned int _pointcount,
  861. const unsigned int *_polygons);
  862. /*<-- Convex Functions*/
  863. /**
  864. * @defgroup collide_box Box Class
  865. * @ingroup collide
  866. */
  867. /**
  868. * @brief Create a box geom with the provided side lengths.
  869. *
  870. * @param space a space to contain the new geom. May be null.
  871. * @param lx the length of the box along the X axis
  872. * @param ly the length of the box along the Y axis
  873. * @param lz the length of the box along the Z axis
  874. *
  875. * @returns A new box geom.
  876. *
  877. * @remarks The point of reference for a box is its center.
  878. *
  879. * @sa dGeomDestroy
  880. * @sa dGeomBoxSetLengths
  881. * @ingroup collide_box
  882. */
  883. ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
  884. /**
  885. * @brief Set the side lengths of the given box.
  886. *
  887. * @param box the box to set
  888. * @param lx the length of the box along the X axis
  889. * @param ly the length of the box along the Y axis
  890. * @param lz the length of the box along the Z axis
  891. *
  892. * @sa dGeomBoxGetLengths
  893. * @ingroup collide_box
  894. */
  895. ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
  896. /**
  897. * @brief Get the side lengths of a box.
  898. *
  899. * @param box the box to query
  900. * @param result the returned side lengths
  901. *
  902. * @sa dGeomBoxSetLengths
  903. * @ingroup collide_box
  904. */
  905. ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
  906. /**
  907. * @brief Return the depth of a point in a box.
  908. *
  909. * @param box the box to query
  910. * @param x the X coordinate of the point to test.
  911. * @param y the Y coordinate of the point to test.
  912. * @param z the Z coordinate of the point to test.
  913. *
  914. * @returns The depth of the point. Points inside the box will have a
  915. * positive depth, points outside it will have a negative depth, and points
  916. * on the surface will have a depth of zero.
  917. */
  918. ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
  919. ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
  920. ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
  921. ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
  922. ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
  923. ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
  924. ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
  925. ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
  926. ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
  927. /* For now we want to have a backwards compatible C-API, note: C++ API is not.*/
  928. #define dCreateCCylinder dCreateCapsule
  929. #define dGeomCCylinderSetParams dGeomCapsuleSetParams
  930. #define dGeomCCylinderGetParams dGeomCapsuleGetParams
  931. #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
  932. #define dCCylinderClass dCapsuleClass
  933. ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
  934. ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
  935. ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
  936. ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
  937. ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
  938. ODE_API dReal dGeomRayGetLength (dGeomID ray);
  939. ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
  940. dReal dx, dReal dy, dReal dz);
  941. ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
  942. /*
  943. * Set/get ray flags that influence ray collision detection.
  944. * These flags are currently only noticed by the trimesh collider, because
  945. * they can make a major differences there.
  946. */
  947. ODE_API_DEPRECATED ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
  948. ODE_API_DEPRECATED ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
  949. ODE_API void dGeomRaySetFirstContact (dGeomID g, int firstContact);
  950. ODE_API int dGeomRayGetFirstContact (dGeomID g);
  951. ODE_API void dGeomRaySetBackfaceCull (dGeomID g, int backfaceCull);
  952. ODE_API int dGeomRayGetBackfaceCull (dGeomID g);
  953. ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
  954. ODE_API int dGeomRayGetClosestHit (dGeomID g);
  955. #include "collision_trimesh.h"
  956. ODE_API_DEPRECATED ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
  957. ODE_API_DEPRECATED ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
  958. ODE_API_DEPRECATED ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
  959. ODE_API_DEPRECATED ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
  960. ODE_API_DEPRECATED ODE_API int dGeomTransformGetCleanup (dGeomID g);
  961. ODE_API_DEPRECATED ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
  962. ODE_API_DEPRECATED ODE_API int dGeomTransformGetInfo (dGeomID g);
  963. /* ************************************************************************ */
  964. /* heightfield functions */
  965. /* Data storage for heightfield data.*/
  966. struct dxHeightfieldData;
  967. typedef struct dxHeightfieldData* dHeightfieldDataID;
  968. /**
  969. * @brief Callback prototype
  970. *
  971. * Used by the callback heightfield data type to sample a height for a
  972. * given cell position.
  973. *
  974. * @param p_user_data User data specified when creating the dHeightfieldDataID
  975. * @param x The index of a sample in the local x axis. It is a value
  976. * in the range zero to ( nWidthSamples - 1 ).
  977. * @param x The index of a sample in the local z axis. It is a value
  978. * in the range zero to ( nDepthSamples - 1 ).
  979. *
  980. * @return The sample height which is then scaled and offset using the
  981. * values specified when the heightfield data was created.
  982. *
  983. * @ingroup collide
  984. */
  985. typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
  986. /**
  987. * @brief Creates a heightfield geom.
  988. *
  989. * Uses the information in the given dHeightfieldDataID to construct
  990. * a geom representing a heightfield in a collision space.
  991. *
  992. * @param space The space to add the geom to.
  993. * @param data The dHeightfieldDataID created by dGeomHeightfieldDataCreate and
  994. * setup by dGeomHeightfieldDataBuildCallback, dGeomHeightfieldDataBuildByte,
  995. * dGeomHeightfieldDataBuildShort or dGeomHeightfieldDataBuildFloat.
  996. * @param bPlaceable If non-zero this geom can be transformed in the world using the
  997. * usual functions such as dGeomSetPosition and dGeomSetRotation. If the geom is
  998. * not set as placeable, then it uses a fixed orientation where the global y axis
  999. * represents the dynamic 'height' of the heightfield.
  1000. *
  1001. * @return A geom id to reference this geom in other calls.
  1002. *
  1003. * @ingroup collide
  1004. */
  1005. ODE_API dGeomID dCreateHeightfield( dSpaceID space,
  1006. dHeightfieldDataID data, int bPlaceable );
  1007. /**
  1008. * @brief Creates a new empty dHeightfieldDataID.
  1009. *
  1010. * Allocates a new dHeightfieldDataID and returns it. You must call
  1011. * dGeomHeightfieldDataDestroy to destroy it after the geom has been removed.
  1012. * The dHeightfieldDataID value is used when specifying a data format type.
  1013. *
  1014. * @return A dHeightfieldDataID for use with dGeomHeightfieldDataBuildCallback,
  1015. * dGeomHeightfieldDataBuildByte, dGeomHeightfieldDataBuildShort or
  1016. * dGeomHeightfieldDataBuildFloat.
  1017. * @ingroup collide
  1018. */
  1019. ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void);
  1020. /**
  1021. * @brief Destroys a dHeightfieldDataID.
  1022. *
  1023. * Deallocates a given dHeightfieldDataID and all managed resources.
  1024. *
  1025. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1026. * @ingroup collide
  1027. */
  1028. ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
  1029. /**
  1030. * @brief Configures a dHeightfieldDataID to use a callback to
  1031. * retrieve height data.
  1032. *
  1033. * Before a dHeightfieldDataID can be used by a geom it must be
  1034. * configured to specify the format of the height data.
  1035. * This call specifies that the heightfield data is computed by
  1036. * the user and it should use the given callback when determining
  1037. * the height of a given element of it's shape.
  1038. *
  1039. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1040. *
  1041. * @param width Specifies the total 'width' of the heightfield along
  1042. * the geom's local x axis.
  1043. * @param depth Specifies the total 'depth' of the heightfield along
  1044. * the geom's local z axis.
  1045. *
  1046. * @param widthSamples Specifies the number of vertices to sample
  1047. * along the width of the heightfield. Each vertex has a corresponding
  1048. * height value which forms the overall shape.
  1049. * Naturally this value must be at least two or more.
  1050. * @param depthSamples Specifies the number of vertices to sample
  1051. * along the depth of the heightfield.
  1052. *
  1053. * @param scale A uniform scale applied to all raw height data.
  1054. * @param offset An offset applied to the scaled height data.
  1055. *
  1056. * @param thickness A value subtracted from the lowest height
  1057. * value which in effect adds an additional cuboid to the base of the
  1058. * heightfield. This is used to prevent geoms from looping under the
  1059. * desired terrain and not registering as a collision. Note that the
  1060. * thickness is not affected by the scale or offset parameters.
  1061. *
  1062. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1063. * directions along the local x and z axes. If zero the heightfield is
  1064. * bounded from zero to width in the local x axis, and zero to depth in
  1065. * the local z axis.
  1066. *
  1067. * @ingroup collide
  1068. */
  1069. ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
  1070. void* pUserData, dHeightfieldGetHeight* pCallback,
  1071. dReal width, dReal depth, int widthSamples, int depthSamples,
  1072. dReal scale, dReal offset, dReal thickness, int bWrap );
  1073. /**
  1074. * @brief Configures a dHeightfieldDataID to use height data in byte format.
  1075. *
  1076. * Before a dHeightfieldDataID can be used by a geom it must be
  1077. * configured to specify the format of the height data.
  1078. * This call specifies that the heightfield data is stored as a rectangular
  1079. * array of bytes (8 bit unsigned) representing the height at each sample point.
  1080. *
  1081. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1082. *
  1083. * @param pHeightData A pointer to the height data.
  1084. * @param bCopyHeightData When non-zero the height data is copied to an
  1085. * internal store. When zero the height data is accessed by reference and
  1086. * so must persist throughout the lifetime of the heightfield.
  1087. *
  1088. * @param width Specifies the total 'width' of the heightfield along
  1089. * the geom's local x axis.
  1090. * @param depth Specifies the total 'depth' of the heightfield along
  1091. * the geom's local z axis.
  1092. *
  1093. * @param widthSamples Specifies the number of vertices to sample
  1094. * along the width of the heightfield. Each vertex has a corresponding
  1095. * height value which forms the overall shape.
  1096. * Naturally this value must be at least two or more.
  1097. * @param depthSamples Specifies the number of vertices to sample
  1098. * along the depth of the heightfield.
  1099. *
  1100. * @param scale A uniform scale applied to all raw height data.
  1101. * @param offset An offset applied to the scaled height data.
  1102. *
  1103. * @param thickness A value subtracted from the lowest height
  1104. * value which in effect adds an additional cuboid to the base of the
  1105. * heightfield. This is used to prevent geoms from looping under the
  1106. * desired terrain and not registering as a collision. Note that the
  1107. * thickness is not affected by the scale or offset parameters.
  1108. *
  1109. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1110. * directions along the local x and z axes. If zero the heightfield is
  1111. * bounded from zero to width in the local x axis, and zero to depth in
  1112. * the local z axis.
  1113. *
  1114. * @ingroup collide
  1115. */
  1116. ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
  1117. const unsigned char* pHeightData, int bCopyHeightData,
  1118. dReal width, dReal depth, int widthSamples, int depthSamples,
  1119. dReal scale, dReal offset, dReal thickness, int bWrap );
  1120. /**
  1121. * @brief Configures a dHeightfieldDataID to use height data in short format.
  1122. *
  1123. * Before a dHeightfieldDataID can be used by a geom it must be
  1124. * configured to specify the format of the height data.
  1125. * This call specifies that the heightfield data is stored as a rectangular
  1126. * array of shorts (16 bit signed) representing the height at each sample point.
  1127. *
  1128. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1129. *
  1130. * @param pHeightData A pointer to the height data.
  1131. * @param bCopyHeightData When non-zero the height data is copied to an
  1132. * internal store. When zero the height data is accessed by reference and
  1133. * so must persist throughout the lifetime of the heightfield.
  1134. *
  1135. * @param width Specifies the total 'width' of the heightfield along
  1136. * the geom's local x axis.
  1137. * @param depth Specifies the total 'depth' of the heightfield along
  1138. * the geom's local z axis.
  1139. *
  1140. * @param widthSamples Specifies the number of vertices to sample
  1141. * along the width of the heightfield. Each vertex has a corresponding
  1142. * height value which forms the overall shape.
  1143. * Naturally this value must be at least two or more.
  1144. * @param depthSamples Specifies the number of vertices to sample
  1145. * along the depth of the heightfield.
  1146. *
  1147. * @param scale A uniform scale applied to all raw height data.
  1148. * @param offset An offset applied to the scaled height data.
  1149. *
  1150. * @param thickness A value subtracted from the lowest height
  1151. * value which in effect adds an additional cuboid to the base of the
  1152. * heightfield. This is used to prevent geoms from looping under the
  1153. * desired terrain and not registering as a collision. Note that the
  1154. * thickness is not affected by the scale or offset parameters.
  1155. *
  1156. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1157. * directions along the local x and z axes. If zero the heightfield is
  1158. * bounded from zero to width in the local x axis, and zero to depth in
  1159. * the local z axis.
  1160. *
  1161. * @ingroup collide
  1162. */
  1163. ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
  1164. const short* pHeightData, int bCopyHeightData,
  1165. dReal width, dReal depth, int widthSamples, int depthSamples,
  1166. dReal scale, dReal offset, dReal thickness, int bWrap );
  1167. /**
  1168. * @brief Configures a dHeightfieldDataID to use height data in
  1169. * single precision floating point format.
  1170. *
  1171. * Before a dHeightfieldDataID can be used by a geom it must be
  1172. * configured to specify the format of the height data.
  1173. * This call specifies that the heightfield data is stored as a rectangular
  1174. * array of single precision floats representing the height at each
  1175. * sample point.
  1176. *
  1177. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1178. *
  1179. * @param pHeightData A pointer to the height data.
  1180. * @param bCopyHeightData When non-zero the height data is copied to an
  1181. * internal store. When zero the height data is accessed by reference and
  1182. * so must persist throughout the lifetime of the heightfield.
  1183. *
  1184. * @param width Specifies the total 'width' of the heightfield along
  1185. * the geom's local x axis.
  1186. * @param depth Specifies the total 'depth' of the heightfield along
  1187. * the geom's local z axis.
  1188. *
  1189. * @param widthSamples Specifies the number of vertices to sample
  1190. * along the width of the heightfield. Each vertex has a corresponding
  1191. * height value which forms the overall shape.
  1192. * Naturally this value must be at least two or more.
  1193. * @param depthSamples Specifies the number of vertices to sample
  1194. * along the depth of the heightfield.
  1195. *
  1196. * @param scale A uniform scale applied to all raw height data.
  1197. * @param offset An offset applied to the scaled height data.
  1198. *
  1199. * @param thickness A value subtracted from the lowest height
  1200. * value which in effect adds an additional cuboid to the base of the
  1201. * heightfield. This is used to prevent geoms from looping under the
  1202. * desired terrain and not registering as a collision. Note that the
  1203. * thickness is not affected by the scale or offset parameters.
  1204. *
  1205. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1206. * directions along the local x and z axes. If zero the heightfield is
  1207. * bounded from zero to width in the local x axis, and zero to depth in
  1208. * the local z axis.
  1209. *
  1210. * @ingroup collide
  1211. */
  1212. ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
  1213. const float* pHeightData, int bCopyHeightData,
  1214. dReal width, dReal depth, int widthSamples, int depthSamples,
  1215. dReal scale, dReal offset, dReal thickness, int bWrap );
  1216. /**
  1217. * @brief Configures a dHeightfieldDataID to use height data in
  1218. * double precision floating point format.
  1219. *
  1220. * Before a dHeightfieldDataID can be used by a geom it must be
  1221. * configured to specify the format of the height data.
  1222. * This call specifies that the heightfield data is stored as a rectangular
  1223. * array of double precision floats representing the height at each
  1224. * sample point.
  1225. *
  1226. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1227. *
  1228. * @param pHeightData A pointer to the height data.
  1229. * @param bCopyHeightData When non-zero the height data is copied to an
  1230. * internal store. When zero the height data is accessed by reference and
  1231. * so must persist throughout the lifetime of the heightfield.
  1232. *
  1233. * @param width Specifies the total 'width' of the heightfield along
  1234. * the geom's local x axis.
  1235. * @param depth Specifies the total 'depth' of the heightfield along
  1236. * the geom's local z axis.
  1237. *
  1238. * @param widthSamples Specifies the number of vertices to sample
  1239. * along the width of the heightfield. Each vertex has a corresponding
  1240. * height value which forms the overall shape.
  1241. * Naturally this value must be at least two or more.
  1242. * @param depthSamples Specifies the number of vertices to sample
  1243. * along the depth of the heightfield.
  1244. *
  1245. * @param scale A uniform scale applied to all raw height data.
  1246. * @param offset An offset applied to the scaled height data.
  1247. *
  1248. * @param thickness A value subtracted from the lowest height
  1249. * value which in effect adds an additional cuboid to the base of the
  1250. * heightfield. This is used to prevent geoms from looping under the
  1251. * desired terrain and not registering as a collision. Note that the
  1252. * thickness is not affected by the scale or offset parameters.
  1253. *
  1254. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1255. * directions along the local x and z axes. If zero the heightfield is
  1256. * bounded from zero to width in the local x axis, and zero to depth in
  1257. * the local z axis.
  1258. *
  1259. * @ingroup collide
  1260. */
  1261. ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
  1262. const double* pHeightData, int bCopyHeightData,
  1263. dReal width, dReal depth, int widthSamples, int depthSamples,
  1264. dReal scale, dReal offset, dReal thickness, int bWrap );
  1265. /**
  1266. * @brief Manually set the minimum and maximum height bounds.
  1267. *
  1268. * This call allows you to set explicit min / max values after initial
  1269. * creation typically for callback heightfields which default to +/- infinity,
  1270. * or those whose data has changed. This must be set prior to binding with a
  1271. * geom, as the the AABB is not recomputed after it's first generation.
  1272. *
  1273. * @remarks The minimum and maximum values are used to compute the AABB
  1274. * for the heightfield which is used for early rejection of collisions.
  1275. * A close fit will yield a more efficient collision check.
  1276. *
  1277. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1278. * @param min_height The new minimum height value. Scale, offset and thickness is then applied.
  1279. * @param max_height The new maximum height value. Scale and offset is then applied.
  1280. * @ingroup collide
  1281. */
  1282. ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
  1283. dReal minHeight, dReal maxHeight );
  1284. /**
  1285. * @brief Assigns a dHeightfieldDataID to a heightfield geom.
  1286. *
  1287. * Associates the given dHeightfieldDataID with a heightfield geom.
  1288. * This is done without affecting the GEOM_PLACEABLE flag.
  1289. *
  1290. * @param g A geom created by dCreateHeightfield
  1291. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1292. * @ingroup collide
  1293. */
  1294. ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
  1295. /**
  1296. * @brief Gets the dHeightfieldDataID bound to a heightfield geom.
  1297. *
  1298. * Returns the dHeightfieldDataID associated with a heightfield geom.
  1299. *
  1300. * @param g A geom created by dCreateHeightfield
  1301. * @return The dHeightfieldDataID which may be NULL if none was assigned.
  1302. * @ingroup collide
  1303. */
  1304. ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
  1305. /* ************************************************************************ */
  1306. /* utility functions */
  1307. ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
  1308. const dVector3 b1, const dVector3 b2,
  1309. dVector3 cp1, dVector3 cp2);
  1310. ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
  1311. const dVector3 side1, const dVector3 _p2,
  1312. const dMatrix3 R2, const dVector3 side2);
  1313. /* The meaning of flags parameter is the same as in dCollide()*/
  1314. ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
  1315. const dVector3 side1, const dVector3 p2,
  1316. const dMatrix3 R2, const dVector3 side2,
  1317. dVector3 normal, dReal *depth, int *return_code,
  1318. int flags, dContactGeom *contact, int skip);
  1319. ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
  1320. /* ************************************************************************ */
  1321. /* custom classes */
  1322. typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
  1323. typedef int dColliderFn (dGeomID o1, dGeomID o2,
  1324. int flags, dContactGeom *contact, int skip);
  1325. typedef dColliderFn * dGetColliderFnFn (int num);
  1326. typedef void dGeomDtorFn (dGeomID o);
  1327. typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
  1328. typedef struct dGeomClass {
  1329. int bytes;
  1330. dGetColliderFnFn *collider;
  1331. dGetAABBFn *aabb;
  1332. dAABBTestFn *aabb_test;
  1333. dGeomDtorFn *dtor;
  1334. } dGeomClass;
  1335. ODE_API int dCreateGeomClass (const dGeomClass *classptr);
  1336. ODE_API void * dGeomGetClassData (dGeomID);
  1337. ODE_API dGeomID dCreateGeom (int classnum);
  1338. /**
  1339. * @brief Sets a custom collider function for two geom classes.
  1340. *
  1341. * @param i The first geom class handled by this collider
  1342. * @param j The second geom class handled by this collider
  1343. * @param fn The collider function to use to determine collisions.
  1344. * @ingroup collide
  1345. */
  1346. ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn);
  1347. /* ************************************************************************ */
  1348. #ifdef __cplusplus
  1349. }
  1350. #endif
  1351. #endif