From f3d1517a9a8175f4a9d67cac1174d56d7d5f8509 Mon Sep 17 00:00:00 2001 From: rude Date: Sun, 22 Nov 2009 13:53:07 +0100 Subject: [PATCH] Fixed offset bug in body:applyImpulse and body:applyForce. --- src/modules/physics/box2d/Body.cpp | 4 +-- src/modules/physics/box2d/wrap_Body.cpp | 39 +++++++++++++++++++++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/modules/physics/box2d/Body.cpp b/src/modules/physics/box2d/Body.cpp index d32c83696..da0afa741 100644 --- a/src/modules/physics/box2d/Body.cpp +++ b/src/modules/physics/box2d/Body.cpp @@ -118,7 +118,7 @@ namespace box2d void Body::applyImpulse(float jx, float jy) { - body->ApplyImpulse(b2Vec2(jx, jy), world->scaleDown(body->GetWorldCenter())); + body->ApplyImpulse(b2Vec2(jx, jy), body->GetWorldCenter()); } void Body::applyImpulse(float jx, float jy, float rx, float ry) @@ -138,7 +138,7 @@ namespace box2d void Body::applyForce(float fx, float fy) { - body->ApplyForce(b2Vec2(fx, fy), world->scaleDown(body->GetWorldCenter())); + body->ApplyForce(b2Vec2(fx, fy), body->GetWorldCenter()); } void Body::setX(float x) diff --git a/src/modules/physics/box2d/wrap_Body.cpp b/src/modules/physics/box2d/wrap_Body.cpp index 88ffd18dc..b699fddb6 100644 --- a/src/modules/physics/box2d/wrap_Body.cpp +++ b/src/modules/physics/box2d/wrap_Body.cpp @@ -140,9 +140,22 @@ namespace box2d Body * t = luax_checkbody(L, 1); float jx = (float)luaL_checknumber(L, 2); float jy = (float)luaL_checknumber(L, 3); - float rx = (float)luaL_optnumber(L, 4, 0); - float ry = (float)luaL_optnumber(L, 5, 0); - t->applyImpulse(jx, jy, rx, ry); + + if(lua_gettop(L) == 3) + { + t->applyImpulse(jx, jy); + } + else if(lua_gettop(L) == 5) + { + float rx = (float)luaL_checknumber(L, 4); + float ry = (float)luaL_checknumber(L, 5); + t->applyImpulse(jx, jy, rx, ry); + } + else + { + return luaL_error(L, "Wrong number of parameters."); + } + return 0; } @@ -159,9 +172,23 @@ namespace box2d Body * t = luax_checkbody(L, 1); float fx = (float)luaL_checknumber(L, 2); float fy = (float)luaL_checknumber(L, 3); - float rx = (float)luaL_optnumber(L, 4, 0); - float ry = (float)luaL_optnumber(L, 5, 0); - t->applyForce(fx, fy, rx, ry); + + + if(lua_gettop(L) == 3) + { + t->applyForce(fx, fy); + } + else if(lua_gettop(L) == 5) + { + float rx = (float)luaL_checknumber(L, 4); + float ry = (float)luaL_checknumber(L, 5); + t->applyForce(fx, fy, rx, ry); + } + else + { + return luaL_error(L, "Wrong number of parameters."); + } + return 0; }