Add Body:isTouching(otherbody). See issue #1365.

This commit is contained in:
Alex Szpakowski
2018-01-14 14:37:48 -04:00
parent ac52666c6f
commit 02e115c339
3 changed files with 27 additions and 0 deletions
+16
View File
@@ -422,6 +422,22 @@ bool Body::isFixedRotation() const
return body->IsFixedRotation();
}
bool Body::isTouching(Body *other) const
{
const b2ContactEdge *ce = body->GetContactList();
b2Body *otherbody = other->body;
while (ce != nullptr)
{
if (ce->other == otherbody)
return true;
ce = ce->next;
}
return false;
}
World *Body::getWorld() const
{
return world;
+2
View File
@@ -382,6 +382,8 @@ public:
void setFixedRotation(bool fixed);
bool isFixedRotation() const;
bool isTouching(Body *other) const;
/**
* Get the World this Body resides in.
*/
+9
View File
@@ -522,6 +522,14 @@ int w_Body_isFixedRotation(lua_State *L)
return 1;
}
int w_Body_isTouching(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
Body *other = luax_checkbody(L, 2);
luax_pushboolean(L, t->isTouching(other));
return 1;
}
int w_Body_getWorld(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
@@ -655,6 +663,7 @@ static const luaL_Reg w_Body_functions[] =
{ "setAwake", w_Body_setAwake },
{ "setFixedRotation", w_Body_setFixedRotation },
{ "isFixedRotation", w_Body_isFixedRotation },
{ "isTouching", w_Body_isTouching },
{ "getWorld", w_Body_getWorld },
{ "getFixtures", w_Body_getFixtures },
{ "getJoints", w_Body_getJoints },