Support reference angle on revolute, prismatic, and weld joints (fixes #1194)

This commit is contained in:
airstruck
2016-08-19 14:36:36 +02:00
parent 78a2e80818
commit 154f7cbc7e
12 changed files with 154 additions and 14 deletions
+9 -3
View File
@@ -219,11 +219,13 @@ int w_newRevoluteJoint(lua_State *L)
float yA = (float)luaL_checknumber(L, 4);
float xB, yB;
bool collideConnected;
float referenceAngle = 0.0f;
if (lua_gettop(L) >= 6)
{
xB = (float)luaL_checknumber(L, 5);
yB = (float)luaL_checknumber(L, 6);
collideConnected = luax_optboolean(L, 7, false);
referenceAngle = (float)luaL_optnumber(L, 8, referenceAngle);
}
else
{
@@ -233,7 +235,7 @@ int w_newRevoluteJoint(lua_State *L)
}
RevoluteJoint *j;
luax_catchexcept(L, [&]() {
j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
j->release();
@@ -248,6 +250,7 @@ int w_newPrismaticJoint(lua_State *L)
float yA = (float)luaL_checknumber(L, 4);
float xB, yB, ax, ay;
bool collideConnected;
float referenceAngle = 0.0f;
if (lua_gettop(L) >= 8)
{
xB = (float)luaL_checknumber(L, 5);
@@ -255,6 +258,7 @@ int w_newPrismaticJoint(lua_State *L)
ax = (float)luaL_checknumber(L, 7);
ay = (float)luaL_checknumber(L, 8);
collideConnected = luax_optboolean(L, 9, false);
referenceAngle = (float)luaL_optnumber(L, 10, referenceAngle);
}
else
{
@@ -266,7 +270,7 @@ int w_newPrismaticJoint(lua_State *L)
}
PrismaticJoint *j;
luax_catchexcept(L, [&]() {
j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
j = instance()->newPrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_PRISMATIC_JOINT_ID, j);
j->release();
@@ -350,11 +354,13 @@ int w_newWeldJoint(lua_State *L)
float yA = (float)luaL_checknumber(L, 4);
float xB, yB;
bool collideConnected;
float referenceAngle = 0.0f;
if (lua_gettop(L) >= 6)
{
xB = (float)luaL_checknumber(L, 5);
yB = (float)luaL_checknumber(L, 6);
collideConnected = luax_optboolean(L, 7, false);
referenceAngle = (float)luaL_optnumber(L, 8, referenceAngle);
}
else
{
@@ -364,7 +370,7 @@ int w_newWeldJoint(lua_State *L)
}
WeldJoint *j;
luax_catchexcept(L, [&]() {
j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
j = instance()->newWeldJoint(body1, body2, xA, yA, xB, yB, collideConnected, referenceAngle);
});
luax_pushtype(L, PHYSICS_WELD_JOINT_ID, j);
j->release();