]> git.cworth.org Git - akamaru/blobdiff - main.c
Add new Spacer constraint and a 'dock' model.
[akamaru] / main.c
diff --git a/main.c b/main.c
index 3cef5e98772520c59d4c63ba2dd31974bbc13294..39cb5ad1158a64535661f33fb6221138f74ca51d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -152,8 +152,9 @@ model_init_grid (Model *model)
     (num_ropes - 1) * num_rope_objects;
   const int string_length = 20;
   const int rope_offset = 20;
-  double x, y;
-  int i, j, index, string_index;
+  Object *object;
+  String *string;
+  int i, j;
 
   memset (model, 0, sizeof *model);
   model->objects = g_new (Object, num_objects);
@@ -169,27 +170,18 @@ model_init_grid (Model *model)
   model->offsets[0].dx = rope_offset;
   model->offsets[0].dy = 0;
 
+  object = model->objects;
+  string = model->strings;
   for (i = 0; i < num_ropes; i++) {
     for (j = 0; j < num_rope_objects; j++) {
-      x = 200 + i * rope_offset;
-      y = 40 + j * string_length;
-      index = i * num_rope_objects + j;
-      object_init (&model->objects[index], x, y, 1);
-
-      if (i + 1 < num_ropes) {
-       string_index = i * num_rope_objects + j;
-       model->strings[string_index].a = &model->objects[index];
-       model->strings[string_index].b = &model->objects[index + num_rope_objects];
-       model->strings[string_index].length = string_length;
-      }
+      object_init (object, 200 + i * rope_offset, 40 + j * string_length, 1);
 
-      if (j + 1 < num_rope_objects) {
-       string_index =
-         (num_ropes - 1) * num_rope_objects + i * (num_rope_objects - 1) + j;
-       model->strings[string_index].a = &model->objects[index];
-       model->strings[string_index].b = &model->objects[index + 1];
-       model->strings[string_index].length = string_length;
-      }
+      if (i + 1 < num_ropes)
+       string_init (string++,
+                    object, object + num_rope_objects, string_length);
+      if (j + 1 < num_rope_objects)
+       string_init (string++, object, object + 1, string_length);
+      object++;
     }
 
     model->offsets[0].objects[i] = &model->objects[i * num_rope_objects];
@@ -269,6 +261,53 @@ model_init_wobbly (Model *model)
   }
 }
 
+static void
+model_init_dock (Model *model)
+{
+  const int num_objects = 8;
+  const int num_spacers = (num_objects - 1) * (num_objects - 2) / 2;
+  const int num_springs = num_objects - 1;
+  const int distance = 30;
+  double x, y;
+  int i, j;
+  Object *object;
+  Spring *spring;
+  Spacer *spacer;
+
+  memset (model, 0, sizeof *model);
+  model->objects = g_new (Object, num_objects);
+  model->num_objects = num_objects;
+  model->springs = g_new (Spring, num_springs);
+  model->num_springs = num_springs;
+  model->spacers = g_new (Spacer, num_spacers);
+  model->num_spacers = num_spacers;
+  model->k = 0.1;
+
+  model_init_polygons (model);
+  model->polygons = g_new (Polygon, 1);
+  polygon_init_rectangle (&model->polygons[0], -400, 300, 1400, 350);
+  model->num_polygons = 1;
+
+
+  object = model->objects;
+  spring = model->springs;
+  spacer = model->spacers;
+  for (i = 0; i < num_objects; i++, object++) {
+    x = 200 + i * distance / 3;
+    y = 40;
+    object_init (object, x, y, 1);
+    if (i == 0)
+      continue;
+    spring_init (spring++,
+                &model->objects[0],
+                &model->objects[i],
+                distance);
+    for (j = 1; j < num_objects - i; j++) {
+      spacer_init (spacer++, object, object + j, distance);
+    }
+  }
+}
+
 typedef struct _Color Color;
 struct _Color {
   double red, green, blue;
@@ -562,7 +601,8 @@ create_model_store (void)
     { "Curtain", model_init_curtain },
     { "Grid", model_init_grid },
     { "Molecule", model_init_molecule },
-    { "Wobbly", model_init_wobbly }
+    { "Wobbly", model_init_wobbly },
+    { "Dock", model_init_dock }
   };
 
   GtkTreeIter iter;