mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Added Joint:getBodies (see issue #922.)
This commit is contained in:
@@ -95,6 +95,32 @@ Joint::Type Joint::getType() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Body *Joint::getBodyA() const
|
||||||
|
{
|
||||||
|
b2Body *b2body = joint->GetBodyA();
|
||||||
|
if (b2body == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
Body *body = (Body *) Memoizer::find(b2body);
|
||||||
|
if (body == nullptr)
|
||||||
|
throw love::Exception("A body has escaped Memoizer!");
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
|
Body *Joint::getBodyB() const
|
||||||
|
{
|
||||||
|
b2Body *b2body = joint->GetBodyB();
|
||||||
|
if (b2body == nullptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
Body *body = (Body *) Memoizer::find(b2body);
|
||||||
|
if (body == nullptr)
|
||||||
|
throw love::Exception("A body has escaped Memoizer!");
|
||||||
|
|
||||||
|
return body;
|
||||||
|
}
|
||||||
|
|
||||||
bool Joint::isValid() const
|
bool Joint::isValid() const
|
||||||
{
|
{
|
||||||
return joint != 0;
|
return joint != 0;
|
||||||
|
|||||||
@@ -79,12 +79,14 @@ public:
|
|||||||
**/
|
**/
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the type of joint.
|
* Gets the type of joint.
|
||||||
**/
|
**/
|
||||||
Type getType() const;
|
Type getType() const;
|
||||||
|
|
||||||
|
Body *getBodyA() const;
|
||||||
|
Body *getBodyB() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the anchor positions of the Joint in world
|
* Gets the anchor positions of the Joint in world
|
||||||
* coordinates. This is useful for debugdrawing the joint.
|
* coordinates. This is useful for debugdrawing the joint.
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getMaxTorque", w_FrictionJoint_getMaxTorque },
|
{ "getMaxTorque", w_FrictionJoint_getMaxTorque },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getRatio", w_GearJoint_getRatio },
|
{ "getRatio", w_GearJoint_getRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
// LOVE
|
// LOVE
|
||||||
#include "wrap_Joint.h"
|
#include "wrap_Joint.h"
|
||||||
#include "common/StringMap.h"
|
#include "common/StringMap.h"
|
||||||
|
#include "Body.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,22 @@ int w_Joint_getType(lua_State *L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_Joint_getBodies(lua_State *L)
|
||||||
|
{
|
||||||
|
Joint *t = luax_checkjoint(L, 1);
|
||||||
|
Body *b1 = nullptr;
|
||||||
|
Body *b2 = nullptr;
|
||||||
|
|
||||||
|
luax_catchexcept(L, [&]() {
|
||||||
|
b1 = t->getBodyA();
|
||||||
|
b2 = t->getBodyB();
|
||||||
|
});
|
||||||
|
|
||||||
|
luax_pushtype(L, "Body", PHYSICS_BODY_T, b1);
|
||||||
|
luax_pushtype(L, "Body", PHYSICS_BODY_T, b2);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
int w_Joint_getAnchors(lua_State *L)
|
int w_Joint_getAnchors(lua_State *L)
|
||||||
{
|
{
|
||||||
Joint *t = luax_checkjoint(L, 1);
|
Joint *t = luax_checkjoint(L, 1);
|
||||||
@@ -99,6 +116,7 @@ int w_Joint_destroy(lua_State *L)
|
|||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace box2d
|
|||||||
|
|
||||||
Joint *luax_checkjoint(lua_State *L, int idx);
|
Joint *luax_checkjoint(lua_State *L, int idx);
|
||||||
int w_Joint_getType(lua_State *L);
|
int w_Joint_getType(lua_State *L);
|
||||||
|
int w_Joint_getBodies(lua_State *L);
|
||||||
int w_Joint_getAnchors(lua_State *L);
|
int w_Joint_getAnchors(lua_State *L);
|
||||||
int w_Joint_getReactionForce(lua_State *L);
|
int w_Joint_getReactionForce(lua_State *L);
|
||||||
int w_Joint_getReactionTorque(lua_State *L);
|
int w_Joint_getReactionTorque(lua_State *L);
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getCorrectionFactor", w_MotorJoint_getCorrectionFactor },
|
{ "getCorrectionFactor", w_MotorJoint_getCorrectionFactor },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getRatio", w_PulleyJoint_getRatio },
|
{ "getRatio", w_PulleyJoint_getRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getLimits", w_RevoluteJoint_getLimits },
|
{ "getLimits", w_RevoluteJoint_getLimits },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getMaxLength", w_RopeJoint_getMaxLength },
|
{ "getMaxLength", w_RopeJoint_getMaxLength },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getDampingRatio", w_WeldJoint_getDampingRatio },
|
{ "getDampingRatio", w_WeldJoint_getDampingRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||||
// From Joint.
|
// From Joint.
|
||||||
{ "getType", w_Joint_getType },
|
{ "getType", w_Joint_getType },
|
||||||
|
{ "getBodies", w_Joint_getBodies },
|
||||||
{ "getAnchors", w_Joint_getAnchors },
|
{ "getAnchors", w_Joint_getAnchors },
|
||||||
{ "getReactionForce", w_Joint_getReactionForce },
|
{ "getReactionForce", w_Joint_getReactionForce },
|
||||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||||
|
|||||||
Reference in New Issue
Block a user