Added 2-point version of love.physics.newRevoluteJoint (fixes #1175)

This commit is contained in:
airstruck
2016-07-07 21:18:35 +02:00
parent 24da8433d0
commit 9a2f99dc3d
6 changed files with 29 additions and 12 deletions
+1
View File
@@ -7,6 +7,7 @@ Released: N/A
* Added 'shaderswitches' field to the table returned by love.graphics.getStats. * Added 'shaderswitches' field to the table returned by love.graphics.getStats.
* Added Quad:getTextureDimensions. * Added Quad:getTextureDimensions.
* Added PrismaticJoint:getAxis and WheelJoint:getAxis. * Added PrismaticJoint:getAxis and WheelJoint:getAxis.
* Added 2-point version of love.physics.newRevoluteJoint.
* Fixed love on iOS 6. * Fixed love on iOS 6.
* Fixed os.execute always returning -1 on Linux. * Fixed os.execute always returning -1 on Linux.
+2 -2
View File
@@ -223,9 +223,9 @@ MouseJoint *Physics::newMouseJoint(Body *body, float x, float y)
return new MouseJoint(body, x, 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) PrismaticJoint *Physics::newPrismaticJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
+5 -3
View File
@@ -171,11 +171,13 @@ public:
/** /**
* Creates a new RevoluteJoint connecting body1 with body2. * Creates a new RevoluteJoint connecting body1 with body2.
* @param x Anchor along the x-axis. (World coordinates) * @param xA Anchor for body 1 along the x-axis. (World coordinates)
* @param y Anchor along the y-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. * @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. * Creates a new PrismaticJoint connecting body1 with body2.
+3 -2
View File
@@ -34,12 +34,13 @@ namespace physics
namespace box2d 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(body1, body2)
, joint(NULL) , joint(NULL)
{ {
b2RevoluteJointDef def; 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; def.collideConnected = collideConnected;
joint = (b2RevoluteJoint *)createJoint(&def); joint = (b2RevoluteJoint *)createJoint(&def);
} }
+1 -1
View File
@@ -42,7 +42,7 @@ public:
/** /**
* Creates a new RevoluteJoint connecting body1 and body2. * 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(); virtual ~RevoluteJoint();
+17 -4
View File
@@ -215,12 +215,25 @@ int w_newRevoluteJoint(lua_State *L)
{ {
Body *body1 = luax_checkbody(L, 1); Body *body1 = luax_checkbody(L, 1);
Body *body2 = luax_checkbody(L, 2); Body *body2 = luax_checkbody(L, 2);
float x = (float)luaL_checknumber(L, 3); float xA = (float)luaL_checknumber(L, 3);
float y = (float)luaL_checknumber(L, 4); float yA = (float)luaL_checknumber(L, 4);
bool collideConnected = luax_optboolean(L, 5, false); 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; RevoluteJoint *j;
luax_catchexcept(L, [&]() { 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); luax_pushtype(L, PHYSICS_REVOLUTE_JOINT_ID, j);
j->release(); j->release();