fixed.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/fixed.cpp
  27. //
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. #include <UnitTest++.h>
  31. #include <ode/ode.h>
  32. #include "../../ode/src/config.h"
  33. #include "../../ode/src/joints/fixed.h"
  34. SUITE (TestdxJointFixed)
  35. {
  36. struct dxJointFixed_Fixture_1
  37. {
  38. dxJointFixed_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 = dJointCreateFixed (wId, 0);
  46. joint = (dxJointFixed*) jId;
  47. dJointAttach (jId, bId1, bId2);
  48. }
  49. ~dxJointFixed_Fixture_1()
  50. {
  51. dWorldDestroy (wId);
  52. }
  53. dWorldID wId;
  54. dBodyID bId1;
  55. dBodyID bId2;
  56. dJointID jId;
  57. dxJointFixed* joint;
  58. };
  59. TEST_FIXTURE (dxJointFixed_Fixture_1, test_dJointSetFixed)
  60. {
  61. // the 2 bodies are align
  62. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. } // End of SUITE TestdxJointFixed