int w_Body_setMassData(lua_State *L) { Body *t = luax_checkbody(L, 1); float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); float m = (float)luaL_checknumber(L, 4); float i = (float)luaL_checknumber(L, 5); luax_catchexcept(L, [&](){ t->setMassData(x, y, m, i); }); return 0; }
int w_Body_setMass(lua_State * L) { Body * t = luax_checkbody(L, 1); float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); float m = (float)luaL_checknumber(L, 4); float i = (float)luaL_checknumber(L, 5); t->setMass(x, y, m, i); return 0; }
int w_Body_getPosition(lua_State * L) { Body * t = luax_checkbody(L, 1); float x_o, y_o; t->getPosition(x_o, y_o); lua_pushnumber(L, x_o); lua_pushnumber(L, y_o); return 2; }
int w_Body_getLinearVelocity(lua_State * L) { Body * t = luax_checkbody(L, 1); float x_o, y_o; t->getLinearVelocity(x_o, y_o); lua_pushnumber(L, x_o); lua_pushnumber(L, y_o); return 2; }
int w_Body_getLocalCenter(lua_State * L) { Body * t = luax_checkbody(L, 1); float x_o, y_o; t->getLocalCenter(x_o, y_o); lua_pushnumber(L, x_o); lua_pushnumber(L, y_o); return 2; }
int w_Body_getLocalVector(lua_State * L) { Body * t = luax_checkbody(L, 1); float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); float x_o, y_o; t->getLocalVector(x, y, x_o, y_o); lua_pushnumber(L, x_o); lua_pushnumber(L, y_o); return 2; }
int w_Body_getLinearVelocityFromLocalPoint(lua_State * L) { Body * t = luax_checkbody(L, 1); float x = (float)luaL_checknumber(L, 2); float y = (float)luaL_checknumber(L, 3); float x_o, y_o; t->getLinearVelocityFromLocalPoint(x, y, x_o, y_o); lua_pushnumber(L, x_o); lua_pushnumber(L, y_o); return 2; }
int Physics::newPolygonShape(lua_State * L) { int argc = lua_gettop(L); int vcount = (int)(argc-1)/2; // 1 body + 3 vertices love::luax_assert_argc(L, 1 + (2 * 3)); Body * b = luax_checkbody(L, 1); b2PolygonDef def; def.friction = 0.5f; def.restitution = 0.1f; def.density = 1.0f; std::vector<point2d> points(def.vertexCount); std::vector<point2d> convex_hull; for(int i = 0;i<vcount;i++) { float x = (float)lua_tonumber(L, -2); float y = (float)lua_tonumber(L, -1); point2d tmp(x, y); points.push_back(tmp); lua_pop(L, 2); } // Compute convex hull. GrahamScanConvexHull()(points, convex_hull); def.vertexCount = (int32)convex_hull.size(); if(def.vertexCount < 3) return luaL_error(L, "Polygon degenerated to less than three points."); for(int i = 0;i<def.vertexCount;i++) def.vertices[def.vertexCount-i-1].Set((float)convex_hull[i].x, (float)convex_hull[i].y); PolygonShape * p = new PolygonShape(b, &def); luax_newtype(L, "PolygonShape", LOVE_PHYSICS_POLYGON_SHAPE_BITS, (void*)p); return 1; }
int w_Body_applyImpulse(lua_State * L) { Body * t = luax_checkbody(L, 1); float jx = (float)luaL_checknumber(L, 2); float jy = (float)luaL_checknumber(L, 3); 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; }
int w_Body_setMassFromShapes(lua_State * L) { Body * t = luax_checkbody(L, 1); t->setMassFromShapes(); return 0; }
int w_Body_resetMassData(lua_State *L) { Body *t = luax_checkbody(L, 1); luax_catchexcept(L, [&](){ t->resetMassData(); }); return 0; }
int w_Body_getWorldPoints(lua_State *L) { Body *t = luax_checkbody(L, 1); lua_remove(L, 1); return t->getWorldPoints(L); }
int w_Body_getAngle(lua_State * L) { Body * t = luax_checkbody(L, 1); lua_pushnumber(L, t->getAngle()); return 1; }
int w_Body_wakeUp(lua_State * L) { Body * t = luax_checkbody(L, 1); t->wakeUp(); return 0; }
int w_Body_putToSleep(lua_State * L) { Body * t = luax_checkbody(L, 1); t->putToSleep(); return 0; }
int w_Body_getAllowSleeping(lua_State * L) { Body * t = luax_checkbody(L, 1); lua_pushboolean(L, t->getAllowSleeping()); return 1; }
int w_Body_isFrozen(lua_State * L) { Body * t = luax_checkbody(L, 1); luax_pushboolean(L, t->isFrozen()); return 1; }
int w_Body_isSleepingAllowed(lua_State *L) { Body *t = luax_checkbody(L, 1); lua_pushboolean(L, t->isSleepingAllowed()); return 1; }
int w_Body_destroy(lua_State *L) { Body *t = luax_checkbody(L, 1); luax_catchexcept(L, [&](){ t->destroy(); }); return 0; }
int w_Body_getUserData(lua_State *L) { Body *t = luax_checkbody(L, 1); lua_remove(L, 1); return t->getUserData(L); }
int w_Body_resetMassData(lua_State * L) { Body * t = luax_checkbody(L, 1); t->resetMassData(); return 0; }
int w_Body_getLinearDamping(lua_State * L) { Body * t = luax_checkbody(L, 1); lua_pushnumber(L, t->getLinearDamping()); return 1; }
int w_Body_getAngularVelocity(lua_State * L) { Body * t = luax_checkbody(L, 1); lua_pushnumber(L, t->getAngularVelocity()); return 1; }