PrismaticJoint.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. * Copyright (c) 2006-2010 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 "PrismaticJoint.h"
  21. // Module
  22. #include "Body.h"
  23. #include "World.h"
  24. namespace love
  25. {
  26. namespace physics
  27. {
  28. namespace box2d
  29. {
  30. PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
  31. : Joint(body1, body2)
  32. {
  33. b2PrismaticJointDef def;
  34. def.Initialize(body1->body, body2->body, world->scaleDown(b2Vec2(x,y)), b2Vec2(ax,ay));
  35. def.lowerTranslation = 0.0f;
  36. def.upperTranslation = 100.0f;
  37. def.enableLimit = true;
  38. joint = (b2PrismaticJoint*)createJoint(&def);
  39. }
  40. PrismaticJoint::~PrismaticJoint()
  41. {
  42. destroyJoint(joint);
  43. joint = 0;
  44. }
  45. float PrismaticJoint::getJointTranslation() const
  46. {
  47. return world->scaleDown(joint->GetJointTranslation());
  48. }
  49. float PrismaticJoint::getJointSpeed() const
  50. {
  51. return world->scaleDown(joint->GetJointSpeed());
  52. }
  53. void PrismaticJoint::setMotorEnabled(bool motor)
  54. {
  55. return joint->EnableMotor(motor);
  56. }
  57. bool PrismaticJoint::isMotorEnabled() const
  58. {
  59. return joint->IsMotorEnabled();
  60. }
  61. void PrismaticJoint::setMaxMotorForce(float force)
  62. {
  63. joint->SetMaxMotorForce(force);
  64. }
  65. float PrismaticJoint::getMaxMotorForce() const
  66. {
  67. return joint->m_maxMotorForce;
  68. }
  69. void PrismaticJoint::setMotorSpeed(float speed)
  70. {
  71. joint->SetMotorSpeed(speed);
  72. }
  73. float PrismaticJoint::getMotorSpeed() const
  74. {
  75. return joint->GetMotorSpeed();
  76. }
  77. float PrismaticJoint::getMotorForce() const
  78. {
  79. return joint->GetMotorForce();
  80. }
  81. void PrismaticJoint::setLimitsEnabled(bool limit)
  82. {
  83. joint->EnableLimit(limit);
  84. }
  85. bool PrismaticJoint::isLimitsEnabled() const
  86. {
  87. return joint->IsLimitEnabled();
  88. }
  89. void PrismaticJoint::setUpperLimit(float limit)
  90. {
  91. joint->SetLimits(joint->GetLowerLimit(), world->scaleDown(limit));
  92. }
  93. void PrismaticJoint::setLowerLimit(float limit)
  94. {
  95. joint->SetLimits(world->scaleDown(limit), joint->GetUpperLimit());
  96. }
  97. void PrismaticJoint::setLimits(float lower, float upper)
  98. {
  99. joint->SetLimits(world->scaleDown(lower), world->scaleDown(upper));
  100. }
  101. float PrismaticJoint::getLowerLimit() const
  102. {
  103. return world->scaleUp(joint->GetLowerLimit());
  104. }
  105. float PrismaticJoint::getUpperLimit() const
  106. {
  107. return world->scaleUp(joint->GetUpperLimit());
  108. }
  109. int PrismaticJoint::getLimits(lua_State * L)
  110. {
  111. lua_pushnumber(L, world->scaleUp(joint->GetLowerLimit()));
  112. lua_pushnumber(L, world->scaleUp(joint->GetUpperLimit()));
  113. return 2;
  114. }
  115. } // box2d
  116. } // physics
  117. } // love