mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Add one sided edge support. Just not sure if the ghost vertices are fine.
This commit is contained in:
@@ -83,10 +83,19 @@ PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h, flo
|
|||||||
return new PolygonShape(s);
|
return new PolygonShape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeShape *Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
EdgeShape *Physics::newEdgeShape(float x1, float y1, float x2, float y2, bool oneSided)
|
||||||
{
|
{
|
||||||
b2EdgeShape *s = new b2EdgeShape();
|
b2EdgeShape *s = new b2EdgeShape();
|
||||||
s->SetTwoSided(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
if (oneSided)
|
||||||
|
{
|
||||||
|
b2Vec2 v1 = Physics::scaleDown(b2Vec2(x1, y1));
|
||||||
|
b2Vec2 v2 = Physics::scaleDown(b2Vec2(x2, y2));
|
||||||
|
s->SetOneSided(v1, v1, v2, v2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s->SetTwoSided(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
||||||
|
}
|
||||||
return new EdgeShape(s);
|
return new EdgeShape(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public:
|
|||||||
* @param x2 The x coordinate of the second point.
|
* @param x2 The x coordinate of the second point.
|
||||||
* @param y2 The y coordinate of the second point.
|
* @param y2 The y coordinate of the second point.
|
||||||
**/
|
**/
|
||||||
EdgeShape *newEdgeShape(float x1, float y1, float x2, float y2);
|
EdgeShape *newEdgeShape(float x1, float y1, float x2, float y2, bool oneSided);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new PolygonShape from a variable number of vertices.
|
* Creates a new PolygonShape from a variable number of vertices.
|
||||||
|
|||||||
@@ -160,8 +160,9 @@ int w_newEdgeShape(lua_State *L)
|
|||||||
float y1 = (float)luaL_checknumber(L, 2);
|
float y1 = (float)luaL_checknumber(L, 2);
|
||||||
float x2 = (float)luaL_checknumber(L, 3);
|
float x2 = (float)luaL_checknumber(L, 3);
|
||||||
float y2 = (float)luaL_checknumber(L, 4);
|
float y2 = (float)luaL_checknumber(L, 4);
|
||||||
|
bool oneSided = luax_optboolean(L, 5, false);
|
||||||
EdgeShape *shape;
|
EdgeShape *shape;
|
||||||
luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2); });
|
luax_catchexcept(L, [&](){ shape = instance()->newEdgeShape(x1, y1, x2, y2, oneSided); });
|
||||||
luax_pushtype(L, shape);
|
luax_pushtype(L, shape);
|
||||||
shape->release();
|
shape->release();
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user