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

--HG--
branch : box2d-update
This commit is contained in:
Bill Meltsner
2011-09-24 03:39:21 -04:00
parent 08f894a98e
commit a0c0fd8387
4 changed files with 34 additions and 0 deletions
+19
View File
@@ -281,6 +281,25 @@ namespace box2d
x_o = v.x;
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)
{
+6
View File
@@ -282,6 +282,12 @@ namespace box2d
* @returns The y-coordinate of the vector in world coordinates.
**/
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
+8
View File
@@ -360,6 +360,13 @@ namespace box2d
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)
{
@@ -557,6 +564,7 @@ namespace box2d
{ "setType", w_Body_setType },
{ "getWorldPoint", w_Body_getWorldPoint },
{ "getWorldVector", w_Body_getWorldVector },
{ "getWorldPoints", w_Body_getWorldPoints },
{ "getLocalPoint", w_Body_getLocalPoint },
{ "getLocalVector", w_Body_getLocalVector },
{ "getLinearVelocityFromWorldPoint", w_Body_getLinearVelocityFromWorldPoint },
+1
View File
@@ -67,6 +67,7 @@ namespace box2d
int w_Body_setType(lua_State * L);
int w_Body_getWorldPoint(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_getLocalVector(lua_State * L);
int w_Body_getLinearVelocityFromWorldPoint(lua_State * L);