samples/guiAndGfx: eC port of JFD's Mekano
[sdk] / samples / guiAndGfx / mekano / mekanoobjectgravity.ec
diff --git a/samples/guiAndGfx/mekano/mekanoobjectgravity.ec b/samples/guiAndGfx/mekano/mekanoobjectgravity.ec
new file mode 100644 (file)
index 0000000..0c50aa4
--- /dev/null
@@ -0,0 +1,24 @@
+import "mekanosimulation"
+
+class MekanoObjectGravity : MekanoObject
+{
+   Vector2D gravity;
+
+public:
+   property Vector2D gravity
+   {
+      set { gravity = value; }
+      get { value = gravity; }
+   }
+
+   void exertForces(MekanoSimulation sim)
+   {
+      for(o : sim.objectList)
+         for(p : o.points; p.type == center)
+         {
+            Vector2D f;
+            f.scale(gravity, o.mass);
+            o.applyForce(f, p);
+         }
+   }
+}