diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index e2e6be22e..7720b92ea 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -167,9 +167,9 @@ namespace box2d return new RevoluteJoint(body1, body2, x, y, collideConnected); } - PrismaticJoint * Physics::newPrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected) + PrismaticJoint * Physics::newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected) { - return new PrismaticJoint(body1, body2, x, y, ax, ay, collideConnected); + return new PrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected); } PulleyJoint * Physics::newPulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected) diff --git a/src/modules/physics/box2d/Physics.h b/src/modules/physics/box2d/Physics.h index 127e28ec2..96ed7989a 100644 --- a/src/modules/physics/box2d/Physics.h +++ b/src/modules/physics/box2d/Physics.h @@ -183,13 +183,15 @@ namespace box2d /** * Creates a new PrismaticJoint connecting body1 with body2. - * @param x World-anchor along the x-axis. - * @param y World-anchor along the y-axis. + * @param xA World-anchor for body1 along the x-axis. + * @param yA World-anchor for body1 along the y-axis. + * @param xB World-anchor for body2 along the x-axis. + * @param yB World-anchor for body2 along the y-axis. * @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. **/ - PrismaticJoint * newPrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected); + PrismaticJoint * newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); /** * Creates a new PulleyJoint connecting body1 with body2. diff --git a/src/modules/physics/box2d/PrismaticJoint.cpp b/src/modules/physics/box2d/PrismaticJoint.cpp index 17b6b1c7e..276cb5493 100644 --- a/src/modules/physics/box2d/PrismaticJoint.cpp +++ b/src/modules/physics/box2d/PrismaticJoint.cpp @@ -31,12 +31,13 @@ namespace physics { namespace box2d { - PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected) + PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected) : Joint(body1, body2), joint(NULL) { b2PrismaticJointDef 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.lowerTranslation = 0.0f; def.upperTranslation = 100.0f; def.enableLimit = true; @@ -52,12 +53,12 @@ namespace box2d float PrismaticJoint::getJointTranslation() const { - return Physics::scaleDown(joint->GetJointTranslation()); + return Physics::scaleUp(joint->GetJointTranslation()); } float PrismaticJoint::getJointSpeed() const { - return Physics::scaleDown(joint->GetJointSpeed()); + return Physics::scaleUp(joint->GetJointSpeed()); } void PrismaticJoint::enableMotor(bool motor) diff --git a/src/modules/physics/box2d/PrismaticJoint.h b/src/modules/physics/box2d/PrismaticJoint.h index 5e0c39222..b7c5efeec 100644 --- a/src/modules/physics/box2d/PrismaticJoint.h +++ b/src/modules/physics/box2d/PrismaticJoint.h @@ -46,7 +46,7 @@ namespace box2d /** * Creates a new PrismaticJoint connecting body1 and body2. **/ - PrismaticJoint(Body * body1, Body * body2, float x, float y, float ax, float ay, bool collideConnected); + PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected); virtual ~PrismaticJoint(); diff --git a/src/modules/physics/box2d/wrap_Physics.cpp b/src/modules/physics/box2d/wrap_Physics.cpp index 89d82424c..dd422f579 100644 --- a/src/modules/physics/box2d/wrap_Physics.cpp +++ b/src/modules/physics/box2d/wrap_Physics.cpp @@ -176,12 +176,24 @@ 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); - PrismaticJoint * j = instance->newPrismaticJoint(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); + } + PrismaticJoint * j = instance->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected); luax_newtype(L, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T, (void*)j); return 1; }