Browse Source

Merged in thelinx/love (Body:setMass)

Bart van Strien 13 years ago
parent
commit
2549d84ec8

+ 8 - 0
src/modules/physics/box2d/Body.cpp

@@ -253,6 +253,14 @@ namespace box2d
 		body->SetMassData(&massData);
 	}
 
+	void Body::setMass(float m)
+	{
+		b2MassData data;
+		body->GetMassData(&data);
+		data.mass = m;
+		body->SetMassData(&data);
+	}
+
 	void Body::setInertia(float i)
 	{
 		b2MassData massData;

+ 6 - 0
src/modules/physics/box2d/Body.h

@@ -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 - 0
src/modules/physics/box2d/wrap_Body.cpp

@@ -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 - 0
src/modules/physics/box2d/wrap_Body.h

@@ -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);