Commit 7c5092f7 authored by Viktor Lidholt's avatar Viktor Lidholt

Adds support for dampening on weld physics joints in sprites

parent 106d3c4b
...@@ -64,7 +64,7 @@ class PhysicsJointRevolute extends PhysicsJoint { ...@@ -64,7 +64,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
PhysicsJointRevolute( PhysicsJointRevolute(
PhysicsBody bodyA, PhysicsBody bodyA,
PhysicsBody bodyB, PhysicsBody bodyB,
this.worldAnchor, { this._worldAnchor, {
this.lowerAngle: 0.0, this.lowerAngle: 0.0,
this.upperAngle: 0.0, this.upperAngle: 0.0,
this.enableLimit: false, this.enableLimit: false,
...@@ -73,7 +73,7 @@ class PhysicsJointRevolute extends PhysicsJoint { ...@@ -73,7 +73,7 @@ class PhysicsJointRevolute extends PhysicsJoint {
_completeCreation(); _completeCreation();
} }
final Point worldAnchor; final Point _worldAnchor;
final double lowerAngle; final double lowerAngle;
final double upperAngle; final double upperAngle;
final bool enableLimit; final bool enableLimit;
...@@ -81,8 +81,8 @@ class PhysicsJointRevolute extends PhysicsJoint { ...@@ -81,8 +81,8 @@ class PhysicsJointRevolute extends PhysicsJoint {
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsNode physicsNode) {
// Create Joint Definition // Create Joint Definition
Vector2 vecAnchor = new Vector2( Vector2 vecAnchor = new Vector2(
worldAnchor.x / physicsNode.b2WorldToNodeConversionFactor, _worldAnchor.x / physicsNode.b2WorldToNodeConversionFactor,
worldAnchor.y / physicsNode.b2WorldToNodeConversionFactor _worldAnchor.y / physicsNode.b2WorldToNodeConversionFactor
); );
box2d.RevoluteJointDef b2Def = new box2d.RevoluteJointDef(); box2d.RevoluteJointDef b2Def = new box2d.RevoluteJointDef();
...@@ -120,12 +120,17 @@ class PhysicsJointWeld extends PhysicsJoint { ...@@ -120,12 +120,17 @@ class PhysicsJointWeld extends PhysicsJoint {
PhysicsJointWeld( PhysicsJointWeld(
PhysicsBody bodyA, PhysicsBody bodyA,
PhysicsBody bodyB, { PhysicsBody bodyB, {
double breakingForce double breakingForce,
this.dampening: 0.0,
this.frequency: 0.0
} }
) : super(bodyA, bodyB, breakingForce) { ) : super(bodyA, bodyB, breakingForce) {
_completeCreation(); _completeCreation();
} }
final double dampening;
final double frequency;
box2d.Joint _createB2Joint(PhysicsNode physicsNode) { box2d.Joint _createB2Joint(PhysicsNode physicsNode) {
box2d.WeldJointDef b2Def = new box2d.WeldJointDef(); box2d.WeldJointDef b2Def = new box2d.WeldJointDef();
Vector2 middle = new Vector2( Vector2 middle = new Vector2(
...@@ -133,6 +138,8 @@ class PhysicsJointWeld extends PhysicsJoint { ...@@ -133,6 +138,8 @@ class PhysicsJointWeld extends PhysicsJoint {
(bodyA._body.position.y + bodyB._body.position.y) / 2.0 (bodyA._body.position.y + bodyB._body.position.y) / 2.0
); );
b2Def.initialize(bodyA._body, bodyB._body, middle); b2Def.initialize(bodyA._body, bodyB._body, middle);
b2Def.dampingRatio = dampening;
b2Def.frequencyHz = frequency;
return physicsNode.b2World.createJoint(b2Def); return physicsNode.b2World.createJoint(b2Def);
} }
} }
......
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