Add a custom Body:setMass function.

This commit is contained in:
Linus Sjögren
2012-01-10 04:14:17 +01:00
parent be55579a22
commit afd0ef1d9e
4 changed files with 24 additions and 0 deletions
+8
View File
@@ -253,6 +253,14 @@ namespace box2d
body->SetMassData(&massData);
}
int Body::setMass(float m)
{
b2MassData data;
body->GetMassData(&data);
data.mass = m;
body->SetMassData(&data);
}
void Body::setInertia(float i)
{
b2MassData massData;
+6
View File
@@ -242,6 +242,12 @@ namespace box2d
**/
void setMassData(float x, float y, float m, float i);
/**
* Sets just the mass. This is provided as a LOVE bonus. Lovely!
* @param m The mass.
**/
void setMass(float m);
/**
* Sets the inertia while keeping the other properties
* (mass and local center).
+9
View File
@@ -294,6 +294,14 @@ namespace box2d
return 0;
}
int w_Body_setMass(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
float m = (float)luaL_checknumber(L, 2);
t->setMass(m);
return 0;
}
int w_Body_setInertia(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
@@ -552,6 +560,7 @@ namespace box2d
{ "setPosition", w_Body_setPosition },
{ "resetMassData", w_Body_resetMassData },
{ "setMassData", w_Body_setMassData },
{ "setMass", w_Body_setMass },
{ "setInertia", w_Body_setInertia },
{ "setAngularDamping", w_Body_setAngularDamping },
{ "setLinearDamping", w_Body_setLinearDamping },
+1
View File
@@ -60,6 +60,7 @@ namespace box2d
int w_Body_setPosition(lua_State * L);
int w_Body_resetMassData(lua_State * L);
int w_Body_setMassData(lua_State * L);
int w_Body_setMass(lua_State * L);
int w_Body_setInertia(lua_State * L);
int w_Body_setAngularDamping(lua_State * L);
int w_Body_setLinearDamping(lua_State * L);