summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlp Toker <alp@atoker.com>2006-07-27 06:20:03 +0100
committerAlp Toker <alp@atoker.com>2006-07-27 06:20:03 +0100
commit24963900945baf5b355fd06d9a98d5bd067b215b (patch)
tree5e7c27c06e17faaf5d817e4f7dcfc2eda66b3844
parent04392d16af38704ba31bc45ddf689a5ee70e3192 (diff)
downloadcompiz-cil-24963900945baf5b355fd06d9a98d5bd067b215b.tar.gz
compiz-cil-24963900945baf5b355fd06d9a98d5bd067b215b.tar.bz2
Start on Spring constraint
Needed for dock model
-rw-r--r--physics/Demo.cs2
-rw-r--r--physics/Model.cs25
2 files changed, 17 insertions, 10 deletions
diff --git a/physics/Demo.cs b/physics/Demo.cs
index db2650c..7ca53e5 100644
--- a/physics/Demo.cs
+++ b/physics/Demo.cs
@@ -98,7 +98,6 @@ public class PhysDemo
n.Position = new PhysModel.Point (200, 40 + i * stickLength);
n.PreviousPosition = n.Position;
n.Mass = 1;
- n.Model = model;
model.Particles.Add (n);
if (prev != null) {
@@ -131,7 +130,6 @@ public class PhysDemo
PhysModel.Point pos = new PhysModel.Point (200 + i * ropeOffset, 40 + j * stickLength);
Particle n = new Particle ();
n.Mass = 1;
- n.Model = model;
n.Position = pos;
n.PreviousPosition = pos;
model.Particles.Add (n);
diff --git a/physics/Model.cs b/physics/Model.cs
index 10aa427..29a656f 100644
--- a/physics/Model.cs
+++ b/physics/Model.cs
@@ -124,7 +124,10 @@ namespace PhysModel
public void AccumulateForces ()
{
foreach (Particle n in Particles)
- n.AccumulateForces ();
+ n.AccumulateForces (this);
+
+ foreach (Spring s in Springs)
+ s.AccumulateForces (this);
}
public void Constrain ()
@@ -176,8 +179,6 @@ namespace PhysModel
public class Particle
{
- public Model Model;
-
public Vector Force;
public Point Position;
@@ -202,7 +203,7 @@ namespace PhysModel
return Math.Sqrt (d.X*d.X + d.Y*d.Y);
}
- public void AccumulateForces ()
+ public void AccumulateForces (Model Model)
{
//Gravity
Force = Model.Gravity * Mass;
@@ -252,12 +253,20 @@ namespace PhysModel
public class Spring : Stick
{
- /*
- public void AccumulateForces ()
+ public void AccumulateForces (Model model)
{
- double x, y, dx, dy, distance, displacement;
+ Point pos = A.Position;
+ Vector d = B.Position - pos;
+
+ double distance = Math.Sqrt (d.X*d.X + d.Y*d.Y);
+
+ Vector u = d / distance;
+
+ double displacement = distance - Length;
+
+ A.Force += u * model.K * displacement;
+ B.Force -= u * model.K * displacement;
}
- */
}
public class OffsetSpring : Spring