DistanceJoint.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /**
  2. * Copyright (c) 2006-2020 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. #include "DistanceJoint.h"
  21. // Module
  22. #include "Body.h"
  23. #include "World.h"
  24. #include "Physics.h"
  25. namespace love
  26. {
  27. namespace physics
  28. {
  29. namespace box2d
  30. {
  31. DistanceJoint::DistanceJoint(Body *body1, Body *body2, float x1, float y1, float x2, float y2, bool collideConnected)
  32. : Joint(body1, body2)
  33. , joint(NULL)
  34. {
  35. b2DistanceJointDef def;
  36. def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
  37. def.collideConnected = collideConnected;
  38. joint = (b2DistanceJoint *)createJoint(&def);
  39. }
  40. DistanceJoint::~DistanceJoint()
  41. {
  42. }
  43. void DistanceJoint::setLength(float length)
  44. {
  45. joint->SetLength(Physics::scaleDown(length));
  46. }
  47. float DistanceJoint::getLength() const
  48. {
  49. return Physics::scaleUp(joint->GetLength());
  50. }
  51. void DistanceJoint::setStiffness(float hz)
  52. {
  53. joint->SetStiffness(hz);
  54. }
  55. float DistanceJoint::getStiffness() const
  56. {
  57. return joint->GetStiffness();
  58. }
  59. void DistanceJoint::setDamping(float d)
  60. {
  61. joint->SetDamping(d);
  62. }
  63. float DistanceJoint::getDamping() const
  64. {
  65. return joint->GetDamping();
  66. }
  67. } // box2d
  68. } // physics
  69. } // love