mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
A first attempt at overhauling collision. New everything.
--HG-- branch : box2d-update
This commit is contained in:
@@ -28,54 +28,82 @@ namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Contact::Contact(World * world, b2Contact * contact)
|
||||
: contact(contact), world(world)
|
||||
Contact::Contact(b2Contact * contact)
|
||||
: contact(contact)
|
||||
{
|
||||
world->retain();
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
world->release();
|
||||
}
|
||||
|
||||
int Contact::getPosition(lua_State * L)
|
||||
int Contact::getPositions(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
lua_pushnumber(L, Physics::scaleUp(point.position.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(point.position.y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
int Contact::getVelocity(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
lua_pushnumber(L, Physics::scaleUp(point.velocity.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(point.velocity.y));
|
||||
return 2;
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
int points = contact->GetManifold()->pointCount;
|
||||
for (int i = 0; i < points; i++) {
|
||||
b2Vec2 position = Physics::scaleUp(manifold.points[i]);
|
||||
lua_pushnumber(L, position.x);
|
||||
lua_pushnumber(L, position.y);
|
||||
}
|
||||
return points*2;
|
||||
}
|
||||
|
||||
int Contact::getNormal(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
lua_pushnumber(L, Physics::scaleUp(point.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(point.normal.y));
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Contact::getSeparation() const
|
||||
{
|
||||
return Physics::scaleUp(point.separation);
|
||||
}
|
||||
|
||||
float Contact::getFriction() const
|
||||
{
|
||||
return point.friction;
|
||||
return contact->GetFriction();
|
||||
}
|
||||
|
||||
float Contact::getRestitution() const
|
||||
{
|
||||
return point.restitution;
|
||||
return contact->GetRestitution();
|
||||
}
|
||||
|
||||
bool Contact::isEnabled() const
|
||||
{
|
||||
return contact->IsEnabled();
|
||||
}
|
||||
|
||||
bool Contact::isTouching() const
|
||||
{
|
||||
return contact->IsTouching();
|
||||
}
|
||||
|
||||
void Contact::setFriction(float friction)
|
||||
{
|
||||
contact->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Contact::setRestitution(float restitution)
|
||||
{
|
||||
contact->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Contact::setEnabled(bool enabled)
|
||||
{
|
||||
contact->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
void Contact::resetFriction()
|
||||
{
|
||||
contact->ResetFriction();
|
||||
}
|
||||
|
||||
void Contact::resetRestitution()
|
||||
{
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
|
||||
Reference in New Issue
Block a user