mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Support reference angle on revolute, prismatic, and weld joints (fixes #1194)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user