mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Added 2-point version of love.physics.newRevoluteJoint (fixes #1175)
This commit is contained in:
@@ -223,9 +223,9 @@ MouseJoint *Physics::newMouseJoint(Body *body, float x, float y)
|
||||
return new MouseJoint(body, x, y);
|
||||
}
|
||||
|
||||
RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
RevoluteJoint *Physics::newRevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new RevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
return new RevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
|
||||
@@ -171,11 +171,13 @@ public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
RevoluteJoint *newRevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 with body2.
|
||||
|
||||
@@ -34,12 +34,13 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected)
|
||||
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2)
|
||||
, joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)));
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RevoluteJoint *)createJoint(&def);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 and body2.
|
||||
**/
|
||||
RevoluteJoint(Body *body1, Body *body2, float x, float y, bool collideConnected);
|
||||
RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
virtual ~RevoluteJoint();
|
||||
|
||||
|
||||
@@ -215,12 +215,25 @@ int w_newRevoluteJoint(lua_State *L)
|
||||
{
|
||||
Body *body1 = luax_checkbody(L, 1);
|
||||
Body *body2 = luax_checkbody(L, 2);
|
||||
float x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
bool collideConnected = luax_optboolean(L, 5, false);
|
||||
float xA = (float)luaL_checknumber(L, 3);
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
}
|
||||
RevoluteJoint *j;
|
||||
luax_catchexcept(L, [&]() {
|
||||
j = instance()->newRevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
j = instance()->newRevoluteJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
});
|
||||
luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
|
||||
j->release();
|
||||
|
||||
Reference in New Issue
Block a user