123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- /**
- * Copyright (c) 2006-2012 LOVE Development Team
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- *
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- **/
- #include "wrap_Body.h"
- namespace love
- {
- namespace physics
- {
- namespace box2d
- {
- Body * luax_checkbody(lua_State * L, int idx)
- {
- Body * b = luax_checktype<Body>(L, idx, "Body", PHYSICS_BODY_T);
- if (b->body == 0)
- luaL_error(L, "Attempt to use destroyed body.");
- return b;
- }
- int w_Body_getX(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getX());
- return 1;
- }
- int w_Body_getY(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getY());
- return 1;
- }
- int w_Body_getAngle(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getAngle());
- return 1;
- }
- 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_getWorldCenter(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float x_o, y_o;
- t->getWorldCenter(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_getAngularVelocity(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getAngularVelocity());
- return 1;
- }
- int w_Body_getMass(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getMass());
- return 1;
- }
- int w_Body_getInertia(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getInertia());
- return 1;
- }
- int w_Body_getMassData(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_remove(L, 1);
- return t->getMassData(L);
- }
- int w_Body_getAngularDamping(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getAngularDamping());
- return 1;
- }
- int w_Body_getLinearDamping(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getLinearDamping());
- return 1;
- }
- int w_Body_getGravityScale(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushnumber(L, t->getGravityScale());
- return 1;
- }
- int w_Body_getType(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- const char * type = "";
- Body::getConstant(t->getType(), type);
- lua_pushstring(L, type);
- return 1;
- }
- int w_Body_applyLinearImpulse(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->applyLinearImpulse(jx, jy);
- }
- else if (lua_gettop(L) == 5)
- {
- float rx = (float)luaL_checknumber(L, 4);
- float ry = (float)luaL_checknumber(L, 5);
- t->applyLinearImpulse(jx, jy, rx, ry);
- }
- else
- {
- return luaL_error(L, "Wrong number of parameters.");
- }
- return 0;
- }
- int w_Body_applyAngularImpulse(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float i = (float)luaL_checknumber(L, 2);
- t->applyAngularImpulse(i);
- return 0;
- }
- int w_Body_applyTorque(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg = (float)luaL_checknumber(L, 2);
- t->applyTorque(arg);
- return 0;
- }
- int w_Body_applyForce(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float fx = (float)luaL_checknumber(L, 2);
- float fy = (float)luaL_checknumber(L, 3);
- 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;
- }
- int w_Body_setX(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setX(arg1);
- return 0;
- }
- int w_Body_setY(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setY(arg1);
- return 0;
- }
- int w_Body_setLinearVelocity(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- float arg2 = (float)luaL_checknumber(L, 3);
- t->setLinearVelocity(arg1, arg2);
- return 0;
- }
- int w_Body_setAngle(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setAngle(arg1);
- return 0;
- }
- int w_Body_setAngularVelocity(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setAngularVelocity(arg1);
- return 0;
- }
- int w_Body_setPosition(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- float arg2 = (float)luaL_checknumber(L, 3);
- t->setPosition(arg1, arg2);
- return 0;
- }
- int w_Body_resetMassData(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- t->resetMassData();
- return 0;
- }
- 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);
- t->setMassData(x, y, m, i);
- return 0;
- }
- int w_Body_setMass(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float m = (float)luaL_checknumber(L, 2);
- t->setMass(m);
- return 0;
- }
- int w_Body_setInertia(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float i = (float)luaL_checknumber(L, 2);
- t->setInertia(i);
- return 0;
- }
- int w_Body_setAngularDamping(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setAngularDamping(arg1);
- return 0;
- }
- int w_Body_setLinearDamping(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setLinearDamping(arg1);
- return 0;
- }
- int w_Body_setGravityScale(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- float arg1 = (float)luaL_checknumber(L, 2);
- t->setGravityScale(arg1);
- return 0;
- }
- int w_Body_setType(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- const char * typeStr = luaL_checkstring(L, 2);
- Body::Type type;
- Body::getConstant(typeStr, type);
- t->setType(type);
- return 0;
- }
- int w_Body_getWorldPoint(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->getWorldPoint(x, y, x_o, y_o);
- lua_pushnumber(L, x_o);
- lua_pushnumber(L, y_o);
- return 2;
- }
- int w_Body_getWorldVector(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->getWorldVector(x, y, x_o, y_o);
- lua_pushnumber(L, x_o);
- lua_pushnumber(L, y_o);
- return 2;
- }
- int w_Body_getWorldPoints(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_remove(L, 1);
- return t->getWorldPoints(L);
- }
- int w_Body_getLocalPoint(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->getLocalPoint(x, y, 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_getLinearVelocityFromWorldPoint(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->getLinearVelocityFromWorldPoint(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 w_Body_isBullet(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- luax_pushboolean(L, t->isBullet());
- return 1;
- }
- int w_Body_setBullet(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = luax_toboolean(L, 2);
- t->setBullet(b);
- return 0;
- }
- int w_Body_isActive(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- luax_pushboolean(L, t->isActive());
- return 1;
- }
- int w_Body_isAwake(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- luax_pushboolean(L, t->isAwake());
- return 1;
- }
- int w_Body_setSleepingAllowed(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = luax_toboolean(L, 2);
- t->setSleepingAllowed(b);
- return 0;
- }
- int w_Body_isSleepingAllowed(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_pushboolean(L, t->isSleepingAllowed());
- return 1;
- }
- int w_Body_setActive(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = luax_toboolean(L, 2);
- t->setActive(b);
- return 0;
- }
- int w_Body_setAwake(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = luax_toboolean(L, 2);
- t->setAwake(b);
- return 0;
- }
- int w_Body_setFixedRotation(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = luax_toboolean(L, 2);
- t->setFixedRotation(b);
- return 0;
- }
- int w_Body_isFixedRotation(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- bool b = t->isFixedRotation();
- luax_pushboolean(L, b);
- return 1;
- }
- int w_Body_getFixtureList(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- lua_remove(L, 1);
- return t->getFixtureList(L);
- }
- int w_Body_destroy(lua_State * L)
- {
- Body * t = luax_checkbody(L, 1);
- try
- {
- t->destroy();
- }
- catch (love::Exception & e)
- {
- luaL_error(L, "%s", e.what());
- }
- return 0;
- }
- static const luaL_Reg functions[] = {
- { "getX", w_Body_getX },
- { "getY", w_Body_getY },
- { "getAngle", w_Body_getAngle },
- { "getPosition", w_Body_getPosition },
- { "getLinearVelocity", w_Body_getLinearVelocity },
- { "getWorldCenter", w_Body_getWorldCenter },
- { "getLocalCenter", w_Body_getLocalCenter },
- { "getAngularVelocity", w_Body_getAngularVelocity },
- { "getMass", w_Body_getMass },
- { "getInertia", w_Body_getInertia },
- { "getMassData", w_Body_getMassData },
- { "getAngularDamping", w_Body_getAngularDamping },
- { "getLinearDamping", w_Body_getLinearDamping },
- { "getGravityScale", w_Body_getGravityScale },
- { "getType", w_Body_getType },
- { "applyLinearImpulse", w_Body_applyLinearImpulse },
- { "applyAngularImpulse", w_Body_applyAngularImpulse },
- { "applyTorque", w_Body_applyTorque },
- { "applyForce", w_Body_applyForce },
- { "setX", w_Body_setX },
- { "setY", w_Body_setY },
- { "setLinearVelocity", w_Body_setLinearVelocity },
- { "setAngle", w_Body_setAngle },
- { "setAngularVelocity", w_Body_setAngularVelocity },
- { "setPosition", w_Body_setPosition },
- { "resetMassData", w_Body_resetMassData },
- { "setMassData", w_Body_setMassData },
- { "setMass", w_Body_setMass },
- { "setInertia", w_Body_setInertia },
- { "setAngularDamping", w_Body_setAngularDamping },
- { "setLinearDamping", w_Body_setLinearDamping },
- { "setGravityScale", w_Body_setGravityScale },
- { "setType", w_Body_setType },
- { "getWorldPoint", w_Body_getWorldPoint },
- { "getWorldVector", w_Body_getWorldVector },
- { "getWorldPoints", w_Body_getWorldPoints },
- { "getLocalPoint", w_Body_getLocalPoint },
- { "getLocalVector", w_Body_getLocalVector },
- { "getLinearVelocityFromWorldPoint", w_Body_getLinearVelocityFromWorldPoint },
- { "getLinearVelocityFromLocalPoint", w_Body_getLinearVelocityFromLocalPoint },
- { "isBullet", w_Body_isBullet },
- { "setBullet", w_Body_setBullet },
- { "isActive", w_Body_isActive },
- { "isAwake", w_Body_isAwake },
- { "setSleepingAllowed", w_Body_setSleepingAllowed },
- { "isSleepingAllowed", w_Body_isSleepingAllowed },
- { "setActive", w_Body_setActive },
- { "setAwake", w_Body_setAwake },
- { "setFixedRotation", w_Body_setFixedRotation },
- { "isFixedRotation", w_Body_isFixedRotation },
- { "getFixtureList", w_Body_getFixtureList },
- { "destroy", w_Body_destroy },
- { 0, 0 }
- };
- extern "C" int luaopen_body(lua_State * L)
- {
- return luax_register_type(L, "Body", functions);
- }
- } // box2d
- } // physics
- } // love
|