mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Add Body:getWorldPoints, basically for use with PolygonShape:getPoints to facilitate easier drawing
--HG-- branch : box2d-update
This commit is contained in:
@@ -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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 },
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user