slider.cpp 41 KB

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