Browse Source

Add Body:getWorldPoints, basically for use with PolygonShape:getPoints to facilitate easier drawing

--HG--
branch : box2d-update
Bill Meltsner 14 years ago
parent
commit
a0c0fd8387

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

@@ -281,6 +281,25 @@ namespace box2d
 		x_o = v.x;
 		x_o = v.x;
 		y_o = v.y;
 		y_o = v.y;
 	}
 	}
+	
+	int Body::getWorldPoints(lua_State * L)
+	{
+		int argc = lua_gettop(L);
+		int vcount = (int)argc/2;
+		// at least one point
+		love::luax_assert_argc(L, 2);
+		
+		for(int i = 0;i<vcount;i++)
+		{
+			float x = (float)lua_tonumber(L, i*2+1);
+			float y = (float)lua_tonumber(L, i*2+2);
+			b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
+			lua_pushnumber(L, point.x);
+			lua_pushnumber(L, point.y);
+		}
+		
+		return argc;
+	}
 
 
 	void Body::getLocalPoint(float x, float y, float & x_o, float & y_o)
 	void Body::getLocalPoint(float x, float y, float & x_o, float & y_o)
 	{
 	{

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

@@ -282,6 +282,12 @@ namespace box2d
 		* @returns The y-coordinate of the vector in world coordinates.
 		* @returns The y-coordinate of the vector in world coordinates.
 		**/
 		**/
 		void getWorldVector(float x, float y, float & x_o, float & y_o);
 		void getWorldVector(float x, float y, float & x_o, float & y_o);
+		
+		/**
+		* Transforms a series of points (x, y) from local coordinates
+		* to world coordinates.
+		**/
+		int getWorldPoints(lua_State * L);
 
 
 		/**
 		/**
 		* Transforms a point (x, y) from world coordinates
 		* Transforms a point (x, y) from world coordinates

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

@@ -360,6 +360,13 @@ namespace box2d
 
 
 		return 2;
 		return 2;
 	}
 	}
+	
+	int w_Body_getWorldPoints(lua_State * L)
+	{
+		Body * t = luax_checkbody(L, 1);
+		lua_remove(L, 1);
+		return t->getWorldPoints(L);
+	}
 
 
 	int w_Body_getLocalPoint(lua_State * L)
 	int w_Body_getLocalPoint(lua_State * L)
 	{
 	{
@@ -557,6 +564,7 @@ namespace box2d
 		{ "setType", w_Body_setType },
 		{ "setType", w_Body_setType },
 		{ "getWorldPoint", w_Body_getWorldPoint },
 		{ "getWorldPoint", w_Body_getWorldPoint },
 		{ "getWorldVector", w_Body_getWorldVector },
 		{ "getWorldVector", w_Body_getWorldVector },
+		{ "getWorldPoints", w_Body_getWorldPoints },
 		{ "getLocalPoint", w_Body_getLocalPoint },
 		{ "getLocalPoint", w_Body_getLocalPoint },
 		{ "getLocalVector", w_Body_getLocalVector },
 		{ "getLocalVector", w_Body_getLocalVector },
 		{ "getLinearVelocityFromWorldPoint", w_Body_getLinearVelocityFromWorldPoint },
 		{ "getLinearVelocityFromWorldPoint", w_Body_getLinearVelocityFromWorldPoint },

+ 1 - 0
src/modules/physics/box2d/wrap_Body.h

@@ -67,6 +67,7 @@ namespace box2d
 	int w_Body_setType(lua_State * L);
 	int w_Body_setType(lua_State * L);
 	int w_Body_getWorldPoint(lua_State * L);
 	int w_Body_getWorldPoint(lua_State * L);
 	int w_Body_getWorldVector(lua_State * L);
 	int w_Body_getWorldVector(lua_State * L);
+	int w_Body_getWorldPoints(lua_State * L);
 	int w_Body_getLocalPoint(lua_State * L);
 	int w_Body_getLocalPoint(lua_State * L);
 	int w_Body_getLocalVector(lua_State * L);
 	int w_Body_getLocalVector(lua_State * L);
 	int w_Body_getLinearVelocityFromWorldPoint(lua_State * L);
 	int w_Body_getLinearVelocityFromWorldPoint(lua_State * L);