DistanceJoint.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2006-2011 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), joint(NULL)
  33. {
  34. b2DistanceJointDef def;
  35. def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
  36. def.collideConnected = collideConnected;
  37. joint = (b2DistanceJoint*)createJoint(&def);
  38. }
  39. DistanceJoint::~DistanceJoint()
  40. {
  41. }
  42. void DistanceJoint::setLength(float length)
  43. {
  44. joint->SetLength(Physics::scaleDown(length));
  45. }
  46. float DistanceJoint::getLength() const
  47. {
  48. return Physics::scaleUp(joint->GetLength());
  49. }
  50. void DistanceJoint::setFrequency(float hz)
  51. {
  52. joint->SetFrequency(hz);
  53. }
  54. float DistanceJoint::getFrequency() const
  55. {
  56. return joint->GetFrequency();
  57. }
  58. void DistanceJoint::setDampingRatio(float d)
  59. {
  60. joint->SetDampingRatio(d);
  61. }
  62. float DistanceJoint::getDampingRatio() const
  63. {
  64. return joint->GetDampingRatio();
  65. }
  66. } // box2d
  67. } // physics
  68. } // love