提交 1c57e928 编写于 作者: V Viktor Lidholt

Adds support for applying forces and impulses to sprite physics

上级 6c78e664
......@@ -232,6 +232,58 @@ class PhysicsBody {
bool _attached = false;
void applyForce(Offset force, Point worldPoint) {
assert(_body != null);
Vector2 b2Force = new Vector2(
force.dx / _physicsNode.b2WorldToNodeConversionFactor,
force.dy / _physicsNode.b2WorldToNodeConversionFactor);
Vector2 b2Point = new Vector2(
worldPoint.x / _physicsNode.b2WorldToNodeConversionFactor,
worldPoint.y / _physicsNode.b2WorldToNodeConversionFactor
);
_body.applyForce(b2Force, b2Point);
}
void applyForceToCenter(Offset force) {
assert(_body != null);
Vector2 b2Force = new Vector2(
force.dx / _physicsNode.b2WorldToNodeConversionFactor,
force.dy / _physicsNode.b2WorldToNodeConversionFactor);
_body.applyForceToCenter(b2Force);
}
void applyTorque(double torque) {
assert(_body != null);
_body.applyTorque(torque / _physicsNode.b2WorldToNodeConversionFactor);
}
void applyLinearImpulse(Offset impulse, Point worldPoint, [bool wake = true]) {
assert(_body != null);
Vector2 b2Impulse = new Vector2(
impulse.dx / _physicsNode.b2WorldToNodeConversionFactor,
impulse.dy / _physicsNode.b2WorldToNodeConversionFactor);
Vector2 b2Point = new Vector2(
worldPoint.x / _physicsNode.b2WorldToNodeConversionFactor,
worldPoint.y / _physicsNode.b2WorldToNodeConversionFactor
);
_body.applyLinearImpulse(b2Impulse, b2Point, wake);
}
void applyAngularImpulse(double impulse) {
assert(_body != null);
_body.applyAngularImpulse(impulse / _physicsNode.b2WorldToNodeConversionFactor);
}
void _attach(PhysicsNode physicsNode, Node node) {
assert(_attached == false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册