From de170c02c835072f98cc7347f64f74b143280c56 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Fri, 23 Sep 2011 22:32:49 -0400 Subject: [PATCH] Update Joint APIs --HG-- branch : box2d-update --- src/modules/physics/box2d/PulleyJoint.cpp | 16 ++++++++-------- src/modules/physics/box2d/PulleyJoint.h | 12 ++++++------ src/modules/physics/box2d/RevoluteJoint.cpp | 4 ++-- src/modules/physics/box2d/RevoluteJoint.h | 3 ++- src/modules/physics/box2d/wrap_Joint.cpp | 3 ++- .../physics/box2d/wrap_PrismaticJoint.cpp | 3 ++- src/modules/physics/box2d/wrap_PulleyJoint.cpp | 12 ++++++------ src/modules/physics/box2d/wrap_PulleyJoint.h | 4 ++-- src/modules/physics/box2d/wrap_RevoluteJoint.cpp | 3 ++- 9 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/modules/physics/box2d/PulleyJoint.cpp b/src/modules/physics/box2d/PulleyJoint.cpp index 84e449eaf..a4ce4d08b 100644 --- a/src/modules/physics/box2d/PulleyJoint.cpp +++ b/src/modules/physics/box2d/PulleyJoint.cpp @@ -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 diff --git a/src/modules/physics/box2d/PulleyJoint.h b/src/modules/physics/box2d/PulleyJoint.h index ba1eb201f..fcf5e7349 100644 --- a/src/modules/physics/box2d/PulleyJoint.h +++ b/src/modules/physics/box2d/PulleyJoint.h @@ -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. diff --git a/src/modules/physics/box2d/RevoluteJoint.cpp b/src/modules/physics/box2d/RevoluteJoint.cpp index 1a6251c8d..a80ffe303 100644 --- a/src/modules/physics/box2d/RevoluteJoint.cpp +++ b/src/modules/physics/box2d/RevoluteJoint.cpp @@ -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) diff --git a/src/modules/physics/box2d/RevoluteJoint.h b/src/modules/physics/box2d/RevoluteJoint.h index 4f5a57064..c5b255e23 100644 --- a/src/modules/physics/box2d/RevoluteJoint.h +++ b/src/modules/physics/box2d/RevoluteJoint.h @@ -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. diff --git a/src/modules/physics/box2d/wrap_Joint.cpp b/src/modules/physics/box2d/wrap_Joint.cpp index f71885202..3054e58d2 100644 --- a/src/modules/physics/box2d/wrap_Joint.cpp +++ b/src/modules/physics/box2d/wrap_Joint.cpp @@ -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; } diff --git a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp index bffd37a56..a09344a06 100644 --- a/src/modules/physics/box2d/wrap_PrismaticJoint.cpp +++ b/src/modules/physics/box2d/wrap_PrismaticJoint.cpp @@ -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; } diff --git a/src/modules/physics/box2d/wrap_PulleyJoint.cpp b/src/modules/physics/box2d/wrap_PulleyJoint.cpp index d6a4984fb..111d74822 100644 --- a/src/modules/physics/box2d/wrap_PulleyJoint.cpp +++ b/src/modules/physics/box2d/wrap_PulleyJoint.cpp @@ -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 }, diff --git a/src/modules/physics/box2d/wrap_PulleyJoint.h b/src/modules/physics/box2d/wrap_PulleyJoint.h index 6001a5f85..0f68ba7f1 100644 --- a/src/modules/physics/box2d/wrap_PulleyJoint.h +++ b/src/modules/physics/box2d/wrap_PulleyJoint.h @@ -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); diff --git a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp index d770e03a4..d6517e687 100644 --- a/src/modules/physics/box2d/wrap_RevoluteJoint.cpp +++ b/src/modules/physics/box2d/wrap_RevoluteJoint.cpp @@ -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; }