Commit 90971695 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds pulley joint to sprite physics and makes joint variables final

parent 5a7d2167
...@@ -6,8 +6,8 @@ abstract class PhysicsJoint { ...@@ -6,8 +6,8 @@ abstract class PhysicsJoint {
bodyB._joints.add(this); bodyB._joints.add(this);
} }
PhysicsBody bodyA; final PhysicsBody bodyA;
PhysicsBody bodyB; final PhysicsBody bodyB;
bool _active = true; bool _active = true;
box2d.Joint _joint; box2d.Joint _joint;
...@@ -43,21 +43,17 @@ class PhysicsJointRevolute extends PhysicsJoint { ...@@ -43,21 +43,17 @@ class PhysicsJointRevolute extends PhysicsJoint {
PhysicsBody bodyA, PhysicsBody bodyA,
PhysicsBody bodyB, PhysicsBody bodyB,
this.worldAnchor, { this.worldAnchor, {
double lowerAngle: 0.0, this.lowerAngle: 0.0,
double upperAngle: 0.0, this.upperAngle: 0.0,
bool enableLimit: false this.enableLimit: false
}) : super(bodyA, bodyB) { }) : super(bodyA, bodyB) {
this.lowerAngle = lowerAngle;
this.upperAngle = upperAngle;
this.enableLimit = enableLimit;
_completeCreation(); _completeCreation();
} }
Point worldAnchor; final Point worldAnchor;
double lowerAngle; final double lowerAngle;
double upperAngle; final double upperAngle;
bool enableLimit; final bool enableLimit;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsNode physicsNode) {
// Create Joint Definition // Create Joint Definition
...@@ -81,7 +77,8 @@ class PhysicsJointPrismatic extends PhysicsJoint { ...@@ -81,7 +77,8 @@ class PhysicsJointPrismatic extends PhysicsJoint {
PhysicsJointPrismatic( PhysicsJointPrismatic(
PhysicsBody bodyA, PhysicsBody bodyA,
PhysicsBody bodyB, PhysicsBody bodyB,
this.axis) : super(bodyA, bodyB) { this.axis
) : super(bodyA, bodyB) {
_completeCreation(); _completeCreation();
} }
...@@ -97,7 +94,8 @@ class PhysicsJointPrismatic extends PhysicsJoint { ...@@ -97,7 +94,8 @@ class PhysicsJointPrismatic extends PhysicsJoint {
class PhysicsJointWeld extends PhysicsJoint { class PhysicsJointWeld extends PhysicsJoint {
PhysicsJointWeld( PhysicsJointWeld(
PhysicsBody bodyA, PhysicsBody bodyA,
PhysicsBody bodyB) : super(bodyA, bodyB) { PhysicsBody bodyB
) : super(bodyA, bodyB) {
_completeCreation(); _completeCreation();
} }
...@@ -111,3 +109,44 @@ class PhysicsJointWeld extends PhysicsJoint { ...@@ -111,3 +109,44 @@ class PhysicsJointWeld extends PhysicsJoint {
return physicsNode.b2World.createJoint(b2Def); return physicsNode.b2World.createJoint(b2Def);
} }
} }
class PhysicsJointPulley extends PhysicsJoint {
PhysicsJointPulley(
PhysicsBody bodyA,
PhysicsBody bodyB,
this.groundAnchorA,
this.groundAnchorB,
this.anchorA,
this.anchorB,
this.ratio
) : super(bodyA, bodyB) {
_completeCreation();
}
final Point groundAnchorA;
final Point groundAnchorB;
final Point anchorA;
final Point anchorB;
final double ratio;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) {
box2d.PulleyJointDef b2Def = new box2d.PulleyJointDef();
b2Def.initialize(
bodyA._body,
bodyB._body,
_convertPosToVec(groundAnchorA, physicsNode),
_convertPosToVec(groundAnchorB, physicsNode),
_convertPosToVec(anchorA, physicsNode),
_convertPosToVec(anchorB, physicsNode),
ratio
);
return physicsNode.b2World.createJoint(b2Def);
}
}
Vector2 _convertPosToVec(Point pt, PhysicsNode physicsNode) {
return new Vector2(
pt.x / physicsNode.b2WorldToNodeConversionFactor,
pt.y / physicsNode.b2WorldToNodeConversionFactor
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment