summaryrefslogtreecommitdiff
path: root/physics/Particle.cs
diff options
context:
space:
mode:
authorChristopher James Halse Rogers <chris@Burninator.(none)>2007-08-27 20:39:03 +1000
committerChristopher James Halse Rogers <chris@Burninator.(none)>2007-08-27 20:39:03 +1000
commit2ec676133b4e0d5e6187e5339a69bcdaafa1cfcc (patch)
tree33ec0efc4e080e57cb654237f236bbbd5087f02e /physics/Particle.cs
parent8035bb2e2bf4fc30aaef4bfb7c3ea8ad110ecdbb (diff)
parenta871a8128029698e9e789e1a00d0e6c5258d7873 (diff)
downloadcompiz-cil-master.tar.gz
compiz-cil-master.tar.bz2
Merge ../compiz-sharpHEADmaster
Diffstat (limited to 'physics/Particle.cs')
-rw-r--r--physics/Particle.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/physics/Particle.cs b/physics/Particle.cs
new file mode 100644
index 0000000..d69aeee
--- /dev/null
+++ b/physics/Particle.cs
@@ -0,0 +1,54 @@
+// Copyright 2006 Alp Toker <alp@atoker.com>
+// This software is made available under the MIT License
+// See COPYING for details
+
+using System;
+using System.Collections.Generic;
+
+namespace PhysModel
+{
+ public class Particle
+ {
+ public Vector Force;
+
+ public Point Position;
+ public Point PreviousPosition;
+ public Vector Velocity;
+
+ public double Mass;
+ public double Theta;
+
+ /*
+ public Particle (Point position, double mass)
+ {
+ this.Position = position;
+ this.PreviousPosition = position;
+ this.Mass = mass;
+ }
+ */
+
+ public double GetDistance (Point p)
+ {
+ Vector d = Position - p;
+ return Math.Sqrt (d.X*d.X + d.Y*d.Y);
+ }
+
+ public void AccumulateForces (Model Model)
+ {
+ //Gravity
+ Force = Model.Gravity * Mass;
+
+ //Friction
+ Vector v = Position - PreviousPosition;
+
+ Force -= v * Model.Friction;
+ }
+
+ public void Integrate (double step)
+ {
+ Point original_position = Position;
+ Position += Position - PreviousPosition + Force * step * step;
+ PreviousPosition = original_position;
+ }
+ }
+}