Update Joint APIs

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-23 22:32:49 -04:00
parent 6e7d83d7ea
commit de170c02c8
9 changed files with 32 additions and 28 deletions
+8 -8
View File
@@ -31,12 +31,12 @@ namespace physics
{
namespace box2d
{
PulleyJoint::PulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected)
: Joint(body1, body2), joint(NULL)
PulleyJoint::PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
: Joint(bodyA, bodyB), joint(NULL)
{
b2PulleyJointDef def;
def.Initialize(body1->body, body2->body, Physics::scaleDown(groundAnchor1), Physics::scaleDown(groundAnchor2), \
Physics::scaleDown(anchor1), Physics::scaleDown(anchor2), ratio);
def.Initialize(bodyA->body, bodyB->body, Physics::scaleDown(groundAnchorA), Physics::scaleDown(groundAnchorB), \
Physics::scaleDown(anchorA), Physics::scaleDown(anchorB), ratio);
def.collideConnected = collideConnected;
joint = (b2PulleyJoint*)createJoint(&def);
@@ -57,14 +57,14 @@ namespace box2d
return 4;
}
float PulleyJoint::getLength1() const
float PulleyJoint::getLengthA() const
{
return Physics::scaleUp(joint->GetLength1());
return Physics::scaleUp(joint->GetLengthA());
}
float PulleyJoint::getLength2() const
float PulleyJoint::getLengthB() const
{
return Physics::scaleUp(joint->GetLength2());
return Physics::scaleUp(joint->GetLengthB());
}
float PulleyJoint::getRatio() const
+6 -6
View File
@@ -44,9 +44,9 @@ namespace box2d
public:
/**
* Creates a PulleyJoint connecting body1 to body2.
* Creates a PulleyJoint connecting bodyA to bodyB.
**/
PulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected);
PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected);
virtual ~PulleyJoint();
@@ -57,14 +57,14 @@ namespace box2d
int getGroundAnchors(lua_State * L);
/**
* Gets the current length of the segment attached to body1.
* Gets the current length of the segment attached to bodyA.
**/
float getLength1() const;
float getLengthA() const;
/**
* Gets the current length of the segment attached to body2.
* Gets the current length of the segment attached to bodyB.
**/
float getLength2() const;
float getLengthB() const;
/**
* Gets the pulley ratio.
+2 -2
View File
@@ -83,9 +83,9 @@ namespace box2d
return joint->GetMotorSpeed();
}
float RevoluteJoint::getMotorTorque() const
float RevoluteJoint::getMotorTorque(float inv_dt) const
{
return joint->GetMotorTorque();
return joint->GetMotorTorque(inv_dt);
}
void RevoluteJoint::enableLimit(bool limit)
+2 -1
View File
@@ -87,8 +87,9 @@ namespace box2d
/**
* Get the current motor torque, usually in N-m.
* @param inv_dt The inverse timestep.
**/
float getMotorTorque() const;
float getMotorTorque(float inv_dt) const;
/**
* Enable/disable the joint limit.
+2 -1
View File
@@ -59,7 +59,8 @@ namespace box2d
int w_Joint_getReactionTorque(lua_State * L)
{
Joint * t = luax_checkjoint(L, 1);
lua_pushnumber(L, t->getReactionTorque());
float inv_dt = (float)luaL_checknumber(L, 2);
lua_pushnumber(L, t->getReactionTorque(inv_dt));
return 1;
}
@@ -86,7 +86,8 @@ namespace box2d
int w_PrismaticJoint_getMotorForce(lua_State * L)
{
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
lua_pushnumber(L, t->getMotorForce());
float inv_dt = (float)luaL_checknumber(L, 2);
lua_pushnumber(L, t->getMotorForce(inv_dt));
return 1;
}
@@ -38,17 +38,17 @@ namespace box2d
return t->getGroundAnchors(L);
}
int w_PulleyJoint_getLength1(lua_State * L)
int w_PulleyJoint_getLengthA(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
lua_pushnumber(L, t->getLength1());
lua_pushnumber(L, t->getLengthA());
return 1;
}
int w_PulleyJoint_getLength2(lua_State * L)
int w_PulleyJoint_getLengthB(lua_State * L)
{
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
lua_pushnumber(L, t->getLength2());
lua_pushnumber(L, t->getLengthB());
return 1;
}
@@ -61,8 +61,8 @@ namespace box2d
static const luaL_Reg functions[] = {
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
{ "getLength1", w_PulleyJoint_getLength1 },
{ "getLength2", w_PulleyJoint_getLength2 },
{ "getLengthA", w_PulleyJoint_getLengthA },
{ "getLengthB", w_PulleyJoint_getLengthB },
{ "getRatio", w_PulleyJoint_getRatio },
// From Joint.
{ "getType", w_Joint_getType },
+2 -2
View File
@@ -34,8 +34,8 @@ namespace box2d
{
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx);
int w_PulleyJoint_getGroundAnchors(lua_State * L);
int w_PulleyJoint_getLength1(lua_State * L);
int w_PulleyJoint_getLength2(lua_State * L);
int w_PulleyJoint_getLengthA(lua_State * L);
int w_PulleyJoint_getLengthB(lua_State * L);
int w_PulleyJoint_getRatio(lua_State * L);
int luaopen_pulleyjoint(lua_State * L);
@@ -86,7 +86,8 @@ namespace box2d
int w_RevoluteJoint_getMotorTorque(lua_State * L)
{
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
lua_pushnumber(L, t->getMotorTorque());
float inv_dt = (float)luaL_checknumber(L, 2);
lua_pushnumber(L, t->getMotorTorque(inv_dt));
return 1;
}