Commit 5ac4d1ea authored by Viktor Lidholt's avatar Viktor Lidholt

Adds forwarding of properties to box2d in sprite physics

parent 018cef61
...@@ -13,10 +13,10 @@ class PhysicsBody { ...@@ -13,10 +13,10 @@ class PhysicsBody {
double friction: 0.0, double friction: 0.0,
double restitution: 0.0, double restitution: 0.0,
bool isSensor: false, bool isSensor: false,
this.linearVelocity: Offset.zero, Offset linearVelocity: Offset.zero,
this.angularVelocity: 0.0, double angularVelocity: 0.0,
this.linearDampening: 0.0, this.linearDampening: 0.0,
this.angularDampening: 0.0, double awakeangularDampening: 0.0,
this.allowSleep: true, this.allowSleep: true,
this.awake: true, this.awake: true,
this.fixedRotation: false, this.fixedRotation: false,
...@@ -28,11 +28,15 @@ class PhysicsBody { ...@@ -28,11 +28,15 @@ class PhysicsBody {
this.friction = friction; this.friction = friction;
this.restitution = restitution; this.restitution = restitution;
this.isSensor = isSensor; this.isSensor = isSensor;
this.linearVelocity = linearVelocity;
this.angularVelocity = angularVelocity;
this.angularDampening = angularDampening;
} }
Object tag; Object tag;
PhysicsShape shape; final PhysicsShape shape;
PhysicsBodyType type; PhysicsBodyType type;
...@@ -45,7 +49,7 @@ class PhysicsBody { ...@@ -45,7 +49,7 @@ class PhysicsBody {
if (_body == null) if (_body == null)
return; return;
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) { for (box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
f.setDensity(density); f.setDensity(density);
} }
} }
...@@ -59,7 +63,7 @@ class PhysicsBody { ...@@ -59,7 +63,7 @@ class PhysicsBody {
if (_body == null) if (_body == null)
return; return;
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) { for (box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
f.setFriction(friction); f.setFriction(friction);
} }
} }
...@@ -73,7 +77,7 @@ class PhysicsBody { ...@@ -73,7 +77,7 @@ class PhysicsBody {
if (_body == null) if (_body == null)
return; return;
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) { for (box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
f.setRestitution(restitution); f.setRestitution(restitution);
} }
} }
...@@ -87,17 +91,65 @@ class PhysicsBody { ...@@ -87,17 +91,65 @@ class PhysicsBody {
if (_body == null) if (_body == null)
return; return;
for(box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) { for (box2d.Fixture f = _body.getFixtureList(); f != null; f = f.getNext()) {
f.setSensor(isSensor); f.setSensor(isSensor);
} }
} }
Offset linearVelocity; Offset _linearVelocity;
double angularVelocity;
Offset get linearVelocity {
if (_body == null)
return _linearVelocity;
else {
double dx = _body.linearVelocity.x * _physicsNode.b2WorldToNodeConversionFactor;
double dy = _body.linearVelocity.y * _physicsNode.b2WorldToNodeConversionFactor;
return new Offset(dx, dy);
}
}
set linearVelocity(Offset linearVelocity) {
_linearVelocity = linearVelocity;
if (_body != null) {
Vector2 vec = new Vector2(
linearVelocity.dx / _physicsNode.b2WorldToNodeConversionFactor,
linearVelocity.dy / _physicsNode.b2WorldToNodeConversionFactor
);
_body.linearVelocity = vec;
}
}
double _angularVelocity;
double get angularVelocity {
if (_body == null)
return _angularVelocity;
else
return _body.angularVelocity;
}
set angularVelocity(double angularVelocity) {
_angularVelocity = angularVelocity;
double linearDampening; if (_body != null) {
_body.angularVelocity = angularVelocity;
}
}
double angularDampening; // TODO: Should this be editable in box2d.Body ?
final double linearDampening;
double _angularDampening;
double get angularDampening => _angularDampening;
set angularDampening(double angularDampening) {
_angularDampening = angularDampening;
if (_body != null)
_body.angularDamping = angularDampening;
}
bool allowSleep; bool allowSleep;
......
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