mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Merge default into minor
--HG-- branch : minor
This commit is contained in:
@@ -84,8 +84,8 @@ public:
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
Body *getBodyA() const;
|
||||
Body *getBodyB() const;
|
||||
virtual Body *getBodyA() const;
|
||||
virtual Body *getBodyB() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
|
||||
@@ -91,6 +91,16 @@ float MouseJoint::getDampingRatio() const
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
Body *MouseJoint::getBodyA() const
|
||||
{
|
||||
return Joint::getBodyB();
|
||||
}
|
||||
|
||||
Body *MouseJoint::getBodyB() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -95,6 +95,9 @@ public:
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
virtual Body *getBodyA() const;
|
||||
virtual Body *getBodyB() const;
|
||||
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint *joint;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -138,6 +138,12 @@ int PrismaticJoint::getLimits(lua_State *L)
|
||||
return 2;
|
||||
}
|
||||
|
||||
int PrismaticJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -134,6 +134,13 @@ public:
|
||||
**/
|
||||
int getLimits(lua_State *L);
|
||||
|
||||
/**
|
||||
* Gets the axis unit vector, relative to body1.
|
||||
* @returns The X component of the axis unit vector.
|
||||
* @returns The Y component of the axis unit vector.
|
||||
**/
|
||||
int getAxis(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -113,6 +113,12 @@ float WheelJoint::getSpringDampingRatio() const
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
int WheelJoint::getAxis(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().x);
|
||||
lua_pushnumber(L, joint->GetLocalAxisA().y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -114,6 +114,13 @@ public:
|
||||
**/
|
||||
float getSpringDampingRatio() const;
|
||||
|
||||
/**
|
||||
* Gets the axis unit vector, relative to body1.
|
||||
* @returns The X component of the axis unit vector.
|
||||
* @returns The Y component of the axis unit vector.
|
||||
**/
|
||||
int getAxis(lua_State *L);
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -164,6 +164,13 @@ int w_PrismaticJoint_getLimits(lua_State *L)
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getAxis(lua_State *L)
|
||||
{
|
||||
PrismaticJoint *t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAxis(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg w_PrismaticJoint_functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
|
||||
@@ -183,6 +190,7 @@ static const luaL_Reg w_PrismaticJoint_functions[] =
|
||||
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
|
||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||
{ "getAxis", w_PrismaticJoint_getAxis },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
@@ -132,6 +132,13 @@ int w_WheelJoint_getSpringDampingRatio(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getAxis(lua_State *L)
|
||||
{
|
||||
WheelJoint *t = luax_checkwheeljoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAxis(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg w_WheelJoint_functions[] =
|
||||
{
|
||||
{ "getJointTranslation", w_WheelJoint_getJointTranslation },
|
||||
@@ -147,6 +154,7 @@ static const luaL_Reg w_WheelJoint_functions[] =
|
||||
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
|
||||
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
|
||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||
{ "getAxis", w_WheelJoint_getAxis },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user