Commits

thelinx committed 63e9f8e

Add a custom Body:setMass function.

Comments (0)

Files changed (4)

src/modules/physics/box2d/Body.cpp

 		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;

src/modules/physics/box2d/Body.h

 		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).
 		* @param i The inertia.

src/modules/physics/box2d/wrap_Body.cpp

 		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);
 		{ "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 },

src/modules/physics/box2d/wrap_Body.h

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