slider.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 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. //234567890123456789012345678901234567890123456789012345678901234567890123456789
  23. // 1 2 3 4 5 6 7
  24. ////////////////////////////////////////////////////////////////////////////////
  25. // This file create unit test for some of the functions found in:
  26. // ode/src/joinst/slider.cpp
  27. //
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. #include <UnitTest++.h>
  31. #include <ode/ode.h>
  32. #include "../../ode/src/joints/slider.h"
  33. SUITE (TestdxJointSlider)
  34. {
  35. struct dxJointSlider_Fixture_1
  36. {
  37. dxJointSlider_Fixture_1()
  38. {
  39. wId = dWorldCreate();
  40. bId1 = dBodyCreate (wId);
  41. dBodySetPosition (bId1, 0, -1, 0);
  42. bId2 = dBodyCreate (wId);
  43. dBodySetPosition (bId2, 0, 1, 0);
  44. jId = dJointCreateSlider (wId, 0);
  45. joint = (dxJointSlider*) jId;
  46. dJointAttach (jId, bId1, bId2);
  47. }
  48. ~dxJointSlider_Fixture_1()
  49. {
  50. dWorldDestroy (wId);
  51. }
  52. dWorldID wId;
  53. dBodyID bId1;
  54. dBodyID bId2;
  55. dJointID jId;
  56. dxJointSlider* joint;
  57. };
  58. TEST_FIXTURE (dxJointSlider_Fixture_1, test_dJointSetSlider)
  59. {
  60. // the 2 bodies are align
  61. dJointSetSliderAxis (jId, 1, 0, 0);
  62. CHECK_CLOSE (joint->qrel[0], 1.0, 1e-4);
  63. CHECK_CLOSE (joint->qrel[1], 0.0, 1e-4);
  64. CHECK_CLOSE (joint->qrel[2], 0.0, 1e-4);
  65. CHECK_CLOSE (joint->qrel[3], 0.0, 1e-4);
  66. dMatrix3 R;
  67. // Rotate 2nd body 90deg around X
  68. dBodySetPosition (bId2, 0, 0, 1);
  69. dRFromAxisAndAngle (R, 1, 0, 0, M_PI/2.0);
  70. dBodySetRotation (bId2, R);
  71. dJointSetSliderAxis (jId, 1, 0 ,0);
  72. CHECK_CLOSE (joint->qrel[0], 0.70710678118654757, 1e-4);
  73. CHECK_CLOSE (joint->qrel[1], 0.70710678118654757, 1e-4);
  74. CHECK_CLOSE (joint->qrel[2], 0.0, 1e-4);
  75. CHECK_CLOSE (joint->qrel[3], 0.0, 1e-4);
  76. // Rotate 2nd body -90deg around X
  77. dBodySetPosition (bId2, 0, 0, -1);
  78. dRFromAxisAndAngle (R, 1, 0, 0, -M_PI/2.0);
  79. dBodySetRotation (bId2, R);
  80. dJointSetSliderAxis (jId, 1, 0 ,0);
  81. CHECK_CLOSE (joint->qrel[0], 0.70710678118654757, 1e-4);
  82. CHECK_CLOSE (joint->qrel[1], -0.70710678118654757, 1e-4);
  83. CHECK_CLOSE (joint->qrel[2], 0.0, 1e-4);
  84. CHECK_CLOSE (joint->qrel[3], 0.0, 1e-4);
  85. // Rotate 2nd body 90deg around Z
  86. dBodySetPosition (bId2, 0, 1, 0);
  87. dRFromAxisAndAngle (R, 0, 0, 1, M_PI/2.0);
  88. dBodySetRotation (bId2, R);
  89. dJointSetSliderAxis (jId, 1, 0 ,0);
  90. CHECK_CLOSE (joint->qrel[0], 0.70710678118654757, 1e-4);
  91. CHECK_CLOSE (joint->qrel[1], 0.0, 1e-4);
  92. CHECK_CLOSE (joint->qrel[2], 0.0, 1e-4);
  93. CHECK_CLOSE (joint->qrel[3], 0.70710678118654757, 1e-4);
  94. // Rotate 2nd body 45deg around Y
  95. dBodySetPosition (bId2, 0, 1, 0);
  96. dRFromAxisAndAngle (R, 0, 1, 0, M_PI/4.0);
  97. dBodySetRotation (bId2, R);
  98. dJointSetSliderAxis (jId, 1, 0 ,0);
  99. CHECK_CLOSE (joint->qrel[0], 0.92387953251128674, 1e-4);
  100. CHECK_CLOSE (joint->qrel[1], 0.0, 1e-4);
  101. CHECK_CLOSE (joint->qrel[2], 0.38268343236508984, 1e-4);
  102. CHECK_CLOSE (joint->qrel[3], 0.0, 1e-4);
  103. // Rotate in a strange manner
  104. // Both bodies at origin
  105. dRFromEulerAngles (R, REAL(0.23), REAL(3.1), REAL(-0.73));
  106. dBodySetPosition (bId1, 0, 0, 0);
  107. dBodySetRotation (bId1, R);
  108. dRFromEulerAngles (R, REAL(-0.57), REAL(1.49), REAL(0.81));
  109. dBodySetPosition (bId2, 0, 0, 0);
  110. dBodySetRotation (bId2, R);
  111. dJointSetSliderAxis (jId, 1, 0 ,0);
  112. CHECK_CLOSE (joint->qrel[0], -0.25526036263124319, 1e-4);
  113. CHECK_CLOSE (joint->qrel[1], 0.28434861188441968, 1e-4);
  114. CHECK_CLOSE (joint->qrel[2], -0.65308047160141625, 1e-4);
  115. CHECK_CLOSE (joint->qrel[3], 0.65381489108282143, 1e-4);
  116. }
  117. // The 2 bodies are positionned at (0, 0, 0), with no rotation
  118. // The joint is a Slider Joint
  119. // Axis is along the X axis
  120. // Anchor at (0, 0, 0)
  121. struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X
  122. {
  123. Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X()
  124. {
  125. wId = dWorldCreate();
  126. bId1 = dBodyCreate (wId);
  127. dBodySetPosition (bId1, 0, 0, 0);
  128. bId2 = dBodyCreate (wId);
  129. dBodySetPosition (bId2, 0, 0, 0);
  130. jId = dJointCreateSlider (wId, 0);
  131. joint = (dxJointSlider*) jId;
  132. dJointAttach (jId, bId1, bId2);
  133. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  134. }
  135. ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X()
  136. {
  137. dWorldDestroy (wId);
  138. }
  139. dWorldID wId;
  140. dBodyID bId1;
  141. dBodyID bId2;
  142. dJointID jId;
  143. dxJointSlider* joint;
  144. static const dVector3 axis;
  145. static const dReal offset;
  146. };
  147. const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::axis = {1, 0, 0};
  148. const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X::offset = REAL(3.1);
  149. // Move 1st body offset unit in the X direction
  150. //
  151. // X-------> X---------> Axis -->
  152. // B1 => B1
  153. // B2 B2
  154. //
  155. // Start with a Offset of offset unit
  156. //
  157. // X-------> X---------> Axis -->
  158. // B1 => B1
  159. // B2 B2
  160. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  161. test_dJointSetSliderAxisOffset_B1_3Unit)
  162. {
  163. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  164. dBodySetPosition(bId1, offset, 0, 0);
  165. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  166. }
  167. // Move 1st body offset unit in the opposite X direction
  168. //
  169. // X-------> X---------> Axis -->
  170. // B1 => B1
  171. // B2 B2
  172. //
  173. // Start with a Offset of -offset unit
  174. //
  175. // X-------> X---------> Axis -->
  176. // B1 => B1
  177. // B2 B2
  178. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  179. test_dJointSetSliderAxisOffset_B1_Minus_3Unit)
  180. {
  181. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  182. dBodySetPosition(bId1, -offset, 0, 0);
  183. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  184. }
  185. // Move 2nd body offset unit in the X direction
  186. //
  187. // X-------> X---------> Axis -->
  188. // B1 => B1
  189. // B2 B2
  190. //
  191. // Start with a Offset of offset unit
  192. //
  193. // X-------> X---------> Axis -->
  194. // B1 => B1
  195. // B2 B2
  196. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  197. test_dJointSetSliderAxisOffset_B2_3Unit)
  198. {
  199. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  200. dBodySetPosition(bId2, offset, 0, 0);
  201. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  202. }
  203. // Move 2nd body offset unit in the opposite X direction
  204. //
  205. // X-------> X---------> Axis -->
  206. // B1 => B1
  207. // B2 B2
  208. //
  209. // Start with a Offset of -offset unit
  210. //
  211. // X-------> X---------> Axis -->
  212. // B1 => B1
  213. // B2 B2
  214. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  215. test_dJointSetSliderAxisOffset_B2_Minus_3Unit)
  216. {
  217. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  218. dBodySetPosition(bId2, -offset, 0, 0);
  219. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  220. }
  221. // The 2 bodies are positionned at (0, 0, 0), with no rotation
  222. // The joint is a Slider Joint
  223. // Axis is the opposite of the X axis
  224. // Anchor at (0, 0, 0)
  225. struct Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X
  226. {
  227. Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X()
  228. {
  229. wId = dWorldCreate();
  230. bId1 = dBodyCreate (wId);
  231. dBodySetPosition (bId1, 0, 0, 0);
  232. bId2 = dBodyCreate (wId);
  233. dBodySetPosition (bId2, 0, 0, 0);
  234. jId = dJointCreateSlider (wId, 0);
  235. joint = (dxJointSlider*) jId;
  236. dJointAttach (jId, bId1, bId2);
  237. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  238. }
  239. ~Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X()
  240. {
  241. dWorldDestroy (wId);
  242. }
  243. dWorldID wId;
  244. dBodyID bId1;
  245. dBodyID bId2;
  246. dJointID jId;
  247. dxJointSlider* joint;
  248. static const dVector3 axis;
  249. static const dReal offset;
  250. };
  251. const dVector3 Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0};
  252. const dReal Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1);
  253. // Move 1st body offset unit in the X direction
  254. //
  255. // X-------> X---------> <-- Axis
  256. // B1 => B1
  257. // B2 B2
  258. //
  259. // Start with a Offset of offset unit
  260. //
  261. // X-------> X---------> <-- Axis
  262. // B1 => B1
  263. // B2 B2
  264. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  265. test_dJointSetSliderAxisOffset_B1_3Unit)
  266. {
  267. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  268. dBodySetPosition(bId1, offset, 0, 0);
  269. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  270. }
  271. // Move 1st body offset unit in the opposite X direction
  272. //
  273. // X-------> X---------> <-- Axis
  274. // B1 => B1
  275. // B2 B2
  276. //
  277. // Start with a Offset of offset unit
  278. //
  279. // X-------> X---------> <-- Axis
  280. // B1 => B1
  281. // B2 B2
  282. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  283. test_dJointSetSliderAxisOffset_B1_Minus_3Unit)
  284. {
  285. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  286. dBodySetPosition(bId1, -offset, 0, 0);
  287. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  288. }
  289. // Move 2nd body offset unit in the X direction
  290. //
  291. // X-------> X---------> <-- Axis
  292. // B1 => B1
  293. // B2 B2
  294. //
  295. // Start with a Offset of offset unit
  296. //
  297. // X-------> X---------> <-- Axis
  298. // B1 => B1
  299. // B2 B2
  300. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  301. test_dJointSetSliderAxisOffset_B2_3Unit)
  302. {
  303. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  304. dBodySetPosition(bId2, offset, 0, 0);
  305. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  306. }
  307. // Move 2nd body offset unit in the opposite X direction
  308. //
  309. // X-------> X---------> <-- Axis
  310. // B1 => B1
  311. // B2 B2
  312. //
  313. // Start with a Offset of -offset unit
  314. //
  315. // X-------> X---------> <-- Axis
  316. // B1 => B1
  317. // B2 B2
  318. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  319. test_dJointSetSliderAxisOffset_B2_Minus_3Unit)
  320. {
  321. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  322. dBodySetPosition(bId2, -offset, 0, 0);
  323. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  324. }
  325. // Only body 1
  326. // The body are positionned at (0, 0, 0), with no rotation
  327. // The joint is a Slider Joint
  328. // Axis is along the X axis
  329. // Anchor at (0, 0, 0)
  330. struct Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X
  331. {
  332. Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X()
  333. {
  334. wId = dWorldCreate();
  335. bId1 = dBodyCreate (wId);
  336. dBodySetPosition (bId1, 0, 0, 0);
  337. jId = dJointCreateSlider (wId, 0);
  338. joint = (dxJointSlider*) jId;
  339. dJointAttach (jId, bId1, NULL);
  340. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  341. }
  342. ~Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X()
  343. {
  344. dWorldDestroy (wId);
  345. }
  346. dWorldID wId;
  347. dBodyID bId1;
  348. dJointID jId;
  349. dxJointSlider* joint;
  350. static const dVector3 axis;
  351. static const dReal offset;
  352. };
  353. const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::axis = {1, 0, 0};
  354. const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X::offset = REAL(3.1);
  355. // Move 1st body offset unit in the X direction
  356. //
  357. // X-------> X---------> Axis -->
  358. // B1 => B1
  359. //
  360. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X,
  361. test_dJointSetSliderAxisOffset_B1_OffsetUnit)
  362. {
  363. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  364. dBodySetPosition(bId1, offset, 0, 0);
  365. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  366. }
  367. // Move 1st body offset unit in the opposite X direction
  368. //
  369. // X-------> X---------> Axis -->
  370. // B1 => B1
  371. //
  372. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X,
  373. test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit)
  374. {
  375. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  376. dBodySetPosition(bId1, -offset, 0, 0);
  377. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  378. }
  379. // Only body 1
  380. // The body are positionned at (0, 0, 0), with no rotation
  381. // The joint is a Slider Joint
  382. // Axis is in the oppsite X axis
  383. // Anchor at (0, 0, 0)
  384. struct Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X
  385. {
  386. Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X()
  387. {
  388. wId = dWorldCreate();
  389. bId1 = dBodyCreate (wId);
  390. dBodySetPosition (bId1, 0, 0, 0);
  391. jId = dJointCreateSlider (wId, 0);
  392. joint = (dxJointSlider*) jId;
  393. dJointAttach (jId, bId1, NULL);
  394. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  395. }
  396. ~Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X()
  397. {
  398. dWorldDestroy (wId);
  399. }
  400. dWorldID wId;
  401. dBodyID bId1;
  402. dJointID jId;
  403. dxJointSlider* joint;
  404. static const dVector3 axis;
  405. static const dReal offset;
  406. };
  407. const dVector3 Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0};
  408. const dReal Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1);
  409. // Move 1st body offset unit in the X direction
  410. //
  411. // X-------> X---------> <--- Axis
  412. // B1 => B1
  413. //
  414. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X,
  415. test_dJointSetSliderAxisOffset_B1_OffsetUnit)
  416. {
  417. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  418. dBodySetPosition(bId1, offset, 0, 0);
  419. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  420. }
  421. // Move 1st body offset unit in the opposite X direction
  422. //
  423. // X-------> X---------> <--- Axis
  424. // B1 => B1
  425. //
  426. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X,
  427. test_dJointSetSliderAxisOffset_B1_Minus_OffsetUnit)
  428. {
  429. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  430. dBodySetPosition(bId1, -offset, 0, 0);
  431. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  432. }
  433. // Only body 2
  434. // The body are positionned at (0, 0, 0), with no rotation
  435. // The joint is a Slider Joint
  436. // Axis is along the X axis
  437. // Anchor at (0, 0, 0)
  438. struct Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X
  439. {
  440. Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X()
  441. {
  442. wId = dWorldCreate();
  443. bId2 = dBodyCreate (wId);
  444. dBodySetPosition (bId2, 0, 0, 0);
  445. jId = dJointCreateSlider (wId, 0);
  446. joint = (dxJointSlider*) jId;
  447. dJointAttach (jId, NULL, bId2);
  448. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  449. }
  450. ~Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X()
  451. {
  452. dWorldDestroy (wId);
  453. }
  454. dWorldID wId;
  455. dBodyID bId2;
  456. dJointID jId;
  457. dxJointSlider* joint;
  458. static const dVector3 axis;
  459. static const dReal offset;
  460. };
  461. const dVector3 Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X::axis = {1, 0, 0};
  462. const dReal Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X::offset = REAL(3.1);
  463. // Move 2nd body offset unit in the X direction
  464. //
  465. // X-------> X---------> Axis -->
  466. // B2 => B2
  467. //
  468. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X,
  469. test_dJointSetSliderAxisOffset_B2_OffsetUnit)
  470. {
  471. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  472. dBodySetPosition(bId2, offset, 0, 0);
  473. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  474. }
  475. // Move 2nd body offset unit in the opposite X direction
  476. //
  477. // X-------> X---------> Axis -->
  478. // B2 => B2
  479. //
  480. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X,
  481. test_dJointSetSliderAxisOffset_B2_Minus_OffsetUnit)
  482. {
  483. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  484. dBodySetPosition(bId2, -offset, 0, 0);
  485. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  486. }
  487. // Only body 2
  488. // The body are positionned at (0, 0, 0), with no rotation
  489. // The joint is a Slider Joint
  490. // Axis is in the oppsite X axis
  491. // Anchor at (0, 0, 0)
  492. struct Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X
  493. {
  494. Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X()
  495. {
  496. wId = dWorldCreate();
  497. bId2 = dBodyCreate (wId);
  498. dBodySetPosition (bId2, 0, 0, 0);
  499. jId = dJointCreateSlider (wId, 0);
  500. joint = (dxJointSlider*) jId;
  501. dJointAttach (jId, NULL, bId2);
  502. dJointSetSliderAxis(jId, axis[0], axis[1], axis[2]);
  503. }
  504. ~Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X()
  505. {
  506. dWorldDestroy (wId);
  507. }
  508. dWorldID wId;
  509. dBodyID bId2;
  510. dJointID jId;
  511. dxJointSlider* joint;
  512. static const dVector3 axis;
  513. static const dReal offset;
  514. };
  515. const dVector3 Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X::axis = {-1, 0, 0};
  516. const dReal Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X::offset = REAL(3.1);
  517. // Move 2nd body offset unit in the X direction
  518. //
  519. // X-------> X---------> <--- Axis
  520. // B2 => B2
  521. //
  522. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X,
  523. test_dJointSetSliderAxisOffset_B2_OffsetUnit)
  524. {
  525. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  526. dBodySetPosition(bId2, offset, 0, 0);
  527. CHECK_CLOSE (offset, dJointGetSliderPosition(jId), 1e-4);
  528. }
  529. // Move 2nd body offset unit in the opposite X direction
  530. //
  531. // X-------> X---------> <--- Axis
  532. // B2 => B2
  533. //
  534. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X,
  535. test_dJointSetSliderAxisOffset_B2_Minus_OffsetUnit)
  536. {
  537. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  538. dBodySetPosition(bId2, -offset, 0, 0);
  539. CHECK_CLOSE (-offset, dJointGetSliderPosition(jId), 1e-4);
  540. }
  541. // ==========================================================================
  542. // Test Position Rate
  543. // ==========================================================================
  544. // Apply force on 1st body in the X direction also the Axis direction
  545. //
  546. // X-------> X---------> Axis -->
  547. // B1 F-> => B1
  548. // B2 B2
  549. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  550. test_dJointSetSliderPositionRate_Force_Along_Axis_on_B1)
  551. {
  552. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  553. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  554. dBodyAddForce(bId1, 1.0, 0, 0);
  555. dWorldQuickStep (wId, 1.0);
  556. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  557. }
  558. // Apply force on 1st body in the inverse X direction
  559. //
  560. // X-------> X---------> Axis -->
  561. // B1 <-F => B1
  562. // B2 B2
  563. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  564. test_dJointSetSliderPositionRate_Force_Inverse_of_Axis_on_B1)
  565. {
  566. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  567. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  568. dBodyAddForce(bId1, -1.0, 0, 0);
  569. dWorldQuickStep (wId, 1.0);
  570. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  571. }
  572. // Apply force on 1st body in the X direction also the Axis direction
  573. //
  574. // X-------> X---------> <-- Axis
  575. // B1 F-> => B1
  576. // B2 B2
  577. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  578. test_dJointSetSliderPositionRate_Force_Inverse_Axis_on_B1)
  579. {
  580. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  581. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  582. dBodyAddForce(bId1, 1.0, 0, 0);
  583. dWorldQuickStep (wId, 1.0);
  584. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  585. }
  586. // Apply force on 1st body in the inverse X direction
  587. //
  588. // X-------> X---------> <-- Axis
  589. // B1 <-F => B1
  590. // B2 B2
  591. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  592. test_dJointSetSliderPositionRate_Force_Along_of_Axis_on_B1)
  593. {
  594. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  595. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  596. dBodyAddForce(bId1, -1.0, 0, 0);
  597. dWorldQuickStep (wId, 1.0);
  598. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  599. }
  600. // Apply force on 1st body in the X direction also the Axis direction
  601. //
  602. // X-------> X---------> Axis -->
  603. // B1 => B1
  604. // B2 F-> B2
  605. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  606. test_dJointSetSliderPositionRate_Force_Along_Axis_on_B2)
  607. {
  608. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  609. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  610. dBodyAddForce(bId2, 1.0, 0, 0);
  611. dWorldQuickStep (wId, 1.0);
  612. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  613. }
  614. // Apply force on 1st body in the inverse X direction
  615. //
  616. // X-------> X---------> Axis -->
  617. // B1 => B1
  618. // B2 <-F B2
  619. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Along_X,
  620. test_dJointSetSliderPositionRate_Force_Inverse_of_Axis_on_B2)
  621. {
  622. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  623. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  624. dBodyAddForce(bId2, -1.0, 0, 0);
  625. dWorldQuickStep (wId, 1.0);
  626. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  627. }
  628. // Apply force on 1st body in the X direction also the Axis direction
  629. //
  630. // X-------> X---------> <-- Axis
  631. // B1 => B1
  632. // B2 F-> B2
  633. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  634. test_dJointSetSliderPositionRate_Force_Inverse_Axis_on_B2)
  635. {
  636. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  637. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  638. dBodyAddForce(bId2, 1.0, 0, 0);
  639. dWorldQuickStep (wId, 1.0);
  640. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  641. }
  642. // Apply force on 1st body in the inverse X direction
  643. //
  644. // X-------> X---------> <-- Axis
  645. // B1 => B1
  646. // B2 <-F B2
  647. TEST_FIXTURE (Fixture_dxJointSlider_B1_and_B2_At_Zero_Axis_Inverse_of_X,
  648. test_dJointSetSliderPositionRate_Force_Along_of_Axis_on_B2)
  649. {
  650. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  651. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  652. dBodyAddForce(bId2, -1.0, 0, 0);
  653. dWorldQuickStep (wId, 1.0);
  654. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  655. }
  656. // Apply force on 1st body in the X direction also the Axis direction
  657. //
  658. // X-------> X---------> Axis -->
  659. // B1 F-> => B1
  660. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X,
  661. test_dJointSetSliderPositionRate_Force_Along_Axis_on_B1)
  662. {
  663. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  664. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  665. dBodyAddForce(bId1, 1.0, 0, 0);
  666. dWorldQuickStep (wId, 1.0);
  667. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  668. }
  669. // Apply force on 1st body in the inverse X direction
  670. //
  671. // X-------> X---------> Axis -->
  672. // B1 <-F => B1
  673. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Along_X,
  674. test_dJointSetSliderPositionRate_Force_Inverse_of_Axis_on_B1)
  675. {
  676. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  677. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  678. dBodyAddForce(bId1, -1.0, 0, 0);
  679. dWorldQuickStep (wId, 1.0);
  680. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  681. }
  682. // Apply force on 1st body in the X direction also the Axis direction
  683. //
  684. // X-------> X---------> <-- Axis
  685. // B1 F-> => B1
  686. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X,
  687. test_dJointSetSliderPositionRate_Force_Inverse_Axis_on_B1)
  688. {
  689. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  690. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  691. dBodyAddForce(bId1, 1.0, 0, 0);
  692. dWorldQuickStep (wId, 1.0);
  693. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  694. }
  695. // Apply force on 1st body in the inverse X direction
  696. //
  697. // X-------> X---------> <-- Axis
  698. // B1 <-F => B1
  699. TEST_FIXTURE (Fixture_dxJointSlider_B1_At_Zero_Axis_Inverse_of_X,
  700. test_dJointSetSliderPositionRate_Force_Along_of_Axis_on_B1)
  701. {
  702. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  703. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  704. dBodyAddForce(bId1, -1.0, 0, 0);
  705. dWorldQuickStep (wId, 1.0);
  706. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  707. }
  708. // Apply force on body 2 in the X direction also the Axis direction
  709. //
  710. // X-------> X---------> Axis -->
  711. // B2 F-> B2
  712. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X,
  713. test_dJointSetSliderPositionRate_Force_Along_Axis_on_B2)
  714. {
  715. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  716. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  717. dBodyAddForce(bId2, 1.0, 0, 0);
  718. dWorldQuickStep (wId, 1.0);
  719. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  720. }
  721. // Apply force on body 2 in the inverse X direction
  722. //
  723. // X-------> X---------> Axis -->
  724. // B2 <-F B2
  725. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Along_X,
  726. test_dJointSetSliderPositionRate_Force_Inverse_of_Axis_on_B2)
  727. {
  728. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  729. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  730. dBodyAddForce(bId2, -1.0, 0, 0);
  731. dWorldQuickStep (wId, 1.0);
  732. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  733. }
  734. // Apply force on body 2 in the X direction also the Axis direction
  735. //
  736. // X-------> X---------> <-- Axis
  737. // B2 F-> B2
  738. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X,
  739. test_dJointSetSliderPositionRate_Force_Inverse_Axis_on_B2)
  740. {
  741. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  742. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  743. dBodyAddForce(bId2, 1.0, 0, 0);
  744. dWorldQuickStep (wId, 1.0);
  745. CHECK_CLOSE (1, dJointGetSliderPositionRate(jId), 1e-4);
  746. }
  747. // Apply force on body 2 in the inverse X direction
  748. //
  749. // X-------> X---------> <-- Axis
  750. // B2 <-F B2
  751. TEST_FIXTURE (Fixture_dxJointSlider_B2_At_Zero_Axis_Inverse_of_X,
  752. test_dJointSetSliderPositionRate_Force_Along_of_Axis_on_B2)
  753. {
  754. CHECK_CLOSE (0.0, dJointGetSliderPosition(jId), 1e-4);
  755. CHECK_CLOSE (0.0, dJointGetSliderPositionRate(jId), 1e-4);
  756. dBodyAddForce(bId2, -1.0, 0, 0);
  757. dWorldQuickStep (wId, 1.0);
  758. CHECK_CLOSE (-1, dJointGetSliderPositionRate(jId), 1e-4);
  759. }
  760. // Create 2 bodies attached by a Slider joint
  761. // Axis is along the X axis (Default value
  762. // Anchor at (0, 0, 0) (Default value)
  763. //
  764. // ^Y
  765. // |
  766. // |
  767. // |
  768. // |
  769. // Body1 | Body2
  770. // * Z-----*->x
  771. struct dxJointSlider_Test_Initialization
  772. {
  773. dxJointSlider_Test_Initialization()
  774. {
  775. wId = dWorldCreate();
  776. // Remove gravity to have the only force be the force of the joint
  777. dWorldSetGravity(wId, 0,0,0);
  778. for (int j=0; j<2; ++j)
  779. {
  780. bId[j][0] = dBodyCreate (wId);
  781. dBodySetPosition (bId[j][0], -1, -2, -3);
  782. bId[j][1] = dBodyCreate (wId);
  783. dBodySetPosition (bId[j][1], 11, 22, 33);
  784. dMatrix3 R;
  785. dVector3 axis; // Random axis
  786. axis[0] = REAL(0.53);
  787. axis[1] = -REAL(0.71);
  788. axis[2] = REAL(0.43);
  789. dNormalize3(axis);
  790. dRFromAxisAndAngle (R, axis[0], axis[1], axis[2],
  791. REAL(0.47123)); // 27deg
  792. dBodySetRotation (bId[j][0], R);
  793. axis[0] = REAL(1.2);
  794. axis[1] = REAL(0.87);
  795. axis[2] = -REAL(0.33);
  796. dNormalize3(axis);
  797. dRFromAxisAndAngle (R, axis[0], axis[1], axis[2],
  798. REAL(0.47123)); // 27deg
  799. dBodySetRotation (bId[j][1], R);
  800. jId[j] = dJointCreateSlider (wId, 0);
  801. dJointAttach (jId[j], bId[j][0], bId[j][1]);
  802. }
  803. }
  804. ~dxJointSlider_Test_Initialization()
  805. {
  806. dWorldDestroy (wId);
  807. }
  808. dWorldID wId;
  809. dBodyID bId[2][2];
  810. dJointID jId[2];
  811. };
  812. // Test if setting a Slider joint with its default values
  813. // will behave the same as a default Slider joint
  814. TEST_FIXTURE (dxJointSlider_Test_Initialization,
  815. test_Slider_Initialization)
  816. {
  817. using namespace std;
  818. dVector3 axis;
  819. dJointGetSliderAxis(jId[1], axis);
  820. dJointSetSliderAxis(jId[1], axis[0], axis[1], axis[2]);
  821. CHECK_CLOSE (dJointGetSliderPosition(jId[0]),
  822. dJointGetSliderPosition(jId[1]), 1e-6);
  823. for (int b=0; b<2; ++b)
  824. {
  825. // Compare body b of the first joint with its equivalent on the
  826. // second joint
  827. const dReal *qA = dBodyGetQuaternion(bId[0][b]);
  828. const dReal *qB = dBodyGetQuaternion(bId[1][b]);
  829. CHECK_CLOSE (qA[0], qB[0], 1e-6);
  830. CHECK_CLOSE (qA[1], qB[1], 1e-6);
  831. CHECK_CLOSE (qA[2], qB[2], 1e-6);
  832. CHECK_CLOSE (qA[3], qB[3], 1e-6);
  833. }
  834. dWorldStep (wId,0.5);
  835. dWorldStep (wId,0.5);
  836. dWorldStep (wId,0.5);
  837. dWorldStep (wId,0.5);
  838. for (int b=0; b<2; ++b)
  839. {
  840. // Compare body b of the first joint with its equivalent on the
  841. // second joint
  842. const dReal *qA = dBodyGetQuaternion(bId[0][b]);
  843. const dReal *qB = dBodyGetQuaternion(bId[1][b]);
  844. CHECK_CLOSE (qA[0], qB[0], 1e-6);
  845. CHECK_CLOSE (qA[1], qB[1], 1e-6);
  846. CHECK_CLOSE (qA[2], qB[2], 1e-6);
  847. CHECK_CLOSE (qA[3], qB[3], 1e-6);
  848. const dReal *posA = dBodyGetPosition(bId[0][b]);
  849. const dReal *posB = dBodyGetPosition(bId[1][b]);
  850. CHECK_CLOSE (posA[0], posB[0], 1e-6);
  851. CHECK_CLOSE (posA[1], posB[1], 1e-6);
  852. CHECK_CLOSE (posA[2], posB[2], 1e-6);
  853. CHECK_CLOSE (posA[3], posB[3], 1e-6);
  854. }
  855. }
  856. // Compare Only body 1 to 2 bodies with one fixed.
  857. //
  858. // The body are positionned at (0, 0, 0), with no rotation
  859. // The joint is a Slider Joint
  860. // Axis is along the X axis
  861. // Anchor at (0, 0, 0)
  862. struct Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X
  863. {
  864. Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X()
  865. {
  866. wId = dWorldCreate();
  867. bId1_12 = dBodyCreate (wId);
  868. dBodySetPosition (bId1_12, 0, 0, 0);
  869. bId2_12 = dBodyCreate (wId);
  870. dBodySetPosition (bId2_12, 0, 0, 0);
  871. // The force will be added in the function since it is not
  872. // always on the same body
  873. jId_12 = dJointCreateSlider (wId, 0);
  874. dJointAttach(jId_12, bId1_12, bId2_12);
  875. fixed = dJointCreateFixed (wId, 0);
  876. bId = dBodyCreate (wId);
  877. dBodySetPosition (bId, 0, 0, 0);
  878. dBodyAddForce (bId, 4, 0, 0);
  879. jId = dJointCreateSlider (wId, 0);
  880. }
  881. ~Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X()
  882. {
  883. dWorldDestroy (wId);
  884. }
  885. dWorldID wId;
  886. dBodyID bId1_12;
  887. dBodyID bId2_12;
  888. dJointID jId_12; // Joint with 2 bodies
  889. dJointID fixed;
  890. dBodyID bId;
  891. dJointID jId; // Joint with one body
  892. };
  893. // This test compare the result of a slider with 2 bodies where body body 2 is
  894. // fixed to the world to a slider with only one body at position 1.
  895. //
  896. // Test the limits [-1, 0.25] when only one body at is attached to the joint
  897. // using dJointAttache(jId, bId, 0);
  898. //
  899. TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X,
  900. test_Limit_minus1_025_One_Body_on_left)
  901. {
  902. dBodyAddForce (bId1_12, 4, 0, 0);
  903. dJointAttach(jId_12, bId1_12, bId2_12);
  904. dJointSetSliderParam(jId_12, dParamLoStop, -1);
  905. dJointSetSliderParam(jId_12, dParamHiStop, 0.25);
  906. dJointAttach(fixed, 0, bId2_12);
  907. dJointSetFixed(fixed);
  908. dJointAttach(jId, bId, 0);
  909. dJointSetSliderParam(jId, dParamLoStop, -1);
  910. dJointSetSliderParam(jId, dParamHiStop, 0.25);
  911. for (int i=0; i<50; ++i)
  912. dWorldStep(wId, 1.0);
  913. const dReal *pos1_12 = dBodyGetPosition(bId1_12);
  914. const dReal *pos = dBodyGetPosition(bId);
  915. CHECK_CLOSE (pos[0], pos1_12[0], 1e-2);
  916. CHECK_CLOSE (pos[1], pos1_12[1], 1e-2);
  917. CHECK_CLOSE (pos[2], pos1_12[2], 1e-2);
  918. }
  919. // This test compare the result of a slider with 2 bodies where body body 1 is
  920. // fixed to the world to a slider with only one body at position 2.
  921. //
  922. // Test the limits [-1, 0.25] when only one body at is attached to the joint
  923. // using dJointAttache(jId, 0, bId);
  924. //
  925. TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X,
  926. test_Limit_minus1_025_One_Body_on_right)
  927. {
  928. dBodyAddForce (bId2_12, 4, 0, 0);
  929. dJointAttach(jId_12, bId1_12, bId2_12);
  930. dJointSetSliderParam(jId_12, dParamLoStop, -1);
  931. dJointSetSliderParam(jId_12, dParamHiStop, 0.25);
  932. dJointAttach(fixed, bId1_12, 0);
  933. dJointSetFixed(fixed);
  934. dJointAttach(jId, 0, bId);
  935. dJointSetSliderParam(jId, dParamLoStop, -1);
  936. dJointSetSliderParam(jId, dParamHiStop, 0.25);
  937. for (int i=0; i<50; ++i)
  938. {
  939. dWorldStep(wId, 1.0);
  940. }
  941. const dReal *pos2_12 = dBodyGetPosition(bId2_12);
  942. const dReal *pos = dBodyGetPosition(bId);
  943. CHECK_CLOSE (pos[0], pos2_12[0], 1e-2);
  944. CHECK_CLOSE (pos[1], pos2_12[1], 1e-2);
  945. CHECK_CLOSE (pos[2], pos2_12[2], 1e-2);
  946. }
  947. // This test compare the result of a slider with 2 bodies where body body 2 is
  948. // fixed to the world to a slider with only one body at position 1.
  949. //
  950. // Test the limits [0, 0] when only one body at is attached to the joint
  951. // using dJointAttache(jId, bId, 0);
  952. //
  953. // The body should not move since their is no room between the two limits
  954. //
  955. TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X,
  956. test_Limit_0_0_One_Body_on_left)
  957. {
  958. dBodyAddForce (bId1_12, 4, 0, 0);
  959. dJointAttach(jId_12, bId1_12, bId2_12);
  960. dJointSetSliderParam(jId_12, dParamLoStop, 0);
  961. dJointSetSliderParam(jId_12, dParamHiStop, 0);
  962. dJointAttach(fixed, 0, bId2_12);
  963. dJointSetFixed(fixed);
  964. dJointAttach(jId, bId, 0);
  965. dJointSetSliderParam(jId, dParamLoStop, 0);
  966. dJointSetSliderParam(jId, dParamHiStop, 0);
  967. for (int i=0; i<500; ++i)
  968. dWorldStep(wId, 1.0);
  969. const dReal *pos1_12 = dBodyGetPosition(bId1_12);
  970. const dReal *pos = dBodyGetPosition(bId);
  971. CHECK_CLOSE (pos[0], pos1_12[0], 1e-4);
  972. CHECK_CLOSE (pos[1], pos1_12[1], 1e-4);
  973. CHECK_CLOSE (pos[2], pos1_12[2], 1e-4);
  974. CHECK_CLOSE (pos[0], 0, 1e-4);
  975. CHECK_CLOSE (pos[1], 0, 1e-4);
  976. CHECK_CLOSE (pos[2], 0, 1e-4);
  977. }
  978. // This test compare the result of a slider with 2 bodies where body body 1 is
  979. // fixed to the world to a slider with only one body at position 2.
  980. //
  981. // Test the limits [0, 0] when only one body at is attached to the joint
  982. // using dJointAttache(jId, 0, bId);
  983. //
  984. // The body should not move since their is no room between the two limits
  985. //
  986. TEST_FIXTURE(Fixture_dxJointSlider_Compare_Body_At_Zero_Axis_Along_X,
  987. test_Limit_0_0_One_Body_on_right)
  988. {
  989. dBodyAddForce (bId2_12, 4, 0, 0);
  990. dJointAttach(jId_12, bId1_12, bId2_12);
  991. dJointSetSliderParam(jId_12, dParamLoStop, 0);
  992. dJointSetSliderParam(jId_12, dParamHiStop, 0);
  993. dJointAttach(fixed, bId1_12, 0);
  994. dJointSetFixed(fixed);
  995. dJointAttach(jId, 0, bId);
  996. dJointSetSliderParam(jId, dParamLoStop, 0);
  997. dJointSetSliderParam(jId, dParamHiStop, 0);
  998. for (int i=0; i<500; ++i)
  999. dWorldStep(wId, 1.0);
  1000. const dReal *pos2_12 = dBodyGetPosition(bId2_12);
  1001. const dReal *pos = dBodyGetPosition(bId);
  1002. CHECK_CLOSE (pos[0], pos2_12[0], 1e-4);
  1003. CHECK_CLOSE (pos[1], pos2_12[1], 1e-4);
  1004. CHECK_CLOSE (pos[2], pos2_12[2], 1e-4);
  1005. CHECK_CLOSE (pos[0], 0, 1e-4);
  1006. CHECK_CLOSE (pos[1], 0, 1e-4);
  1007. CHECK_CLOSE (pos[2], 0, 1e-4);
  1008. }
  1009. } // End of SUITE TestdxJointSlider