Add EdgeShape:set/getNext/PreviousVertex. ChainShape:setNext/PreviousVertex can now take no arguments to disable ghost vertices.

Resolves issue #1191.
This commit is contained in:
Alex Szpakowski
2016-08-01 10:15:34 -03:00
parent 2e8f785a01
commit fc2c79ad5f
6 changed files with 183 additions and 47 deletions
+24 -16
View File
@@ -37,18 +37,28 @@ ChainShape *luax_checkchainshape(lua_State *L, int idx)
int w_ChainShape_setNextVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
if (lua_isnoneornil(L, 2))
c->setNextVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
}
return 0;
}
int w_ChainShape_setPreviousVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
if (lua_isnoneornil(L, 2))
c->setPreviousVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
}
return 0;
}
@@ -85,12 +95,11 @@ int w_ChainShape_getPoint(lua_State *L)
int w_ChainShape_getNextVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
if (c->hasNextVertex())
float x, y;
if (c->getNextVertex(x, y))
{
b2Vec2 v;
luax_catchexcept(L, [&](){ v = c->getNextVertex(); });
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;
@@ -99,12 +108,11 @@ int w_ChainShape_getNextVertex(lua_State *L)
int w_ChainShape_getPreviousVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
if (c->hasPreviousVertex())
float x, y;
if (c->getPreviousVertex(x, y))
{
b2Vec2 v;
luax_catchexcept(L, [&](){ v = c->getPreviousVertex(); });
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;