collision.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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. enum
  357. {
  358. dGeomCommonControlClass = 0,
  359. dGeomColliderControlClass = 1
  360. };
  361. enum
  362. {
  363. dGeomCommonAnyControlCode = 0,
  364. dGeomColliderSetMergeSphereContactsControlCode = 1,
  365. dGeomColliderGetMergeSphereContactsControlCode = 2
  366. };
  367. enum
  368. {
  369. dGeomColliderMergeContactsValue__Default = 0, // Used with Set... to restore default value
  370. dGeomColliderMergeContactsValue_None = 1,
  371. dGeomColliderMergeContactsValue_Normals = 2,
  372. dGeomColliderMergeContactsValue_Full = 3
  373. };
  374. /**
  375. * @brief Execute low level control operation for geometry.
  376. *
  377. * The variable the dataSize points to must be initialized before the call.
  378. * If the size does not match the one expected for the control class/code function
  379. * changes it to the size expected and returns failure. This implies the function
  380. * can be called with NULL data and zero size to test if control class/code is supported
  381. * and obtain required data size for it.
  382. *
  383. * dGeomCommonAnyControlCode applies to any control class and returns success if
  384. * at least one control code is available for the given class with given geom.
  385. *
  386. * Currently there are the folliwing control classes supported:
  387. * @li dGeomColliderControlClass
  388. *
  389. * For dGeomColliderControlClass there are the following codes available:
  390. * @li dGeomColliderSetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
  391. * @li dGeomColliderGetMergeSphereContactsControlCode (arg of type int, dGeomColliderMergeContactsValue_*)
  392. *
  393. * @param geom the geom to control
  394. * @param controlClass the control class
  395. * @param controlCode the control code for the class
  396. * @param dataValue the control argument pointer
  397. * @param dataSize the control argument size provided or expected
  398. * @returns Boolean execution status
  399. * @ingroup collide
  400. */
  401. ODE_API int dGeomLowLevelControl (dGeomID geom, int controlClass, int controlCode, void *dataValue, int *dataSize);
  402. /**
  403. * @brief Get world position of a relative point on geom.
  404. *
  405. * Calling this function on a non-placeable geom results in the same point being
  406. * returned.
  407. *
  408. * @ingroup collide
  409. * @param result will contain the result.
  410. */
  411. ODE_API void dGeomGetRelPointPos
  412. (
  413. dGeomID geom, dReal px, dReal py, dReal pz,
  414. dVector3 result
  415. );
  416. /**
  417. * @brief takes a point in global coordinates and returns
  418. * the point's position in geom-relative coordinates.
  419. *
  420. * Calling this function on a non-placeable geom results in the same point being
  421. * returned.
  422. *
  423. * @remarks
  424. * This is the inverse of dGeomGetRelPointPos()
  425. * @ingroup collide
  426. * @param result will contain the result.
  427. */
  428. ODE_API void dGeomGetPosRelPoint
  429. (
  430. dGeomID geom, dReal px, dReal py, dReal pz,
  431. dVector3 result
  432. );
  433. /**
  434. * @brief Convert from geom-local to world coordinates.
  435. *
  436. * Calling this function on a non-placeable geom results in the same vector being
  437. * returned.
  438. *
  439. * @ingroup collide
  440. * @param result will contain the result.
  441. */
  442. ODE_API void dGeomVectorToWorld
  443. (
  444. dGeomID geom, dReal px, dReal py, dReal pz,
  445. dVector3 result
  446. );
  447. /**
  448. * @brief Convert from world to geom-local coordinates.
  449. *
  450. * Calling this function on a non-placeable geom results in the same vector being
  451. * returned.
  452. *
  453. * @ingroup collide
  454. * @param result will contain the result.
  455. */
  456. ODE_API void dGeomVectorFromWorld
  457. (
  458. dGeomID geom, dReal px, dReal py, dReal pz,
  459. dVector3 result
  460. );
  461. /* ************************************************************************ */
  462. /* geom offset from body */
  463. /**
  464. * @brief Set the local offset position of a geom from its body.
  465. *
  466. * Sets the geom's positional offset in local coordinates.
  467. * After this call, the geom will be at a new position determined from the
  468. * body's position and the offset.
  469. * The geom must be attached to a body.
  470. * If the geom did not have an offset, it is automatically created.
  471. *
  472. * @param geom the geom to set.
  473. * @param x the new X coordinate.
  474. * @param y the new Y coordinate.
  475. * @param z the new Z coordinate.
  476. * @ingroup collide
  477. */
  478. ODE_API void dGeomSetOffsetPosition (dGeomID geom, dReal x, dReal y, dReal z);
  479. /**
  480. * @brief Set the local offset rotation matrix of a geom from its body.
  481. *
  482. * Sets the geom's rotational offset in local coordinates.
  483. * After this call, the geom will be at a new position determined from the
  484. * body's position and the offset.
  485. * The geom must be attached to a body.
  486. * If the geom did not have an offset, it is automatically created.
  487. *
  488. * @param geom the geom to set.
  489. * @param R the new rotation matrix.
  490. * @ingroup collide
  491. */
  492. ODE_API void dGeomSetOffsetRotation (dGeomID geom, const dMatrix3 R);
  493. /**
  494. * @brief Set the local offset rotation of a geom from its body.
  495. *
  496. * Sets the geom's rotational offset in local coordinates.
  497. * After this call, the geom will be at a new position determined from the
  498. * body's position and the offset.
  499. * The geom must be attached to a body.
  500. * If the geom did not have an offset, it is automatically created.
  501. *
  502. * @param geom the geom to set.
  503. * @param Q the new rotation.
  504. * @ingroup collide
  505. */
  506. ODE_API void dGeomSetOffsetQuaternion (dGeomID geom, const dQuaternion Q);
  507. /**
  508. * @brief Set the offset position of a geom from its body.
  509. *
  510. * Sets the geom's positional offset to move it to the new world
  511. * coordinates.
  512. * After this call, the geom will be at the world position passed in,
  513. * and the offset will be the difference from the current body position.
  514. * The geom must be attached to a body.
  515. * If the geom did not have an offset, it is automatically created.
  516. *
  517. * @param geom the geom to set.
  518. * @param x the new X coordinate.
  519. * @param y the new Y coordinate.
  520. * @param z the new Z coordinate.
  521. * @ingroup collide
  522. */
  523. ODE_API void dGeomSetOffsetWorldPosition (dGeomID geom, dReal x, dReal y, dReal z);
  524. /**
  525. * @brief Set the offset rotation of a geom from its body.
  526. *
  527. * Sets the geom's rotational offset to orient it to the new world
  528. * rotation matrix.
  529. * After this call, the geom will be at the world orientation passed in,
  530. * and the offset will be the difference from the current body orientation.
  531. * The geom must be attached to a body.
  532. * If the geom did not have an offset, it is automatically created.
  533. *
  534. * @param geom the geom to set.
  535. * @param R the new rotation matrix.
  536. * @ingroup collide
  537. */
  538. ODE_API void dGeomSetOffsetWorldRotation (dGeomID geom, const dMatrix3 R);
  539. /**
  540. * @brief Set the offset rotation of a geom from its body.
  541. *
  542. * Sets the geom's rotational offset to orient it to the new world
  543. * rotation matrix.
  544. * After this call, the geom will be at the world orientation passed in,
  545. * and the offset will be the difference from the current body orientation.
  546. * The geom must be attached to a body.
  547. * If the geom did not have an offset, it is automatically created.
  548. *
  549. * @param geom the geom to set.
  550. * @param Q the new rotation.
  551. * @ingroup collide
  552. */
  553. ODE_API void dGeomSetOffsetWorldQuaternion (dGeomID geom, const dQuaternion);
  554. /**
  555. * @brief Clear any offset from the geom.
  556. *
  557. * If the geom has an offset, it is eliminated and the geom is
  558. * repositioned at the body's position. If the geom has no offset,
  559. * this function does nothing.
  560. * This is more efficient than calling dGeomSetOffsetPosition(zero)
  561. * and dGeomSetOffsetRotation(identiy), because this function actually
  562. * eliminates the offset, rather than leaving it as the identity transform.
  563. *
  564. * @param geom the geom to have its offset destroyed.
  565. * @ingroup collide
  566. */
  567. ODE_API void dGeomClearOffset(dGeomID geom);
  568. /**
  569. * @brief Check to see whether the geom has an offset.
  570. *
  571. * This function will return non-zero if the offset has been created.
  572. * Note that there is a difference between a geom with no offset,
  573. * and a geom with an offset that is the identity transform.
  574. * In the latter case, although the observed behaviour is identical,
  575. * there is a unnecessary computation involved because the geom will
  576. * be applying the transform whenever it needs to recalculate its world
  577. * position.
  578. *
  579. * @param geom the geom to query.
  580. * @returns Non-zero if the geom has an offset, zero otherwise.
  581. * @ingroup collide
  582. */
  583. ODE_API int dGeomIsOffset(dGeomID geom);
  584. /**
  585. * @brief Get the offset position vector of a geom.
  586. *
  587. * Returns the positional offset of the geom in local coordinates.
  588. * If the geom has no offset, this function returns the zero vector.
  589. *
  590. * @param geom the geom to query.
  591. * @returns A pointer to the geom's offset vector.
  592. * @remarks The returned value is a pointer to the geom's internal
  593. * data structure. It is valid until any changes are made
  594. * to the geom.
  595. * @ingroup collide
  596. */
  597. ODE_API const dReal * dGeomGetOffsetPosition (dGeomID geom);
  598. /**
  599. * @brief Copy the offset position vector of a geom.
  600. *
  601. * Returns the positional offset of the geom in local coordinates.
  602. * If the geom has no offset, this function returns the zero vector.
  603. *
  604. * @param geom the geom to query.
  605. * @param pos returns the offset position
  606. * @ingroup collide
  607. */
  608. ODE_API void dGeomCopyOffsetPosition (dGeomID geom, dVector3 pos);
  609. /**
  610. * @brief Get the offset rotation matrix of a geom.
  611. *
  612. * Returns the rotational offset of the geom in local coordinates.
  613. * If the geom has no offset, this function returns the identity
  614. * matrix.
  615. *
  616. * @param geom the geom to query.
  617. * @returns A pointer to the geom's offset rotation matrix.
  618. * @remarks The returned value is a pointer to the geom's internal
  619. * data structure. It is valid until any changes are made
  620. * to the geom.
  621. * @ingroup collide
  622. */
  623. ODE_API const dReal * dGeomGetOffsetRotation (dGeomID geom);
  624. /**
  625. * @brief Copy the offset rotation matrix of a geom.
  626. *
  627. * Returns the rotational offset of the geom in local coordinates.
  628. * If the geom has no offset, this function returns the identity
  629. * matrix.
  630. *
  631. * @param geom the geom to query.
  632. * @param R returns the rotation matrix.
  633. * @ingroup collide
  634. */
  635. ODE_API void dGeomCopyOffsetRotation (dGeomID geom, dMatrix3 R);
  636. /**
  637. * @brief Get the offset rotation quaternion of a geom.
  638. *
  639. * Returns the rotation offset of the geom as a quaternion.
  640. * If the geom has no offset, the identity quaternion is returned.
  641. *
  642. * @param geom the geom to query.
  643. * @param result a copy of the rotation quaternion.
  644. * @ingroup collide
  645. */
  646. ODE_API void dGeomGetOffsetQuaternion (dGeomID geom, dQuaternion result);
  647. /* ************************************************************************ */
  648. /* collision detection */
  649. /*
  650. * Just generate any contacts (disables any contact refining).
  651. */
  652. #define CONTACTS_UNIMPORTANT 0x80000000
  653. /**
  654. *
  655. * @brief Given two geoms o1 and o2 that potentially intersect,
  656. * generate contact information for them.
  657. *
  658. * Internally, this just calls the correct class-specific collision
  659. * functions for o1 and o2.
  660. *
  661. * @param o1 The first geom to test.
  662. * @param o2 The second geom to test.
  663. *
  664. * @param flags The flags specify how contacts should be generated if
  665. * the geoms touch. The lower 16 bits of flags is an integer that
  666. * specifies the maximum number of contact points to generate. You must
  667. * ask for at least one contact.
  668. * Additionally, following bits may be set:
  669. * CONTACTS_UNIMPORTANT -- just generate any contacts (skip contact refining).
  670. * All other bits in flags must be set to zero. In the future the other bits
  671. * may be used to select from different contact generation strategies.
  672. *
  673. * @param contact Points to an array of dContactGeom structures. The array
  674. * must be able to hold at least the maximum number of contacts. These
  675. * dContactGeom structures may be embedded within larger structures in the
  676. * array -- the skip parameter is the byte offset from one dContactGeom to
  677. * the next in the array. If skip is sizeof(dContactGeom) then contact
  678. * points to a normal (C-style) array. It is an error for skip to be smaller
  679. * than sizeof(dContactGeom).
  680. *
  681. * @returns If the geoms intersect, this function returns the number of contact
  682. * points generated (and updates the contact array), otherwise it returns 0
  683. * (and the contact array is not touched).
  684. *
  685. * @remarks If a space is passed as o1 or o2 then this function will collide
  686. * all objects contained in o1 with all objects contained in o2, and return
  687. * the resulting contact points. This method for colliding spaces with geoms
  688. * (or spaces with spaces) provides no user control over the individual
  689. * collisions. To get that control, use dSpaceCollide or dSpaceCollide2 instead.
  690. *
  691. * @remarks If o1 and o2 are the same geom then this function will do nothing
  692. * and return 0. Technically speaking an object intersects with itself, but it
  693. * is not useful to find contact points in this case.
  694. *
  695. * @remarks This function does not care if o1 and o2 are in the same space or not
  696. * (or indeed if they are in any space at all).
  697. *
  698. * @ingroup collide
  699. */
  700. ODE_API int dCollide (dGeomID o1, dGeomID o2, int flags, dContactGeom *contact,
  701. int skip);
  702. /**
  703. * @brief Determines which pairs of geoms in a space may potentially intersect,
  704. * and calls the callback function for each candidate pair.
  705. *
  706. * @param space The space to test.
  707. *
  708. * @param data Passed from dSpaceCollide directly to the callback
  709. * function. Its meaning is user defined. The o1 and o2 arguments are the
  710. * geoms that may be near each other.
  711. *
  712. * @param callback A callback function is of type @ref dNearCallback.
  713. *
  714. * @remarks Other spaces that are contained within the colliding space are
  715. * not treated specially, i.e. they are not recursed into. The callback
  716. * function may be passed these contained spaces as one or both geom
  717. * arguments.
  718. *
  719. * @remarks dSpaceCollide() is guaranteed to pass all intersecting geom
  720. * pairs to the callback function, but may also pass close but
  721. * non-intersecting pairs. The number of these calls depends on the
  722. * internal algorithms used by the space. Thus you should not expect
  723. * that dCollide will return contacts for every pair passed to the
  724. * callback.
  725. *
  726. * @sa dSpaceCollide2
  727. * @ingroup collide
  728. */
  729. ODE_API void dSpaceCollide (dSpaceID space, void *data, dNearCallback *callback);
  730. /**
  731. * @brief Determines which geoms from one space may potentially intersect with
  732. * geoms from another space, and calls the callback function for each candidate
  733. * pair.
  734. *
  735. * @param space1 The first space to test.
  736. *
  737. * @param space2 The second space to test.
  738. *
  739. * @param data Passed from dSpaceCollide directly to the callback
  740. * function. Its meaning is user defined. The o1 and o2 arguments are the
  741. * geoms that may be near each other.
  742. *
  743. * @param callback A callback function is of type @ref dNearCallback.
  744. *
  745. * @remarks This function can also test a single non-space geom against a
  746. * space. This function is useful when there is a collision hierarchy, i.e.
  747. * when there are spaces that contain other spaces.
  748. *
  749. * @remarks Other spaces that are contained within the colliding space are
  750. * not treated specially, i.e. they are not recursed into. The callback
  751. * function may be passed these contained spaces as one or both geom
  752. * arguments.
  753. *
  754. * @remarks Sublevel value of space affects how the spaces are iterated.
  755. * Both spaces are recursed only if their sublevels match. Otherwise, only
  756. * the space with greater sublevel is recursed and the one with lesser sublevel
  757. * is used as a geom itself.
  758. *
  759. * @remarks dSpaceCollide2() is guaranteed to pass all intersecting geom
  760. * pairs to the callback function, but may also pass close but
  761. * non-intersecting pairs. The number of these calls depends on the
  762. * internal algorithms used by the space. Thus you should not expect
  763. * that dCollide will return contacts for every pair passed to the
  764. * callback.
  765. *
  766. * @sa dSpaceCollide
  767. * @sa dSpaceSetSublevel
  768. * @ingroup collide
  769. */
  770. ODE_API void dSpaceCollide2 (dGeomID space1, dGeomID space2, void *data, dNearCallback *callback);
  771. /* ************************************************************************ */
  772. /* standard classes */
  773. /* the maximum number of user classes that are supported */
  774. enum {
  775. dMaxUserClasses = 4
  776. };
  777. /* class numbers - each geometry object needs a unique number */
  778. enum {
  779. dSphereClass = 0,
  780. dBoxClass,
  781. dCapsuleClass,
  782. dCylinderClass,
  783. dPlaneClass,
  784. dRayClass,
  785. dConvexClass,
  786. dGeomTransformClass,
  787. dTriMeshClass,
  788. dHeightfieldClass,
  789. dFirstSpaceClass,
  790. dSimpleSpaceClass = dFirstSpaceClass,
  791. dHashSpaceClass,
  792. dSweepAndPruneSpaceClass, // SAP
  793. dQuadTreeSpaceClass,
  794. dLastSpaceClass = dQuadTreeSpaceClass,
  795. dFirstUserClass,
  796. dLastUserClass = dFirstUserClass + dMaxUserClasses - 1,
  797. dGeomNumClasses
  798. };
  799. /**
  800. * @defgroup collide_sphere Sphere Class
  801. * @ingroup collide
  802. */
  803. /**
  804. * @brief Create a sphere geom of the given radius, and return its ID.
  805. *
  806. * @param space a space to contain the new geom. May be null.
  807. * @param radius the radius of the sphere.
  808. *
  809. * @returns A new sphere geom.
  810. *
  811. * @remarks The point of reference for a sphere is its center.
  812. *
  813. * @sa dGeomDestroy
  814. * @sa dGeomSphereSetRadius
  815. * @ingroup collide_sphere
  816. */
  817. ODE_API dGeomID dCreateSphere (dSpaceID space, dReal radius);
  818. /**
  819. * @brief Set the radius of a sphere geom.
  820. *
  821. * @param sphere the sphere to set.
  822. * @param radius the new radius.
  823. *
  824. * @sa dGeomSphereGetRadius
  825. * @ingroup collide_sphere
  826. */
  827. ODE_API void dGeomSphereSetRadius (dGeomID sphere, dReal radius);
  828. /**
  829. * @brief Retrieves the radius of a sphere geom.
  830. *
  831. * @param sphere the sphere to query.
  832. *
  833. * @sa dGeomSphereSetRadius
  834. * @ingroup collide_sphere
  835. */
  836. ODE_API dReal dGeomSphereGetRadius (dGeomID sphere);
  837. /**
  838. * @brief Calculate the depth of the a given point within a sphere.
  839. *
  840. * @param sphere the sphere to query.
  841. * @param x the X coordinate of the point.
  842. * @param y the Y coordinate of the point.
  843. * @param z the Z coordinate of the point.
  844. *
  845. * @returns The depth of the point. Points inside the sphere will have a
  846. * positive depth, points outside it will have a negative depth, and points
  847. * on the surface will have a depth of zero.
  848. *
  849. * @ingroup collide_sphere
  850. */
  851. ODE_API dReal dGeomSpherePointDepth (dGeomID sphere, dReal x, dReal y, dReal z);
  852. //--> Convex Functions
  853. ODE_API dGeomID dCreateConvex (dSpaceID space,
  854. dReal *_planes,
  855. unsigned int _planecount,
  856. dReal *_points,
  857. unsigned int _pointcount,unsigned int *_polygons);
  858. ODE_API void dGeomSetConvex (dGeomID g,
  859. dReal *_planes,
  860. unsigned int _count,
  861. dReal *_points,
  862. unsigned int _pointcount,unsigned int *_polygons);
  863. //<-- Convex Functions
  864. /**
  865. * @defgroup collide_box Box Class
  866. * @ingroup collide
  867. */
  868. /**
  869. * @brief Create a box geom with the provided side lengths.
  870. *
  871. * @param space a space to contain the new geom. May be null.
  872. * @param lx the length of the box along the X axis
  873. * @param ly the length of the box along the Y axis
  874. * @param lz the length of the box along the Z axis
  875. *
  876. * @returns A new box geom.
  877. *
  878. * @remarks The point of reference for a box is its center.
  879. *
  880. * @sa dGeomDestroy
  881. * @sa dGeomBoxSetLengths
  882. * @ingroup collide_box
  883. */
  884. ODE_API dGeomID dCreateBox (dSpaceID space, dReal lx, dReal ly, dReal lz);
  885. /**
  886. * @brief Set the side lengths of the given box.
  887. *
  888. * @param box the box to set
  889. * @param lx the length of the box along the X axis
  890. * @param ly the length of the box along the Y axis
  891. * @param lz the length of the box along the Z axis
  892. *
  893. * @sa dGeomBoxGetLengths
  894. * @ingroup collide_box
  895. */
  896. ODE_API void dGeomBoxSetLengths (dGeomID box, dReal lx, dReal ly, dReal lz);
  897. /**
  898. * @brief Get the side lengths of a box.
  899. *
  900. * @param box the box to query
  901. * @param result the returned side lengths
  902. *
  903. * @sa dGeomBoxSetLengths
  904. * @ingroup collide_box
  905. */
  906. ODE_API void dGeomBoxGetLengths (dGeomID box, dVector3 result);
  907. /**
  908. * @brief Return the depth of a point in a box.
  909. *
  910. * @param box the box to query
  911. * @param x the X coordinate of the point to test.
  912. * @param y the Y coordinate of the point to test.
  913. * @param z the Z coordinate of the point to test.
  914. *
  915. * @returns The depth of the point. Points inside the box will have a
  916. * positive depth, points outside it will have a negative depth, and points
  917. * on the surface will have a depth of zero.
  918. */
  919. ODE_API dReal dGeomBoxPointDepth (dGeomID box, dReal x, dReal y, dReal z);
  920. ODE_API dGeomID dCreatePlane (dSpaceID space, dReal a, dReal b, dReal c, dReal d);
  921. ODE_API void dGeomPlaneSetParams (dGeomID plane, dReal a, dReal b, dReal c, dReal d);
  922. ODE_API void dGeomPlaneGetParams (dGeomID plane, dVector4 result);
  923. ODE_API dReal dGeomPlanePointDepth (dGeomID plane, dReal x, dReal y, dReal z);
  924. ODE_API dGeomID dCreateCapsule (dSpaceID space, dReal radius, dReal length);
  925. ODE_API void dGeomCapsuleSetParams (dGeomID ccylinder, dReal radius, dReal length);
  926. ODE_API void dGeomCapsuleGetParams (dGeomID ccylinder, dReal *radius, dReal *length);
  927. ODE_API dReal dGeomCapsulePointDepth (dGeomID ccylinder, dReal x, dReal y, dReal z);
  928. // For now we want to have a backwards compatible C-API, note: C++ API is not.
  929. #define dCreateCCylinder dCreateCapsule
  930. #define dGeomCCylinderSetParams dGeomCapsuleSetParams
  931. #define dGeomCCylinderGetParams dGeomCapsuleGetParams
  932. #define dGeomCCylinderPointDepth dGeomCapsulePointDepth
  933. #define dCCylinderClass dCapsuleClass
  934. ODE_API dGeomID dCreateCylinder (dSpaceID space, dReal radius, dReal length);
  935. ODE_API void dGeomCylinderSetParams (dGeomID cylinder, dReal radius, dReal length);
  936. ODE_API void dGeomCylinderGetParams (dGeomID cylinder, dReal *radius, dReal *length);
  937. ODE_API dGeomID dCreateRay (dSpaceID space, dReal length);
  938. ODE_API void dGeomRaySetLength (dGeomID ray, dReal length);
  939. ODE_API dReal dGeomRayGetLength (dGeomID ray);
  940. ODE_API void dGeomRaySet (dGeomID ray, dReal px, dReal py, dReal pz,
  941. dReal dx, dReal dy, dReal dz);
  942. ODE_API void dGeomRayGet (dGeomID ray, dVector3 start, dVector3 dir);
  943. /*
  944. * Set/get ray flags that influence ray collision detection.
  945. * These flags are currently only noticed by the trimesh collider, because
  946. * they can make a major differences there.
  947. */
  948. ODE_API void dGeomRaySetParams (dGeomID g, int FirstContact, int BackfaceCull);
  949. ODE_API void dGeomRayGetParams (dGeomID g, int *FirstContact, int *BackfaceCull);
  950. ODE_API void dGeomRaySetClosestHit (dGeomID g, int closestHit);
  951. ODE_API int dGeomRayGetClosestHit (dGeomID g);
  952. #include "collision_trimesh.h"
  953. ODE_API dGeomID dCreateGeomTransform (dSpaceID space);
  954. ODE_API void dGeomTransformSetGeom (dGeomID g, dGeomID obj);
  955. ODE_API dGeomID dGeomTransformGetGeom (dGeomID g);
  956. ODE_API void dGeomTransformSetCleanup (dGeomID g, int mode);
  957. ODE_API int dGeomTransformGetCleanup (dGeomID g);
  958. ODE_API void dGeomTransformSetInfo (dGeomID g, int mode);
  959. ODE_API int dGeomTransformGetInfo (dGeomID g);
  960. /* ************************************************************************ */
  961. /* heightfield functions */
  962. // Data storage for heightfield data.
  963. struct dxHeightfieldData;
  964. typedef struct dxHeightfieldData* dHeightfieldDataID;
  965. /**
  966. * @brief Callback prototype
  967. *
  968. * Used by the callback heightfield data type to sample a height for a
  969. * given cell position.
  970. *
  971. * @param p_user_data User data specified when creating the dHeightfieldDataID
  972. * @param x The index of a sample in the local x axis. It is a value
  973. * in the range zero to ( nWidthSamples - 1 ).
  974. * @param x The index of a sample in the local z axis. It is a value
  975. * in the range zero to ( nDepthSamples - 1 ).
  976. *
  977. * @return The sample height which is then scaled and offset using the
  978. * values specified when the heightfield data was created.
  979. *
  980. * @ingroup collide
  981. */
  982. typedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z );
  983. /**
  984. * @brief Creates a heightfield geom.
  985. *
  986. * Uses the information in the given dHeightfieldDataID to construct
  987. * a geom representing a heightfield in a collision space.
  988. *
  989. * @param space The space to add the geom to.
  990. * @param data The dHeightfieldDataID created by dGeomHeightfieldDataCreate and
  991. * setup by dGeomHeightfieldDataBuildCallback, dGeomHeightfieldDataBuildByte,
  992. * dGeomHeightfieldDataBuildShort or dGeomHeightfieldDataBuildFloat.
  993. * @param bPlaceable If non-zero this geom can be transformed in the world using the
  994. * usual functions such as dGeomSetPosition and dGeomSetRotation. If the geom is
  995. * not set as placeable, then it uses a fixed orientation where the global y axis
  996. * represents the dynamic 'height' of the heightfield.
  997. *
  998. * @return A geom id to reference this geom in other calls.
  999. *
  1000. * @ingroup collide
  1001. */
  1002. ODE_API dGeomID dCreateHeightfield( dSpaceID space,
  1003. dHeightfieldDataID data, int bPlaceable );
  1004. /**
  1005. * @brief Creates a new empty dHeightfieldDataID.
  1006. *
  1007. * Allocates a new dHeightfieldDataID and returns it. You must call
  1008. * dGeomHeightfieldDataDestroy to destroy it after the geom has been removed.
  1009. * The dHeightfieldDataID value is used when specifying a data format type.
  1010. *
  1011. * @return A dHeightfieldDataID for use with dGeomHeightfieldDataBuildCallback,
  1012. * dGeomHeightfieldDataBuildByte, dGeomHeightfieldDataBuildShort or
  1013. * dGeomHeightfieldDataBuildFloat.
  1014. * @ingroup collide
  1015. */
  1016. ODE_API dHeightfieldDataID dGeomHeightfieldDataCreate(void);
  1017. /**
  1018. * @brief Destroys a dHeightfieldDataID.
  1019. *
  1020. * Deallocates a given dHeightfieldDataID and all managed resources.
  1021. *
  1022. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1023. * @ingroup collide
  1024. */
  1025. ODE_API void dGeomHeightfieldDataDestroy( dHeightfieldDataID d );
  1026. /**
  1027. * @brief Configures a dHeightfieldDataID to use a callback to
  1028. * retrieve height data.
  1029. *
  1030. * Before a dHeightfieldDataID can be used by a geom it must be
  1031. * configured to specify the format of the height data.
  1032. * This call specifies that the heightfield data is computed by
  1033. * the user and it should use the given callback when determining
  1034. * the height of a given element of it's shape.
  1035. *
  1036. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1037. *
  1038. * @param width Specifies the total 'width' of the heightfield along
  1039. * the geom's local x axis.
  1040. * @param depth Specifies the total 'depth' of the heightfield along
  1041. * the geom's local z axis.
  1042. *
  1043. * @param widthSamples Specifies the number of vertices to sample
  1044. * along the width of the heightfield. Each vertex has a corresponding
  1045. * height value which forms the overall shape.
  1046. * Naturally this value must be at least two or more.
  1047. * @param depthSamples Specifies the number of vertices to sample
  1048. * along the depth of the heightfield.
  1049. *
  1050. * @param scale A uniform scale applied to all raw height data.
  1051. * @param offset An offset applied to the scaled height data.
  1052. *
  1053. * @param thickness A value subtracted from the lowest height
  1054. * value which in effect adds an additional cuboid to the base of the
  1055. * heightfield. This is used to prevent geoms from looping under the
  1056. * desired terrain and not registering as a collision. Note that the
  1057. * thickness is not affected by the scale or offset parameters.
  1058. *
  1059. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1060. * directions along the local x and z axes. If zero the heightfield is
  1061. * bounded from zero to width in the local x axis, and zero to depth in
  1062. * the local z axis.
  1063. *
  1064. * @ingroup collide
  1065. */
  1066. ODE_API void dGeomHeightfieldDataBuildCallback( dHeightfieldDataID d,
  1067. void* pUserData, dHeightfieldGetHeight* pCallback,
  1068. dReal width, dReal depth, int widthSamples, int depthSamples,
  1069. dReal scale, dReal offset, dReal thickness, int bWrap );
  1070. /**
  1071. * @brief Configures a dHeightfieldDataID to use height data in byte format.
  1072. *
  1073. * Before a dHeightfieldDataID can be used by a geom it must be
  1074. * configured to specify the format of the height data.
  1075. * This call specifies that the heightfield data is stored as a rectangular
  1076. * array of bytes (8 bit unsigned) representing the height at each sample point.
  1077. *
  1078. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1079. *
  1080. * @param pHeightData A pointer to the height data.
  1081. * @param bCopyHeightData When non-zero the height data is copied to an
  1082. * internal store. When zero the height data is accessed by reference and
  1083. * so must persist throughout the lifetime of the heightfield.
  1084. *
  1085. * @param width Specifies the total 'width' of the heightfield along
  1086. * the geom's local x axis.
  1087. * @param depth Specifies the total 'depth' of the heightfield along
  1088. * the geom's local z axis.
  1089. *
  1090. * @param widthSamples Specifies the number of vertices to sample
  1091. * along the width of the heightfield. Each vertex has a corresponding
  1092. * height value which forms the overall shape.
  1093. * Naturally this value must be at least two or more.
  1094. * @param depthSamples Specifies the number of vertices to sample
  1095. * along the depth of the heightfield.
  1096. *
  1097. * @param scale A uniform scale applied to all raw height data.
  1098. * @param offset An offset applied to the scaled height data.
  1099. *
  1100. * @param thickness A value subtracted from the lowest height
  1101. * value which in effect adds an additional cuboid to the base of the
  1102. * heightfield. This is used to prevent geoms from looping under the
  1103. * desired terrain and not registering as a collision. Note that the
  1104. * thickness is not affected by the scale or offset parameters.
  1105. *
  1106. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1107. * directions along the local x and z axes. If zero the heightfield is
  1108. * bounded from zero to width in the local x axis, and zero to depth in
  1109. * the local z axis.
  1110. *
  1111. * @ingroup collide
  1112. */
  1113. ODE_API void dGeomHeightfieldDataBuildByte( dHeightfieldDataID d,
  1114. const unsigned char* pHeightData, int bCopyHeightData,
  1115. dReal width, dReal depth, int widthSamples, int depthSamples,
  1116. dReal scale, dReal offset, dReal thickness, int bWrap );
  1117. /**
  1118. * @brief Configures a dHeightfieldDataID to use height data in short format.
  1119. *
  1120. * Before a dHeightfieldDataID can be used by a geom it must be
  1121. * configured to specify the format of the height data.
  1122. * This call specifies that the heightfield data is stored as a rectangular
  1123. * array of shorts (16 bit signed) representing the height at each sample point.
  1124. *
  1125. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1126. *
  1127. * @param pHeightData A pointer to the height data.
  1128. * @param bCopyHeightData When non-zero the height data is copied to an
  1129. * internal store. When zero the height data is accessed by reference and
  1130. * so must persist throughout the lifetime of the heightfield.
  1131. *
  1132. * @param width Specifies the total 'width' of the heightfield along
  1133. * the geom's local x axis.
  1134. * @param depth Specifies the total 'depth' of the heightfield along
  1135. * the geom's local z axis.
  1136. *
  1137. * @param widthSamples Specifies the number of vertices to sample
  1138. * along the width of the heightfield. Each vertex has a corresponding
  1139. * height value which forms the overall shape.
  1140. * Naturally this value must be at least two or more.
  1141. * @param depthSamples Specifies the number of vertices to sample
  1142. * along the depth of the heightfield.
  1143. *
  1144. * @param scale A uniform scale applied to all raw height data.
  1145. * @param offset An offset applied to the scaled height data.
  1146. *
  1147. * @param thickness A value subtracted from the lowest height
  1148. * value which in effect adds an additional cuboid to the base of the
  1149. * heightfield. This is used to prevent geoms from looping under the
  1150. * desired terrain and not registering as a collision. Note that the
  1151. * thickness is not affected by the scale or offset parameters.
  1152. *
  1153. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1154. * directions along the local x and z axes. If zero the heightfield is
  1155. * bounded from zero to width in the local x axis, and zero to depth in
  1156. * the local z axis.
  1157. *
  1158. * @ingroup collide
  1159. */
  1160. ODE_API void dGeomHeightfieldDataBuildShort( dHeightfieldDataID d,
  1161. const short* pHeightData, int bCopyHeightData,
  1162. dReal width, dReal depth, int widthSamples, int depthSamples,
  1163. dReal scale, dReal offset, dReal thickness, int bWrap );
  1164. /**
  1165. * @brief Configures a dHeightfieldDataID to use height data in
  1166. * single precision floating point format.
  1167. *
  1168. * Before a dHeightfieldDataID can be used by a geom it must be
  1169. * configured to specify the format of the height data.
  1170. * This call specifies that the heightfield data is stored as a rectangular
  1171. * array of single precision floats representing the height at each
  1172. * sample point.
  1173. *
  1174. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1175. *
  1176. * @param pHeightData A pointer to the height data.
  1177. * @param bCopyHeightData When non-zero the height data is copied to an
  1178. * internal store. When zero the height data is accessed by reference and
  1179. * so must persist throughout the lifetime of the heightfield.
  1180. *
  1181. * @param width Specifies the total 'width' of the heightfield along
  1182. * the geom's local x axis.
  1183. * @param depth Specifies the total 'depth' of the heightfield along
  1184. * the geom's local z axis.
  1185. *
  1186. * @param widthSamples Specifies the number of vertices to sample
  1187. * along the width of the heightfield. Each vertex has a corresponding
  1188. * height value which forms the overall shape.
  1189. * Naturally this value must be at least two or more.
  1190. * @param depthSamples Specifies the number of vertices to sample
  1191. * along the depth of the heightfield.
  1192. *
  1193. * @param scale A uniform scale applied to all raw height data.
  1194. * @param offset An offset applied to the scaled height data.
  1195. *
  1196. * @param thickness A value subtracted from the lowest height
  1197. * value which in effect adds an additional cuboid to the base of the
  1198. * heightfield. This is used to prevent geoms from looping under the
  1199. * desired terrain and not registering as a collision. Note that the
  1200. * thickness is not affected by the scale or offset parameters.
  1201. *
  1202. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1203. * directions along the local x and z axes. If zero the heightfield is
  1204. * bounded from zero to width in the local x axis, and zero to depth in
  1205. * the local z axis.
  1206. *
  1207. * @ingroup collide
  1208. */
  1209. ODE_API void dGeomHeightfieldDataBuildSingle( dHeightfieldDataID d,
  1210. const float* pHeightData, int bCopyHeightData,
  1211. dReal width, dReal depth, int widthSamples, int depthSamples,
  1212. dReal scale, dReal offset, dReal thickness, int bWrap );
  1213. /**
  1214. * @brief Configures a dHeightfieldDataID to use height data in
  1215. * double precision floating point format.
  1216. *
  1217. * Before a dHeightfieldDataID can be used by a geom it must be
  1218. * configured to specify the format of the height data.
  1219. * This call specifies that the heightfield data is stored as a rectangular
  1220. * array of double precision floats representing the height at each
  1221. * sample point.
  1222. *
  1223. * @param d A new dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1224. *
  1225. * @param pHeightData A pointer to the height data.
  1226. * @param bCopyHeightData When non-zero the height data is copied to an
  1227. * internal store. When zero the height data is accessed by reference and
  1228. * so must persist throughout the lifetime of the heightfield.
  1229. *
  1230. * @param width Specifies the total 'width' of the heightfield along
  1231. * the geom's local x axis.
  1232. * @param depth Specifies the total 'depth' of the heightfield along
  1233. * the geom's local z axis.
  1234. *
  1235. * @param widthSamples Specifies the number of vertices to sample
  1236. * along the width of the heightfield. Each vertex has a corresponding
  1237. * height value which forms the overall shape.
  1238. * Naturally this value must be at least two or more.
  1239. * @param depthSamples Specifies the number of vertices to sample
  1240. * along the depth of the heightfield.
  1241. *
  1242. * @param scale A uniform scale applied to all raw height data.
  1243. * @param offset An offset applied to the scaled height data.
  1244. *
  1245. * @param thickness A value subtracted from the lowest height
  1246. * value which in effect adds an additional cuboid to the base of the
  1247. * heightfield. This is used to prevent geoms from looping under the
  1248. * desired terrain and not registering as a collision. Note that the
  1249. * thickness is not affected by the scale or offset parameters.
  1250. *
  1251. * @param bWrap If non-zero the heightfield will infinitely tile in both
  1252. * directions along the local x and z axes. If zero the heightfield is
  1253. * bounded from zero to width in the local x axis, and zero to depth in
  1254. * the local z axis.
  1255. *
  1256. * @ingroup collide
  1257. */
  1258. ODE_API void dGeomHeightfieldDataBuildDouble( dHeightfieldDataID d,
  1259. const double* pHeightData, int bCopyHeightData,
  1260. dReal width, dReal depth, int widthSamples, int depthSamples,
  1261. dReal scale, dReal offset, dReal thickness, int bWrap );
  1262. /**
  1263. * @brief Manually set the minimum and maximum height bounds.
  1264. *
  1265. * This call allows you to set explicit min / max values after initial
  1266. * creation typically for callback heightfields which default to +/- infinity,
  1267. * or those whose data has changed. This must be set prior to binding with a
  1268. * geom, as the the AABB is not recomputed after it's first generation.
  1269. *
  1270. * @remarks The minimum and maximum values are used to compute the AABB
  1271. * for the heightfield which is used for early rejection of collisions.
  1272. * A close fit will yield a more efficient collision check.
  1273. *
  1274. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1275. * @param min_height The new minimum height value. Scale, offset and thickness is then applied.
  1276. * @param max_height The new maximum height value. Scale and offset is then applied.
  1277. * @ingroup collide
  1278. */
  1279. ODE_API void dGeomHeightfieldDataSetBounds( dHeightfieldDataID d,
  1280. dReal minHeight, dReal maxHeight );
  1281. /**
  1282. * @brief Assigns a dHeightfieldDataID to a heightfield geom.
  1283. *
  1284. * Associates the given dHeightfieldDataID with a heightfield geom.
  1285. * This is done without affecting the GEOM_PLACEABLE flag.
  1286. *
  1287. * @param g A geom created by dCreateHeightfield
  1288. * @param d A dHeightfieldDataID created by dGeomHeightfieldDataCreate
  1289. * @ingroup collide
  1290. */
  1291. ODE_API void dGeomHeightfieldSetHeightfieldData( dGeomID g, dHeightfieldDataID d );
  1292. /**
  1293. * @brief Gets the dHeightfieldDataID bound to a heightfield geom.
  1294. *
  1295. * Returns the dHeightfieldDataID associated with a heightfield geom.
  1296. *
  1297. * @param g A geom created by dCreateHeightfield
  1298. * @return The dHeightfieldDataID which may be NULL if none was assigned.
  1299. * @ingroup collide
  1300. */
  1301. ODE_API dHeightfieldDataID dGeomHeightfieldGetHeightfieldData( dGeomID g );
  1302. /* ************************************************************************ */
  1303. /* utility functions */
  1304. ODE_API void dClosestLineSegmentPoints (const dVector3 a1, const dVector3 a2,
  1305. const dVector3 b1, const dVector3 b2,
  1306. dVector3 cp1, dVector3 cp2);
  1307. ODE_API int dBoxTouchesBox (const dVector3 _p1, const dMatrix3 R1,
  1308. const dVector3 side1, const dVector3 _p2,
  1309. const dMatrix3 R2, const dVector3 side2);
  1310. // The meaning of flags parameter is the same as in dCollide()
  1311. ODE_API int dBoxBox (const dVector3 p1, const dMatrix3 R1,
  1312. const dVector3 side1, const dVector3 p2,
  1313. const dMatrix3 R2, const dVector3 side2,
  1314. dVector3 normal, dReal *depth, int *return_code,
  1315. int flags, dContactGeom *contact, int skip);
  1316. ODE_API void dInfiniteAABB (dGeomID geom, dReal aabb[6]);
  1317. /* ************************************************************************ */
  1318. /* custom classes */
  1319. typedef void dGetAABBFn (dGeomID, dReal aabb[6]);
  1320. typedef int dColliderFn (dGeomID o1, dGeomID o2,
  1321. int flags, dContactGeom *contact, int skip);
  1322. typedef dColliderFn * dGetColliderFnFn (int num);
  1323. typedef void dGeomDtorFn (dGeomID o);
  1324. typedef int dAABBTestFn (dGeomID o1, dGeomID o2, dReal aabb[6]);
  1325. typedef struct dGeomClass {
  1326. int bytes;
  1327. dGetColliderFnFn *collider;
  1328. dGetAABBFn *aabb;
  1329. dAABBTestFn *aabb_test;
  1330. dGeomDtorFn *dtor;
  1331. } dGeomClass;
  1332. ODE_API int dCreateGeomClass (const dGeomClass *classptr);
  1333. ODE_API void * dGeomGetClassData (dGeomID);
  1334. ODE_API dGeomID dCreateGeom (int classnum);
  1335. /**
  1336. * @brief Sets a custom collider function for two geom classes.
  1337. *
  1338. * @param i The first geom class handled by this collider
  1339. * @param j The second geom class handled by this collider
  1340. * @param fn The collider function to use to determine collisions.
  1341. * @ingroup collide
  1342. */
  1343. ODE_API void dSetColliderOverride (int i, int j, dColliderFn *fn);
  1344. /* ************************************************************************ */
  1345. #ifdef __cplusplus
  1346. }
  1347. #endif
  1348. #endif