fixed.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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/joints/fixed.h"
  33. SUITE (TestdxJointFixed)
  34. {
  35. struct dxJointFixed_Fixture_1
  36. {
  37. dxJointFixed_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 = dJointCreateFixed (wId, 0);
  45. joint = (dxJointFixed*) jId;
  46. dJointAttach (jId, bId1, bId2);
  47. }
  48. ~dxJointFixed_Fixture_1()
  49. {
  50. dWorldDestroy (wId);
  51. }
  52. dWorldID wId;
  53. dBodyID bId1;
  54. dBodyID bId2;
  55. dJointID jId;
  56. dxJointFixed* joint;
  57. };
  58. TEST_FIXTURE (dxJointFixed_Fixture_1, test_dJointSetFixed)
  59. {
  60. // the 2 bodies are align
  61. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. dJointSetFixed (jId);
  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. } // End of SUITE TestdxJointFixed