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 @@ WeldJoint::WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, flo
, joint(NULL)
{
b2WeldJointDef 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 = (b2WeldJoint *)createJoint(&def);
}
WeldJoint::WeldJoint(Body *body1, Body *body2, float xA, float yA, float xB, float yB, bool collideConnected, float referenceAngle)
: Joint(body1, body2)
, joint(NULL)
{
b2WeldJointDef def;
init(def, body1, body2, xA, yA, xB, yB, collideConnected);
def.referenceAngle = referenceAngle;
joint = (b2WeldJoint *)createJoint(&def);
}
@@ -49,6 +57,13 @@ WeldJoint::~WeldJoint()
{
}
void WeldJoint::init(b2WeldJointDef &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;
}
void WeldJoint::setFrequency(float hz)
{
joint->SetFrequency(hz);
@@ -69,6 +84,11 @@ float WeldJoint::getDampingRatio() const
return joint->GetDampingRatio();
}
float WeldJoint::getReferenceAngle() const
{
return joint->GetReferenceAngle();
}
} // box2d
} // physics
} // love