Support reference angle on revolute, prismatic, and weld joints (fixes #1194)

This commit is contained in:
airstruck
2016-08-19 14:36:36 +02:00
parent 78a2e80818
commit 154f7cbc7e
12 changed files with 154 additions and 14 deletions
+23 -3
View File
@@ -39,9 +39,17 @@ RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float
, joint(NULL)
{
b2RevoluteJointDef def;
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
def.collideConnected = collideConnected;
init(def, body1, body2, xA, yA, xB, yB, collideConnected);
joint = (b2RevoluteJoint *)createJoint(&def);
}
RevoluteJoint::RevoluteJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected, float referenceAngle)
: Joint(body1, body2)
, joint(NULL)
{
b2RevoluteJointDef def;
init(def, body1, body2, xA, yA, xB, yB, collideConnected);
def.referenceAngle = referenceAngle;
joint = (b2RevoluteJoint *)createJoint(&def);
}
@@ -49,6 +57,13 @@ RevoluteJoint::~RevoluteJoint()
{
}
void RevoluteJoint::init(b2RevoluteJointDef &def, Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected)
{
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
def.collideConnected = collideConnected;
}
float RevoluteJoint::getJointAngle() const
{
return joint->GetJointAngle();
@@ -136,6 +151,11 @@ int RevoluteJoint::getLimits(lua_State *L)
return 2;
}
float RevoluteJoint::getReferenceAngle() const
{
return joint->GetReferenceAngle();
}
} // box2d
} // physics
} // love