]> git.cworth.org Git - akamaru/commitdiff
Add grid model.
authorKristian Høgsberg <krh@redhat.com>
Sat, 20 May 2006 05:45:00 +0000 (01:45 -0400)
committerKristian Høgsberg <krh@dinky.bitplanet.net>
Sat, 20 May 2006 05:45:00 +0000 (01:45 -0400)
akamaru.c

index 58d9e5db67840b496b43a225dd47983fab6f415c..8fa2ec00f6dc4b22e494a8bd24c255196c5e18fa 100644 (file)
--- a/akamaru.c
+++ b/akamaru.c
@@ -188,6 +188,63 @@ model_init_curtain (Model *model)
   model->anchor_object = NULL;
 }
 
+static void
+model_init_grid (Model *model)
+{
+  const int num_ropes = 15;
+  const int num_rope_objects = 15;
+  const int num_objects = num_ropes * num_rope_objects;
+  const int num_sticks = num_ropes * (num_rope_objects - 1) +
+    (num_ropes - 1) * num_rope_objects;
+  const int stick_length = 10;
+  const int rope_offset = 10;
+  double x, y;
+  int i, j, index, stick_index;
+
+  model->objects = g_new (Object, num_objects);
+  model->num_objects = num_objects;
+  model->sticks = g_new (Stick, num_sticks);
+  model->num_sticks = num_sticks;
+  model->offsets = g_new (Offset, num_ropes - 1);
+  model->num_offsets = num_ropes - 1;
+
+  for (i = 0; i < num_ropes; i++) {
+    for (j = 0; j < num_rope_objects; j++) {
+      x = 200 + i * rope_offset;
+      y = 40 + j * stick_length;
+      index = i * num_rope_objects + j;
+      model->objects[index].position.x = x;
+      model->objects[index].position.y = y;
+      model->objects[index].previous_position.x = x;
+      model->objects[index].previous_position.y = y;
+
+      if (i + 1 < num_ropes) {
+       stick_index = i * num_rope_objects + j;
+       model->sticks[stick_index].a = &model->objects[index];
+       model->sticks[stick_index].b = &model->objects[index + num_rope_objects];
+       model->sticks[stick_index].length = stick_length;
+      }
+
+      if (j + 1 < num_rope_objects) {
+       stick_index =
+         (num_ropes - 1) * num_rope_objects + i * (num_rope_objects - 1) + j;
+       model->sticks[stick_index].a = &model->objects[index];
+       model->sticks[stick_index].b = &model->objects[index + 1];
+       model->sticks[stick_index].length = stick_length;
+      }
+    }
+
+    if (i + 1 < num_ropes) {
+      model->offsets[i].a = &model->objects[i * num_rope_objects];
+      model->offsets[i].b = &model->objects[(i + 1) * num_rope_objects];
+      model->offsets[i].dx = rope_offset;
+      model->offsets[i].dy = 0;
+    }
+  }
+
+  model->anchor_object = NULL;
+}
+
 static void
 model_fini (Model *model)
 {
@@ -209,7 +266,7 @@ model_accumulate_forces (Model *model)
 
   for (i = 0; i < model->num_objects; i++) {
     model->objects[i].force.x = 0;
-    model->objects[i].force.y = 0;
+    model->objects[i].force.y = 2;
   }
 }
 
@@ -333,7 +390,7 @@ model_step (Model *model, double delta_t)
   model_accumulate_forces (model);
   model_integrate (model, delta_t);
 
-  for (i = 0; i < 20; i++)
+  for (i = 0; i < 15; i++)
     model_constrain (model, delta_t);
 
   model->theta += delta_t;
@@ -561,7 +618,8 @@ create_model_store (void)
   } models[] = {
     { "Rope", model_init_rope },
     { "Snake", model_init_snake },
-    { "Curtain", model_init_curtain }
+    { "Curtain", model_init_curtain },
+    { "Grid", model_init_grid }
   };
 
   GtkTreeIter iter;