Index: sky/framework/animation/mechanics.dart |
diff --git a/sky/framework/animation/mechanics.dart b/sky/framework/animation/mechanics.dart |
index d946917248db46757a25298c97288232f63db5be..6a6cc4cad46f7f8c744afe9cd8ac06757e5ba1a8 100644 |
--- a/sky/framework/animation/mechanics.dart |
+++ b/sky/framework/animation/mechanics.dart |
@@ -25,10 +25,10 @@ class Particle extends System { |
position += velocity * deltaT; |
} |
- double get energy => 0.5 * mass * velocity * velocity; |
- set energy(double e) { // J |
- assert(e >= 0.0); |
- velocity = math.sqrt(2.0 * e / mass); |
+ void setVelocityFromEnergy({double energy, double direction}) { |
eseidel
2015/04/21 19:52:33
Why the {}? Doesn't that make them optional named
Hixie
2015/04/21 20:18:52
It makes them named, yes. (They're always "optiona
|
+ assert(direction == -1.0 || direction == 1.0); |
+ assert(energy >= 0.0); |
+ velocity = math.sqrt(2.0 * energy / mass) * direction; |
} |
} |
@@ -174,7 +174,10 @@ class ParticleClimbingRamp extends System { |
// potential energy at the top of the slope, which is g*h*m. |
// If the slope's horizontal component is delta P long, then |
// the height is delta P times tan theta. |
- particle.energy = -kGravity * (deltaPosition * tanTheta) * particle.mass; |
+ particle.setVelocityFromEnergy( |
+ energy: (kGravity * (deltaPosition * tanTheta) * particle.mass).abs(), |
+ direction: deltaPosition > 0.0 ? 1.0 : -1.0 |
+ ); |
box.confine(particle); |
} |