]> git.cworth.org Git - akamaru/blobdiff - akamaru.c
Add new akamaru example: a crazy icon dock.
[akamaru] / akamaru.c
index ae01a27223ba5896eefe5ec53fed9b25c33f0849..88277f66bc9dd78a0c491e243731f3089627c24e 100644 (file)
--- a/akamaru.c
+++ b/akamaru.c
@@ -20,9 +20,9 @@
 
 #include "akamaru.h"
 
-const double elasticity = 0.7;
+const double elasticity = 0.5;
 const double friction = 1;
-const double gravity = 20;
+const double gravity = 50;
 
 void
 object_init (Object *object, double x, double y, double mass)
@@ -76,6 +76,14 @@ spacer_init (Spacer *spacer, Object *a, Object *b, double length)
   spacer->length = length;
 }
 
+void
+anchor_init (Anchor *anchor, Object *object, double x, double y)
+{
+  anchor->object = object;
+  anchor->x = x;
+  anchor->y = y;
+}
+
 void
 polygon_init (Polygon *p, int num_points, ...)
 {
@@ -316,6 +324,15 @@ model_constrain_polygon (Model *model, Polygon *polygon)
   }
 }
 
+static void
+model_constrain_anchor (Model *model, Anchor *anchor)
+{
+  anchor->object->position.x = anchor->x;
+  anchor->object->position.y = anchor->y;
+  anchor->object->previous_position.x = anchor->x;
+  anchor->object->previous_position.y = anchor->y;
+}
+
 static void
 model_constrain_offset (Model *model, Offset *offset)
 {
@@ -344,13 +361,10 @@ model_constrain (Model *model)
   double dx, dy, x, y, distance, fraction;
   int i;
 
-  /* Anchor object constraint. */
-  if (model->anchor_object != NULL) {
-    model->anchor_object->position.x = model->anchor_position.x;
-    model->anchor_object->position.y = model->anchor_position.y;
-    model->anchor_object->previous_position.x = model->anchor_position.x;
-    model->anchor_object->previous_position.y = model->anchor_position.y;
-  }
+  if (model->mouse_anchor.object != NULL)
+    model_constrain_anchor (model, &model->mouse_anchor);
+  for (i = 0; i < model->num_anchors; i++)
+    model_constrain_anchor (model, &model->anchors[i]);
 
   /* String constraints. */
   for (i = 0; i < model->num_strings; i++) {