mirror of
https://github.com/love2d/love.git
synced 2026-08-18 19:54:22 +02:00
love.physics: simplify Body and Shape API.
#1130 - Shapes are now directly attached to Bodies when they're created (similar to love 0.7 and older). - Fixtures are removed. - All methods that were in Fixtures now exist in Shapes. - All APIs that used or returned a Fixture now do the same with a Shape. - Add new love.physics.new*Shape variants that take a Body as the first parameter. - Deprecate the new*Shape APIs that don't take a Body. - Deprecate love.physics.newFixture (the deprecated function now returns a Shape). - Replace Body:getFixture and Body:getFixtures with Body:getShape and Body:getShapes (Body:getFixtures is deprecated). - Replace World:queryFixturesInArea and World:getFixturesInArea with World:queryShapesInArea and World:getShapesInArea (queryFixturesInArea is deprecated). - Replace Contact:getFixtures with Contact:getShapes (Contact:getFixtures is deprecated). - Replace all love.physics callback Fixture parameters with Shape parameters. - Deprecate ChainShape:getChildEdge.
This commit is contained in:
@@ -34,8 +34,8 @@ namespace box2d
|
||||
|
||||
love::Type ChainShape::type("ChainShape", &Shape::type);
|
||||
|
||||
ChainShape::ChainShape(b2ChainShape *c, bool own)
|
||||
: Shape(c, own)
|
||||
ChainShape::ChainShape(Body *body, const b2ChainShape &c)
|
||||
: Shape(body, c)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ ChainShape::~ChainShape()
|
||||
|
||||
void ChainShape::setNextVertex(float x, float y)
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->m_nextVertex = Physics::scaleDown(v);
|
||||
@@ -52,6 +53,7 @@ void ChainShape::setNextVertex(float x, float y)
|
||||
|
||||
void ChainShape::setPreviousVertex(float x, float y)
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2Vec2 v(x, y);
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
c->m_prevVertex = Physics::scaleDown(v);
|
||||
@@ -59,44 +61,40 @@ void ChainShape::setPreviousVertex(float x, float y)
|
||||
|
||||
b2Vec2 ChainShape::getNextVertex() const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
|
||||
return Physics::scaleUp(c->m_nextVertex);
|
||||
}
|
||||
|
||||
b2Vec2 ChainShape::getPreviousVertex() const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
|
||||
return Physics::scaleUp(c->m_prevVertex);
|
||||
}
|
||||
|
||||
EdgeShape *ChainShape::getChildEdge(int index) const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
b2EdgeShape *e = new b2EdgeShape;
|
||||
|
||||
try
|
||||
{
|
||||
c->GetChildEdge(e, index);
|
||||
}
|
||||
catch (love::Exception &)
|
||||
{
|
||||
delete e;
|
||||
throw;
|
||||
}
|
||||
b2EdgeShape e;
|
||||
c->GetChildEdge(&e, index);
|
||||
|
||||
return new EdgeShape(e, true);
|
||||
return new EdgeShape(nullptr, e);
|
||||
}
|
||||
|
||||
int ChainShape::getVertexCount() const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_count;
|
||||
}
|
||||
|
||||
b2Vec2 ChainShape::getPoint(int index) const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
if (index < 0 || index >= c->m_count)
|
||||
throw love::Exception("Physics error: index out of bounds");
|
||||
@@ -106,6 +104,7 @@ b2Vec2 ChainShape::getPoint(int index) const
|
||||
|
||||
const b2Vec2 *ChainShape::getPoints() const
|
||||
{
|
||||
throwIfShapeNotValid();
|
||||
b2ChainShape *c = (b2ChainShape *)shape;
|
||||
return c->m_vertices;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user