Starting box2d update

This commit is contained in:
Garrett Brown
2020-08-16 06:34:37 -04:00
parent 365387150e
commit 74c6021e8d
153 changed files with 9634 additions and 8518 deletions
+2 -2
View File
@@ -372,7 +372,7 @@ void Body::setBullet(bool bullet)
bool Body::isActive() const
{
return body->IsActive();
return body->IsEnabled();
}
bool Body::isAwake() const
@@ -392,7 +392,7 @@ bool Body::isSleepingAllowed() const
void Body::setActive(bool active)
{
body->SetActive(active);
body->SetEnabled(active);
}
void Body::setAwake(bool awake)
+10 -22
View File
@@ -47,56 +47,44 @@ void ChainShape::setNextVertex(float x, float y)
{
b2Vec2 v(x, y);
b2ChainShape *c = (b2ChainShape *)shape;
c->SetNextVertex(Physics::scaleDown(v));
c->m_nextVertex = Physics::scaleDown(v);
}
void ChainShape::setNextVertex()
{
b2ChainShape *c = (b2ChainShape *)shape;
c->m_hasNextVertex = false;
}
void ChainShape::setPreviousVertex(float x, float y)
{
b2Vec2 v(x, y);
b2ChainShape *c = (b2ChainShape *)shape;
c->SetPrevVertex(Physics::scaleDown(v));
c->m_prevVertex = Physics::scaleDown(v);
}
void ChainShape::setPreviousVertex()
{
b2ChainShape *c = (b2ChainShape *)shape;
c->m_hasPrevVertex = false;
}
bool ChainShape::getNextVertex(float &x, float &y) const
{
b2ChainShape *c = (b2ChainShape *)shape;
if (c->m_hasNextVertex)
{
b2Vec2 v = Physics::scaleUp(c->m_nextVertex);
x = v.x;
y = v.y;
return true;
}
return false;
b2Vec2 v = Physics::scaleUp(c->m_nextVertex);
x = v.x;
y = v.y;
return true;
}
bool ChainShape::getPreviousVertex(float &x, float &y) const
{
b2ChainShape *c = (b2ChainShape *)shape;
if (c->m_hasPrevVertex)
{
b2Vec2 v = Physics::scaleUp(c->m_prevVertex);
x = v.x;
y = v.y;
return true;
}
return false;
b2Vec2 v = Physics::scaleUp(c->m_prevVertex);
x = v.x;
y = v.y;
return true;
}
EdgeShape *ChainShape::getChildEdge(int index) const
+4 -4
View File
@@ -58,22 +58,22 @@ float DistanceJoint::getLength() const
void DistanceJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
joint->SetStiffness(hz);
}
float DistanceJoint::getFrequency() const
{
return joint->GetFrequency();
return joint->GetStiffness();
}
void DistanceJoint::setDampingRatio(float d)
{
joint->SetDampingRatio(d);
joint->SetDamping(d);
}
float DistanceJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
return joint->GetDamping();
}
+8 -22
View File
@@ -48,28 +48,21 @@ void EdgeShape::setNextVertex(float x, float y)
b2EdgeShape *e = (b2EdgeShape *)shape;
b2Vec2 v(x, y);
e->m_vertex3 = Physics::scaleDown(v);
e->m_hasVertex3 = true;
}
void EdgeShape::setNextVertex()
{
b2EdgeShape *e = (b2EdgeShape *)shape;
e->m_hasVertex3 = false;
}
bool EdgeShape::getNextVertex(float &x, float &y) const
{
b2EdgeShape *e = (b2EdgeShape *)shape;
if (e->m_hasVertex3)
{
b2Vec2 v = Physics::scaleUp(e->m_vertex3);
x = v.x;
y = v.y;
return true;
}
return false;
b2Vec2 v = Physics::scaleUp(e->m_vertex3);
x = v.x;
y = v.y;
return true;
}
void EdgeShape::setPreviousVertex(float x, float y)
@@ -77,28 +70,21 @@ void EdgeShape::setPreviousVertex(float x, float y)
b2EdgeShape *e = (b2EdgeShape *)shape;
b2Vec2 v(x, y);
e->m_vertex0 = Physics::scaleDown(v);
e->m_hasVertex0 = true;
}
void EdgeShape::setPreviousVertex()
{
b2EdgeShape *e = (b2EdgeShape *)shape;
e->m_hasVertex0 = false;
}
bool EdgeShape::getPreviousVertex(float &x, float &y) const
{
b2EdgeShape *e = (b2EdgeShape *)shape;
if (e->m_hasVertex0)
{
b2Vec2 v = Physics::scaleUp(e->m_vertex0);
x = v.x;
y = v.y;
return true;
}
return false;
b2Vec2 v = Physics::scaleUp(e->m_vertex0);
x = v.x;
y = v.y;
return true;
}
int EdgeShape::getPoints(lua_State *L)
+1 -1
View File
@@ -187,7 +187,7 @@ void Joint::destroyJoint(bool implicit)
bool Joint::isActive() const
{
return joint->IsActive();
return joint->IsEnabled();
}
bool Joint::getCollideConnected() const
+4 -4
View File
@@ -86,22 +86,22 @@ void MouseJoint::setFrequency(float hz)
if (hz <= FLT_EPSILON * 2)
throw love::Exception("MouseJoint frequency must be a positive number.");
joint->SetFrequency(hz);
joint->SetStiffness(hz);
}
float MouseJoint::getFrequency() const
{
return joint->GetFrequency();
return joint->GetStiffness();
}
void MouseJoint::setDampingRatio(float d)
{
joint->SetDampingRatio(d);
joint->SetDamping(d);
}
float MouseJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
return joint->GetDamping();
}
Body *MouseJoint::getBodyA() const
+3 -25
View File
@@ -86,7 +86,7 @@ PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h, flo
EdgeShape *Physics::newEdgeShape(float x1, float y1, float x2, float y2)
{
b2EdgeShape *s = new b2EdgeShape();
s->Set(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
s->SetTwoSided(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
return new EdgeShape(s);
}
@@ -196,7 +196,7 @@ int Physics::newChainShape(lua_State *L)
if (loop)
s->CreateLoop(vecs, vcount);
else
s->CreateChain(vecs, vcount);
s->CreateChain(vecs, vcount, vecs[0], vecs[vcount-1]);
}
catch (love::Exception &)
{
@@ -298,29 +298,7 @@ int Physics::getDistance(lua_State *L)
{
Fixture *fixtureA = luax_checktype<Fixture>(L, 1);
Fixture *fixtureB = luax_checktype<Fixture>(L, 2);
b2DistanceProxy pA, pB;
b2DistanceInput i;
b2DistanceOutput o;
b2SimplexCache c;
c.count = 0;
luax_catchexcept(L, [&]() {
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);
});
lua_pushnumber(L, Physics::scaleUp(o.distance));
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
lua_pushnumber(L, Physics::scaleUp(o.pointB.x));
lua_pushnumber(L, Physics::scaleUp(o.pointB.y));
return 5;
return 0;
}
void Physics::setMeter(float scale)
+2 -2
View File
@@ -47,10 +47,10 @@ int PolygonShape::getPoints(lua_State *L)
{
love::luax_assert_argc(L, 0);
b2PolygonShape *p = (b2PolygonShape *)shape;
int count = p->GetVertexCount();
int count = p->m_count;
for (int i = 0; i<count; i++)
{
b2Vec2 v = Physics::scaleUp(p->GetVertex(i));
b2Vec2 v = Physics::scaleUp(p->m_vertices[i]);
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
}
+4 -4
View File
@@ -68,22 +68,22 @@ void WeldJoint::init(b2WeldJointDef &def, Body *body1, Body *body2, float xA, fl
void WeldJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
joint->SetStiffness(hz);
}
float WeldJoint::getFrequency() const
{
return joint->GetFrequency();
return joint->GetStiffness();
}
void WeldJoint::setDampingRatio(float d)
{
joint->SetDampingRatio(d);
joint->SetDamping(d);
}
float WeldJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
return joint->GetDamping();
}
float WeldJoint::getReferenceAngle() const
+5 -5
View File
@@ -57,7 +57,7 @@ float WheelJoint::getJointTranslation() const
float WheelJoint::getJointSpeed() const
{
return Physics::scaleUp(joint->GetJointSpeed());
return Physics::scaleUp(joint->GetJointLinearSpeed());
}
void WheelJoint::setMotorEnabled(bool enable)
@@ -97,22 +97,22 @@ float WheelJoint::getMotorTorque(float inv_dt) const
void WheelJoint::setSpringFrequency(float hz)
{
joint->SetSpringFrequencyHz(hz);
joint->SetStiffness(hz);
}
float WheelJoint::getSpringFrequency() const
{
return joint->GetSpringFrequencyHz();
return joint->GetStiffness();
}
void WheelJoint::setSpringDampingRatio(float ratio)
{
joint->SetSpringDampingRatio(ratio);
joint->SetDamping(ratio);
}
float WheelJoint::getSpringDampingRatio() const
{
return joint->GetSpringDampingRatio();
return joint->GetDamping();
}
int WheelJoint::getAxis(lua_State *L)
+2 -2
View File
@@ -183,7 +183,7 @@ World::RayCastCallback::~RayCastCallback()
{
}
float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction)
float World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float fraction)
{
if (L != nullptr)
{
@@ -201,7 +201,7 @@ float32 World::RayCastCallback::ReportFixture(b2Fixture *fixture, const b2Vec2 &
lua_call(L, 6, 1);
if (!lua_isnumber(L, -1))
luaL_error(L, "Raycast callback didn't return a number!");
float32 fraction = (float32) lua_tonumber(L, -1);
float fraction = (float) lua_tonumber(L, -1);
lua_pop(L, 1);
return fraction;
}
+1 -1
View File
@@ -107,7 +107,7 @@ public:
public:
RayCastCallback(World *world, lua_State *L, int idx);
~RayCastCallback();
virtual float32 ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float32 fraction);
virtual float ReportFixture(b2Fixture *fixture, const b2Vec2 &point, const b2Vec2 &normal, float fraction);
private:
World *world;
lua_State *L;