mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Add a custom Body:setMass function.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user