From d4703960a44baf08bab489d88e8c3ea776528c04 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Tue, 27 Sep 2011 16:38:46 -0400 Subject: [PATCH] Do the same for WheelJoint --HG-- branch : box2d-update --- src/modules/physics/box2d/Physics.cpp | 4 ++-- src/modules/physics/box2d/Physics.h | 8 ++++--- src/modules/physics/box2d/WheelJoint.cpp | 9 ++++---- src/modules/physics/box2d/WheelJoint.h | 2 +- src/modules/physics/box2d/wrap_Physics.cpp | 25 ++++++++++++++++------ 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index 7720b92ea..7ba45f241 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -192,9 +192,9 @@ namespace box2d return new WeldJoint(body1, body2, x, y, collideConnected); } - WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected) + WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected) { - return new WheelJoint(body1, body2, x, y, ax, ay, collideConnected); + return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected); } RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected) diff --git a/src/modules/physics/box2d/Physics.h b/src/modules/physics/box2d/Physics.h index 96ed7989a..2c4491d3f 100644 --- a/src/modules/physics/box2d/Physics.h +++ b/src/modules/physics/box2d/Physics.h @@ -231,13 +231,15 @@ namespace box2d /** * Creates a new WheelJoint connecting body1 with body2. - * @param x Anchor along the x-axis. (World coordinates) - * @param y Anchor along the y-axis. (World coordinates) + * @param xA Anchor for body 1 along the x-axis. (World coordinates) + * @param yA Anchor for body 1 along the y-axis. (World coordinates) + * @param xB Anchor for body 2 along the x-axis. (World coordinates) + * @param yB Anchor for body 2 along the y-axis. (World coordinates) * @param ax The x-component of the world-axis. * @param ay The y-component of the world-axis. * @param collideConnected Whether the connected bodies should collide with each other. Defaults to false. **/ - WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected); + WheelJoint * newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); /** * Creates a new RopeJoint connecting body1 with body2. diff --git a/src/modules/physics/box2d/WheelJoint.cpp b/src/modules/physics/box2d/WheelJoint.cpp index 93e59a910..2a7fb7317 100644 --- a/src/modules/physics/box2d/WheelJoint.cpp +++ b/src/modules/physics/box2d/WheelJoint.cpp @@ -31,12 +31,13 @@ namespace physics { namespace box2d { - WheelJoint::WheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected) + WheelJoint::WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected) : Joint(body1, body2), joint(NULL) { b2WheelJointDef def; - def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)), b2Vec2(ax,ay)); + def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay)); + def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB))); def.collideConnected = collideConnected; joint = (b2WheelJoint*)createJoint(&def); } @@ -49,12 +50,12 @@ namespace box2d float WheelJoint::getJointTranslation() const { - return Physics::scaleDown(joint->GetJointTranslation()); + return Physics::scaleUp(joint->GetJointTranslation()); } float WheelJoint::getJointSpeed() const { - return Physics::scaleDown(joint->GetJointSpeed()); + return Physics::scaleUp(joint->GetJointSpeed()); } void WheelJoint::enableMotor(bool motor) diff --git a/src/modules/physics/box2d/WheelJoint.h b/src/modules/physics/box2d/WheelJoint.h index eb4053636..2f50b14fc 100644 --- a/src/modules/physics/box2d/WheelJoint.h +++ b/src/modules/physics/box2d/WheelJoint.h @@ -47,7 +47,7 @@ namespace box2d /** * Creates a new WheelJoint connecting body1 and body2. **/ - WheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected); + WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); virtual ~WheelJoint(); diff --git a/src/modules/physics/box2d/wrap_Physics.cpp b/src/modules/physics/box2d/wrap_Physics.cpp index dd422f579..0d7f409bc 100644 --- a/src/modules/physics/box2d/wrap_Physics.cpp +++ b/src/modules/physics/box2d/wrap_Physics.cpp @@ -258,12 +258,25 @@ namespace box2d { Body * body1 = luax_checktype(L, 1, "Body", PHYSICS_BODY_T); Body * body2 = luax_checktype(L, 2, "Body", PHYSICS_BODY_T); - float x = (float)luaL_checknumber(L, 3); - float y = (float)luaL_checknumber(L, 4); - float ax = (float)luaL_checknumber(L, 5); - float ay = (float)luaL_checknumber(L, 6); - bool collideConnected = luax_optboolean(L, 7, false); - WheelJoint * j = instance->newWheelJoint(body1, body2, x, y, ax, ay, collideConnected); + float xA = (float)luaL_checknumber(L, 3); + float yA = (float)luaL_checknumber(L, 4); + float xB, yB, ax, ay; + bool collideConnected; + if (lua_gettop(L) >= 8) { + xB = (float)luaL_checknumber(L, 5); + yB = (float)luaL_checknumber(L, 6); + ax = (float)luaL_checknumber(L, 7); + ay = (float)luaL_checknumber(L, 8); + collideConnected = luax_optboolean(L, 9, false); + } else { + xB = xA; + yB = yA; + ax = (float)luaL_checknumber(L, 5); + ay = (float)luaL_checknumber(L, 6); + collideConnected = luax_optboolean(L, 7, false); + } + + WheelJoint * j = instance->newWheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected); luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j); return 1; }