mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Fix love.physics.getDistance
This commit is contained in:
@@ -249,19 +249,26 @@ int Physics::getDistance(lua_State *L)
|
||||
{
|
||||
Fixture *fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
|
||||
Fixture *fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
|
||||
b2DistanceProxy pA, pB;
|
||||
b2DistanceInput i;
|
||||
b2DistanceProxy pA;
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
b2DistanceProxy pB;
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2DistanceOutput o;
|
||||
b2SimplexCache c;
|
||||
b2Distance(&o, &c, &i);
|
||||
c.count = 0;
|
||||
try
|
||||
{
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2Distance(&o, &c, &i);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
luaL_error(L, "%s", e.what());
|
||||
}
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
|
||||
|
||||
Reference in New Issue
Block a user