2
0

dball.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/dball.cpp
  27. //
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. #include <UnitTest++.h>
  31. #include <ode/ode.h>
  32. #include "../../ode/src/config.h"
  33. using namespace std;
  34. SUITE (TestdxJointDBall)
  35. {
  36. struct SimpleFixture {
  37. dWorldID w;
  38. dBodyID b1, b2;
  39. dJointID j;
  40. SimpleFixture() :
  41. w(dWorldCreate()),
  42. b1(dBodyCreate(w)),
  43. b2(dBodyCreate(w)),
  44. j(dJointCreateDBall(w, 0))
  45. {
  46. dJointAttach(j, b1, b2);
  47. }
  48. ~SimpleFixture()
  49. {
  50. dJointDestroy(j);
  51. dBodyDestroy(b1);
  52. dBodyDestroy(b2);
  53. dWorldDestroy(w);
  54. }
  55. };
  56. TEST_FIXTURE(SimpleFixture, testTargetDistance)
  57. {
  58. dBodySetPosition(b1, -1, -2, -3);
  59. dBodySetPosition(b2, 3, 5, 7);
  60. dJointAttach(j, b1, b2); // this recomputes the deduced target distance
  61. CHECK_CLOSE(dJointGetDBallDistance(j), dSqrt(REAL(165.0)), 1e-4);
  62. // moving body should not change target distance
  63. dBodySetPosition(b1, 2,3,4);
  64. CHECK_CLOSE(dJointGetDBallDistance(j), dSqrt(REAL(165.0)), 1e-4);
  65. // setting target distance manually should override the deduced one
  66. dJointSetDBallDistance(j, REAL(6.0));
  67. CHECK_EQUAL(dJointGetDBallDistance(j), REAL(6.0));
  68. }
  69. }