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