Merge pull request #1613 from thegrb93/box2d-update

Box2d update to 2.4.1
This commit is contained in:
Alex Szpakowski
2020-11-02 21:27:57 -04:00
committed by GitHub
185 changed files with 11192 additions and 9207 deletions
+6 -6
View File
@@ -45,7 +45,7 @@ Body::Body(World *world, b2Vec2 p, Body::Type type)
udata->ref = nullptr;
b2BodyDef def;
def.position = Physics::scaleDown(p);
def.userData = (void *) udata;
def.userData.pointer = (uintptr_t)udata;
body = world->world->CreateBody(&def);
// Box2D body holds a reference to the love Body.
this->retain();
@@ -385,9 +385,9 @@ void Body::setBullet(bool bullet)
return body->SetBullet(bullet);
}
bool Body::isActive() const
bool Body::isEnabled() const
{
return body->IsActive();
return body->IsEnabled();
}
bool Body::isAwake() const
@@ -405,9 +405,9 @@ bool Body::isSleepingAllowed() const
return body->IsSleepingAllowed();
}
void Body::setActive(bool active)
void Body::setEnabled(bool enabled)
{
body->SetActive(active);
body->SetEnabled(enabled);
}
void Body::setAwake(bool awake)
@@ -544,7 +544,7 @@ int Body::setUserData(lua_State *L)
if (udata == nullptr)
{
udata = new bodyudata();
body->SetUserData((void *) udata);
body->GetUserData().pointer = (uintptr_t)udata;
}
if(!udata->ref)
+3 -3
View File
@@ -28,7 +28,7 @@
#include "physics/Body.h"
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
@@ -360,7 +360,7 @@ public:
* Checks whether a Body is active or not. An inactive body
* cannot be interacted with.
**/
bool isActive() const;
bool isEnabled() const;
/**
* Checks whether a Body is awake or not. A Body
@@ -377,7 +377,7 @@ public:
/**
* Changes the body's active state.
**/
void setActive(bool active);
void setEnabled(bool enabled);
/**
* Changes the body's sleep state.
+6 -34
View File
@@ -47,56 +47,28 @@ void ChainShape::setNextVertex(float x, float y)
{
b2Vec2 v(x, y);
b2ChainShape *c = (b2ChainShape *)shape;
c->SetNextVertex(Physics::scaleDown(v));
}
void ChainShape::setNextVertex()
{
b2ChainShape *c = (b2ChainShape *)shape;
c->m_hasNextVertex = false;
c->m_nextVertex = Physics::scaleDown(v);
}
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
b2Vec2 ChainShape::getNextVertex() 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;
return Physics::scaleUp(c->m_nextVertex);
}
bool ChainShape::getPreviousVertex(float &x, float &y) const
b2Vec2 ChainShape::getPreviousVertex() 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;
return Physics::scaleUp(c->m_prevVertex);
}
EdgeShape *ChainShape::getChildEdge(int index) const
+2 -4
View File
@@ -56,7 +56,6 @@ public:
* @param y The y-coordinate of the vertex.
**/
void setNextVertex(float x, float y);
void setNextVertex();
/**
* Establish connectivity to a vertex that precedes
@@ -65,17 +64,16 @@ public:
* @param y The y-coordinate of the vertex.
**/
void setPreviousVertex(float x, float y);
void setPreviousVertex();
/**
* Gets the vertex that follows the last vertex.
**/
bool getNextVertex(float &x, float &y) const;
b2Vec2 getNextVertex() const;
/**
* Gets the vertex that precedes the first vertex.
**/
bool getPreviousVertex(float &x, float &y) const;
b2Vec2 getPreviousVertex() const;
/**
* Returns a child EdgeShape.
+1 -1
View File
@@ -27,7 +27,7 @@
#include "World.h"
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
+33 -5
View File
@@ -58,22 +58,50 @@ float DistanceJoint::getLength() const
void DistanceJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
joint->SetStiffness(stiffness);
}
float DistanceJoint::getFrequency() const
{
return joint->GetFrequency();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return frequency;
}
void DistanceJoint::setDampingRatio(float d)
void DistanceJoint::setDampingRatio(float ratio)
{
joint->SetDampingRatio(d);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
joint->SetDamping(damping);
}
float DistanceJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return ratio;
}
void DistanceJoint::setStiffness(float k)
{
joint->SetStiffness(k);
}
float DistanceJoint::getStiffness() const
{
return joint->GetStiffness();
}
void DistanceJoint::setDamping(float d)
{
joint->SetDamping(d);
}
float DistanceJoint::getDamping() const
{
return joint->GetDamping();
}
+25 -7
View File
@@ -57,27 +57,45 @@ public:
float getLength() const;
/**
* Sets the response speed.
* Sets the response speed. Independent of mass
**/
void setFrequency(float hz);
/**
* Gets the response speed.
* Gets the response speed. Independent of mass
**/
float getFrequency() const;
/**
* Sets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Set the spring damping ratio. Independent of mass
**/
void setDampingRatio(float d);
void setDampingRatio(float ratio);
/**
* Gets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Get the spring damping ratio. Independent of mass
**/
float getDampingRatio() const;
/**
* Sets the response speed. Dependent of mass
**/
void setStiffness(float k);
/**
* Gets the response speed. Dependent of mass
**/
float getStiffness() const;
/**
* Set the spring damping. Dependent of mass
**/
void setDamping(float ratio);
/**
* Get the spring damping. Dependent of mass
**/
float getDamping() const;
private:
// The Box2D DistanceJoint object.
b2DistanceJoint *joint;
+4 -34
View File
@@ -48,28 +48,13 @@ 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
b2Vec2 EdgeShape::getNextVertex() 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;
return Physics::scaleUp(e->m_vertex3);
}
void EdgeShape::setPreviousVertex(float x, float y)
@@ -77,28 +62,13 @@ 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
b2Vec2 EdgeShape::getPreviousVertex() 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;
return Physics::scaleUp(e->m_vertex0);
}
int EdgeShape::getPoints(lua_State *L)
+2 -4
View File
@@ -50,12 +50,10 @@ public:
virtual ~EdgeShape();
void setNextVertex(float x, float y);
void setNextVertex();
bool getNextVertex(float &x, float &y) const;
b2Vec2 getNextVertex() const;
void setPreviousVertex(float x, float y);
void setPreviousVertex();
bool getPreviousVertex(float &x, float &y) const;
b2Vec2 getPreviousVertex() const;
/**
* Returns the transformed points of the edge shape.
+2 -2
View File
@@ -45,7 +45,7 @@ Fixture::Fixture(Body *body, Shape *shape, float density)
udata->ref = nullptr;
b2FixtureDef def;
def.shape = shape->shape;
def.userData = (void *)udata;
def.userData.pointer = (uintptr_t)udata;
def.density = density;
fixture = body->body->CreateFixture(&def);
this->retain();
@@ -262,7 +262,7 @@ int Fixture::setUserData(lua_State *L)
if (udata == nullptr)
{
udata = new fixtureudata();
fixture->SetUserData((void *) udata);
fixture->GetUserData().pointer = (uintptr_t)udata;
}
if(!udata->ref)
+1 -1
View File
@@ -29,7 +29,7 @@
#include "common/Reference.h"
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
+4 -4
View File
@@ -154,7 +154,7 @@ float Joint::getReactionTorque(float dt)
b2Joint *Joint::createJoint(b2JointDef *def)
{
def->userData = udata;
def->userData.pointer = (uintptr_t)udata;
joint = world->world->CreateJoint(def);
world->registerObject(joint, this);
// Box2D joint has a reference to this love Joint.
@@ -185,9 +185,9 @@ void Joint::destroyJoint(bool implicit)
this->release();
}
bool Joint::isActive() const
bool Joint::isEnabled() const
{
return joint->IsActive();
return joint->IsEnabled();
}
bool Joint::getCollideConnected() const
@@ -202,7 +202,7 @@ int Joint::setUserData(lua_State *L)
if (udata == nullptr)
{
udata = new jointudata();
joint->SetUserData((void *) udata);
joint->GetUserData().pointer = (uintptr_t)udata;
}
if(!udata->ref)
+2 -2
View File
@@ -26,7 +26,7 @@
#include "physics/Joint.h"
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
@@ -103,7 +103,7 @@ public:
**/
float getReactionTorque(float dt);
bool isActive() const;
bool isEnabled() const;
bool getCollideConnected() const;
+41 -7
View File
@@ -80,28 +80,62 @@ float MouseJoint::getMaxForce() const
void MouseJoint::setFrequency(float hz)
{
// This is kind of a crappy check. The frequency is used in an internal
// This is kind of a crappy check. The Stiffness is used in an internal
// box2d calculation whose result must be > FLT_EPSILON, but other variables
// go into that calculation...
if (hz <= FLT_EPSILON * 2)
throw love::Exception("MouseJoint frequency must be a positive number.");
throw love::Exception("MouseJoint Stiffness must be a positive number.");
joint->SetFrequency(hz);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
joint->SetStiffness(stiffness);
}
float MouseJoint::getFrequency() const
{
return joint->GetFrequency();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return frequency;
}
void MouseJoint::setDampingRatio(float d)
void MouseJoint::setDampingRatio(float ratio)
{
joint->SetDampingRatio(d);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
joint->SetDamping(damping);
}
float MouseJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return ratio;
}
void MouseJoint::setStiffness(float k)
{
// This is kind of a crappy check. The Stiffness is used in an internal
// box2d calculation whose result must be > FLT_EPSILON, but other variables
// go into that calculation...
if (k <= FLT_EPSILON * 2)
throw love::Exception("MouseJoint Stiffness must be a positive number.");
joint->SetStiffness(k);
}
float MouseJoint::getStiffness() const
{
return joint->GetStiffness();
}
void MouseJoint::setDamping(float d)
{
joint->SetDamping(d);
}
float MouseJoint::getDamping() const
{
return joint->GetDamping();
}
Body *MouseJoint::getBodyA() const
+25 -7
View File
@@ -76,27 +76,45 @@ public:
float getMaxForce() const;
/**
* Sets the response speed.
* Sets the response speed. Independent of mass
**/
void setFrequency(float hz);
/**
* Gets the response speed.
* Gets the response speed. Independent of mass
**/
float getFrequency() const;
/**
* Sets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Set the spring damping ratio. Independent of mass
**/
void setDampingRatio(float d);
void setDampingRatio(float ratio);
/**
* Gets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Get the spring damping ratio. Independent of mass
**/
float getDampingRatio() const;
/**
* Sets the response speed. Dependent of mass
**/
void setStiffness(float k);
/**
* Gets the response speed. Dependent of mass
**/
float getStiffness() const;
/**
* Set the spring damping. Dependent of mass
**/
void setDamping(float ratio);
/**
* Get the spring damping. Dependent of mass
**/
float getDamping() const;
virtual Body *getBodyA() const;
virtual Body *getBodyB() const;
+73 -4
View File
@@ -83,10 +83,19 @@ PolygonShape *Physics::newRectangleShape(float x, float y, float w, float h, flo
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();
s->Set(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);
}
@@ -160,7 +169,7 @@ int Physics::newChainShape(lua_State *L)
if (istable)
argc = (int) luax_objlen(L, 2);
if (argc % 2 != 0)
if (argc == 0 || argc % 2 != 0)
return luaL_error(L, "Number of vertex components must be a multiple of two.");
int vcount = argc/2;
@@ -196,7 +205,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 &)
{
@@ -386,6 +395,66 @@ b2AABB Physics::scaleUp(const b2AABB &aabb)
return t;
}
void Physics::b2LinearFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB)
{
float massA = bodyA->GetMass();
float massB = bodyB->GetMass();
float mass;
if (massA > 0.0f && massB > 0.0f)
{
mass = massA * massB / (massA + massB);
}
else if (massA > 0.0f)
{
mass = massA;
}
else
{
mass = massB;
}
if (mass == 0.0f || stiffness <= 0.0f)
{
frequency = 0.0f;
ratio = 0.0f;
return;
};
float omega = b2Sqrt(stiffness / mass);
frequency = omega / (2.0f * b2_pi);
ratio = damping / (mass * 2.0f * omega);
}
void Physics::b2AngularFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB)
{
float IA = bodyA->GetInertia();
float IB = bodyB->GetInertia();
float I;
if (IA > 0.0f && IB > 0.0f)
{
I = IA * IB / (IA + IB);
}
else if (IA > 0.0f)
{
I = IA;
}
else
{
I = IB;
}
if (I == 0.0f || stiffness <= 0.0f)
{
frequency = 0.0f;
ratio = 0.0f;
return;
};
float omega = b2Sqrt(stiffness / I);
frequency = omega / (2.0f * b2_pi);
ratio = damping / (I * 2.0f * omega);
}
} // box2d
} // physics
} // love
+24 -2
View File
@@ -140,7 +140,7 @@ public:
* @param x2 The x 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.
@@ -354,7 +354,29 @@ public:
* @param aabb The unscaled input AABB.
* @return The scaled AABB.
**/
static b2AABB scaleUp(const b2AABB &aabb);
static b2AABB scaleUp(const b2AABB& aabb);
/**
* Calculates linear frequency and damping radio from stiffness and damping
* @param frequency The output frequency
* @param ratio The output damping ratio
* @param stiffness The joint stiffness
* @param damping The joint damping
* @param bodyA The bodyA of the joint
* @param bodyB The bodyB of the joint
**/
static void b2LinearFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB);
/**
* Calculates angular frequency and damping radio from stiffness and damping
* @param frequency The output frequency
* @param ratio The output damping ratio
* @param stiffness The joint stiffness
* @param damping The joint damping
* @param bodyA The bodyA of the joint
* @param bodyB The bodyB of the joint
**/
static void b2AngularFrequency(float& frequency, float& ratio, float stiffness, float damping, b2Body* bodyA, b2Body* bodyB);
private:
+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);
}
+1 -1
View File
@@ -26,7 +26,7 @@
#include "physics/box2d/Body.h"
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
+33 -5
View File
@@ -68,22 +68,50 @@ void WeldJoint::init(b2WeldJointDef &def, Body *body1, Body *body2, float xA, fl
void WeldJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
joint->SetStiffness(stiffness);
}
float WeldJoint::getFrequency() const
{
return joint->GetFrequency();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return frequency;
}
void WeldJoint::setDampingRatio(float d)
void WeldJoint::setDampingRatio(float ratio)
{
joint->SetDampingRatio(d);
float stiffness, damping;
b2LinearStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
joint->SetDamping(damping);
}
float WeldJoint::getDampingRatio() const
{
return joint->GetDampingRatio();
float frequency, ratio;
Physics::b2LinearFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return ratio;
}
void WeldJoint::setStiffness(float k)
{
joint->SetStiffness(k);
}
float WeldJoint::getStiffness() const
{
return joint->GetStiffness();
}
void WeldJoint::setDamping(float d)
{
joint->SetDamping(d);
}
float WeldJoint::getDamping() const
{
return joint->GetDamping();
}
float WeldJoint::getReferenceAngle() const
+25 -7
View File
@@ -50,27 +50,45 @@ public:
virtual ~WeldJoint();
/**
* Sets the response speed.
* Sets the response speed. Independent of mass
**/
void setFrequency(float hz);
/**
* Gets the response speed.
* Gets the response speed. Independent of mass
**/
float getFrequency() const;
/**
* Sets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Set the spring damping ratio. Independent of mass
**/
void setDampingRatio(float d);
void setDampingRatio(float ratio);
/**
* Gets the damping ratio.
* 0 = no damping, 1 = critical damping.
* Get the spring damping ratio. Independent of mass
**/
float getDampingRatio() const;
/**
* Sets the response speed. Dependent of mass
**/
void setStiffness(float k);
/**
* Gets the response speed. Dependent of mass
**/
float getStiffness() const;
/**
* Set the spring damping. Dependent of mass
**/
void setDamping(float ratio);
/**
* Get the spring damping. Dependent of mass
**/
float getDamping() const;
/**
* Gets the reference angle.
**/
+37 -9
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)
@@ -95,24 +95,52 @@ float WheelJoint::getMotorTorque(float inv_dt) const
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
}
void WheelJoint::setSpringFrequency(float hz)
void WheelJoint::setFrequency(float hz)
{
joint->SetSpringFrequencyHz(hz);
float stiffness, damping;
b2AngularStiffness(stiffness, damping, hz, getDampingRatio(), joint->GetBodyA(), joint->GetBodyB());
joint->SetStiffness(stiffness);
}
float WheelJoint::getSpringFrequency() const
float WheelJoint::getFrequency() const
{
return joint->GetSpringFrequencyHz();
float frequency, ratio;
Physics::b2AngularFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return frequency;
}
void WheelJoint::setSpringDampingRatio(float ratio)
void WheelJoint::setDampingRatio(float ratio)
{
joint->SetSpringDampingRatio(ratio);
float stiffness, damping;
b2AngularStiffness(stiffness, damping, getFrequency(), ratio, joint->GetBodyA(), joint->GetBodyB());
joint->SetDamping(damping);
}
float WheelJoint::getSpringDampingRatio() const
float WheelJoint::getDampingRatio() const
{
return joint->GetSpringDampingRatio();
float frequency, ratio;
Physics::b2AngularFrequency(frequency, ratio, joint->GetStiffness(), joint->GetDamping(), joint->GetBodyA(), joint->GetBodyB());
return ratio;
}
void WheelJoint::setStiffness(float k)
{
joint->SetStiffness(k);
}
float WheelJoint::getStiffness() const
{
return joint->GetStiffness();
}
void WheelJoint::setDamping(float ratio)
{
joint->SetDamping(ratio);
}
float WheelJoint::getDamping() const
{
return joint->GetDamping();
}
int WheelJoint::getAxis(lua_State *L)
+28 -9
View File
@@ -96,25 +96,44 @@ public:
float getMotorTorque(float inv_dt) const;
/**
* Set the spring frequency, in hertz. Setting the frequency to 0
* disables the spring.
* Sets the response speed. Independent of mass
**/
void setSpringFrequency(float hz);
void setFrequency(float hz);
/**
* Get the spring frequency, in hertz.
* Gets the response speed. Independent of mass
**/
float getSpringFrequency() const;
float getFrequency() const;
/**
* Set the spring damping ratio.
* Set the spring damping ratio. Independent of mass
**/
void setSpringDampingRatio(float ratio);
void setDampingRatio(float ratio);
/**
* Get the spring damping ratio.
* Get the spring damping ratio. Independent of mass
**/
float getSpringDampingRatio() const;
float getDampingRatio() const;
/**
* Sets the response speed. Dependent of mass
**/
void setStiffness(float k);
/**
* Gets the response speed. Dependent of mass
**/
float getStiffness() const;
/**
* Set the spring damping. Dependent of mass
**/
void setDamping(float ratio);
/**
* Get the spring damping. Dependent of mass
**/
float getDamping() const;
/**
* Gets the axis unit vector, relative to body1.
+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;
}
+2 -2
View File
@@ -31,7 +31,7 @@
#include <unordered_map>
// Box2D
#include <Box2D/Box2D.h>
#include <box2d/Box2D.h>
namespace love
{
@@ -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;
+2 -2
View File
@@ -518,7 +518,7 @@ int w_Body_setBullet(lua_State *L)
int w_Body_isActive(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
luax_pushboolean(L, t->isActive());
luax_pushboolean(L, t->isEnabled());
return 1;
}
@@ -548,7 +548,7 @@ int w_Body_setActive(lua_State *L)
{
Body *t = luax_checkbody(L, 1);
bool b = luax_checkboolean(L, 2);
luax_catchexcept(L, [&](){ t->setActive(b); });
luax_catchexcept(L, [&](){ t->setEnabled(b); });
return 0;
}
+14 -32
View File
@@ -37,28 +37,18 @@ ChainShape *luax_checkchainshape(lua_State *L, int idx)
int w_ChainShape_setNextVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
if (lua_isnoneornil(L, 2))
c->setNextVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
}
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setNextVertex(x, y); });
return 0;
}
int w_ChainShape_setPreviousVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
if (lua_isnoneornil(L, 2))
c->setPreviousVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
}
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
return 0;
}
@@ -95,27 +85,19 @@ int w_ChainShape_getPoint(lua_State *L)
int w_ChainShape_getNextVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
float x, y;
if (c->getNextVertex(x, y))
{
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;
b2Vec2 v = c->getNextVertex();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
int w_ChainShape_getPreviousVertex(lua_State *L)
{
ChainShape *c = luax_checkchainshape(L, 1);
float x, y;
if (c->getPreviousVertex(x, y))
{
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;
b2Vec2 v = c->getPreviousVertex();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
int w_ChainShape_getPoints(lua_State *L)
@@ -80,6 +80,36 @@ int w_DistanceJoint_getDampingRatio(lua_State *L)
return 1;
}
int w_DistanceJoint_setStiffness(lua_State *L)
{
DistanceJoint *t = luax_checkdistancejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setStiffness(arg1);
return 0;
}
int w_DistanceJoint_getStiffness(lua_State *L)
{
DistanceJoint *t = luax_checkdistancejoint(L, 1);
lua_pushnumber(L, t->getStiffness());
return 1;
}
int w_DistanceJoint_setDamping(lua_State *L)
{
DistanceJoint *t = luax_checkdistancejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setDamping(arg1);
return 0;
}
int w_DistanceJoint_getDamping(lua_State *L)
{
DistanceJoint *t = luax_checkdistancejoint(L, 1);
lua_pushnumber(L, t->getDamping());
return 1;
}
static const luaL_Reg w_DistanceJoint_functions[] =
{
{ "setLength", w_DistanceJoint_setLength },
@@ -88,6 +118,10 @@ static const luaL_Reg w_DistanceJoint_functions[] =
{ "getFrequency", w_DistanceJoint_getFrequency },
{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
{ "setStiffness", w_DistanceJoint_setStiffness },
{ "getStiffness", w_DistanceJoint_getStiffness },
{ "setDamping", w_DistanceJoint_setDamping },
{ "getDamping", w_DistanceJoint_getDamping },
{ 0, 0 }
};
+14 -32
View File
@@ -35,55 +35,37 @@ EdgeShape *luax_checkedgeshape(lua_State *L, int idx)
int w_EdgeShape_setNextVertex(lua_State *L)
{
EdgeShape *t = luax_checkedgeshape(L, 1);
if (lua_isnoneornil(L, 2))
t->setNextVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setNextVertex(x, y);
}
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setNextVertex(x, y);
return 0;
}
int w_EdgeShape_setPreviousVertex(lua_State *L)
{
EdgeShape *t = luax_checkedgeshape(L, 1);
if (lua_isnoneornil(L, 2))
t->setPreviousVertex();
else
{
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setPreviousVertex(x, y);
}
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
t->setPreviousVertex(x, y);
return 0;
}
int w_EdgeShape_getNextVertex(lua_State *L)
{
EdgeShape *t = luax_checkedgeshape(L, 1);
float x, y;
if (t->getNextVertex(x, y))
{
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;
b2Vec2 v = t->getNextVertex();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
int w_EdgeShape_getPreviousVertex(lua_State *L)
{
EdgeShape *t = luax_checkedgeshape(L, 1);
float x, y;
if (t->getPreviousVertex(x, y))
{
lua_pushnumber(L, x);
lua_pushnumber(L, y);
return 2;
}
return 0;
b2Vec2 v = t->getPreviousVertex();
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
return 2;
}
int w_EdgeShape_getPoints(lua_State *L)
@@ -96,6 +96,36 @@ int w_MouseJoint_getDampingRatio(lua_State *L)
return 1;
}
int w_MouseJoint_setStiffness(lua_State *L)
{
MouseJoint *t = luax_checkmousejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
luax_catchexcept(L, [&]() { t->setStiffness(arg1); });
return 0;
}
int w_MouseJoint_getStiffness(lua_State *L)
{
MouseJoint *t = luax_checkmousejoint(L, 1);
lua_pushnumber(L, t->getStiffness());
return 1;
}
int w_MouseJoint_setDamping(lua_State *L)
{
MouseJoint *t = luax_checkmousejoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setDamping(arg1);
return 0;
}
int w_MouseJoint_getDamping(lua_State *L)
{
MouseJoint *t = luax_checkmousejoint(L, 1);
lua_pushnumber(L, t->getDamping());
return 1;
}
static const luaL_Reg w_MouseJoint_functions[] =
{
{ "setTarget", w_MouseJoint_setTarget },
@@ -106,6 +136,10 @@ static const luaL_Reg w_MouseJoint_functions[] =
{ "getFrequency", w_MouseJoint_getFrequency },
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
{ "setStiffness", w_MouseJoint_setStiffness },
{ "getStiffness", w_MouseJoint_getStiffness },
{ "setDamping", w_MouseJoint_setDamping },
{ "getDamping", w_MouseJoint_getDamping },
{ 0, 0 }
};
+2 -1
View File
@@ -160,8 +160,9 @@ int w_newEdgeShape(lua_State *L)
float y1 = (float)luaL_checknumber(L, 2);
float x2 = (float)luaL_checknumber(L, 3);
float y2 = (float)luaL_checknumber(L, 4);
bool oneSided = luax_optboolean(L, 5, false);
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);
shape->release();
return 1;
@@ -65,6 +65,36 @@ int w_WeldJoint_getDampingRatio(lua_State *L)
return 1;
}
int w_WeldJoint_setStiffness(lua_State *L)
{
WeldJoint *t = luax_checkweldjoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setStiffness(arg1);
return 0;
}
int w_WeldJoint_getStiffness(lua_State *L)
{
WeldJoint *t = luax_checkweldjoint(L, 1);
lua_pushnumber(L, t->getStiffness());
return 1;
}
int w_WeldJoint_setDamping(lua_State *L)
{
WeldJoint *t = luax_checkweldjoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setDamping(arg1);
return 0;
}
int w_WeldJoint_getDamping(lua_State *L)
{
WeldJoint *t = luax_checkweldjoint(L, 1);
lua_pushnumber(L, t->getDamping());
return 1;
}
int w_WeldJoint_getReferenceAngle(lua_State *L)
{
WeldJoint *t = luax_checkweldjoint(L, 1);
@@ -78,6 +108,10 @@ static const luaL_Reg w_WeldJoint_functions[] =
{ "getFrequency", w_WeldJoint_getFrequency },
{ "setDampingRatio", w_WeldJoint_setDampingRatio },
{ "getDampingRatio", w_WeldJoint_getDampingRatio },
{ "setStiffness", w_WeldJoint_setStiffness },
{ "getStiffness", w_WeldJoint_getStiffness },
{ "setDamping", w_WeldJoint_setDamping },
{ "getDamping", w_WeldJoint_getDamping },
{ "getReferenceAngle", w_WeldJoint_getReferenceAngle },
{ 0, 0 }
};
+54 -12
View File
@@ -102,33 +102,63 @@ int w_WheelJoint_getMotorTorque(lua_State *L)
return 1;
}
int w_WheelJoint_setSpringFrequency(lua_State *L)
int w_WheelJoint_setFrequency(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setSpringFrequency(arg1);
t->setFrequency(arg1);
return 0;
}
int w_WheelJoint_getSpringFrequency(lua_State *L)
int w_WheelJoint_getFrequency(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getSpringFrequency());
lua_pushnumber(L, t->getFrequency());
return 1;
}
int w_WheelJoint_setSpringDampingRatio(lua_State *L)
int w_WheelJoint_setDampingRatio(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setSpringDampingRatio(arg1);
t->setDampingRatio(arg1);
return 0;
}
int w_WheelJoint_getSpringDampingRatio(lua_State *L)
int w_WheelJoint_getDampingRatio(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getSpringDampingRatio());
lua_pushnumber(L, t->getDampingRatio());
return 1;
}
int w_WheelJoint_setStiffness(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setStiffness(arg1);
return 0;
}
int w_WheelJoint_getStiffness(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getStiffness());
return 1;
}
int w_WheelJoint_setDamping(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
float arg1 = (float)luaL_checknumber(L, 2);
t->setDamping(arg1);
return 0;
}
int w_WheelJoint_getDamping(lua_State *L)
{
WheelJoint *t = luax_checkwheeljoint(L, 1);
lua_pushnumber(L, t->getDamping());
return 1;
}
@@ -150,10 +180,22 @@ static const luaL_Reg w_WheelJoint_functions[] =
{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
{ "getMotorTorque", w_WheelJoint_getMotorTorque },
{ "setSpringFrequency", w_WheelJoint_setSpringFrequency },
{ "getSpringFrequency", w_WheelJoint_getSpringFrequency },
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
{ "setSpringFrequency", w_WheelJoint_setFrequency },
{ "getSpringFrequency", w_WheelJoint_getFrequency },
{ "setSpringDampingRatio", w_WheelJoint_setDampingRatio },
{ "getSpringDampingRatio", w_WheelJoint_getDampingRatio },
{ "setSpringStiffness", w_WheelJoint_setStiffness },
{ "getSpringStiffness", w_WheelJoint_getStiffness },
{ "setSpringDamping", w_WheelJoint_setDamping },
{ "getSpringDamping", w_WheelJoint_getDamping },
{ "setFrequency", w_WheelJoint_setFrequency },
{ "getFrequency", w_WheelJoint_getFrequency },
{ "setDampingRatio", w_WheelJoint_setDampingRatio },
{ "getDampingRatio", w_WheelJoint_getDampingRatio },
{ "setStiffness", w_WheelJoint_setStiffness },
{ "getStiffness", w_WheelJoint_getStiffness },
{ "setDamping", w_WheelJoint_setDamping },
{ "getDamping", w_WheelJoint_getDamping },
{ "getAxis", w_WheelJoint_getAxis },
{ 0, 0 }
};