]> git.cworth.org Git - akamaru/commitdiff
Add init function for springs and clean up grid init.
authorKristian Høgsberg <krh@redhat.com>
Wed, 24 May 2006 19:42:48 +0000 (15:42 -0400)
committerKristian Høgsberg <krh@dinky.bitplanet.net>
Wed, 24 May 2006 19:42:48 +0000 (15:42 -0400)
akamaru.c
akamaru.h
main.c

index d158f3e2da5b3728882025fb3ce9c3598def2aef..eee05e24a1d68f28bd4893c431e11235e5487664 100644 (file)
--- a/akamaru.c
+++ b/akamaru.c
@@ -42,6 +42,14 @@ spring_init (Spring *spring, Object *a, Object *b, double length)
   spring->length = length;
 }
 
+void
+string_init (String *string, Object *a, Object *b, double length)
+{
+  string->a = a;
+  string->b = b;
+  string->length = length;
+}
+
 void
 offset_spring_init (OffsetSpring *spring, Object *a, Object *b,
                    double dx, double dy)
index 81eeb8545ab286219b727fde9e11265ab10db1d3..1d4796c94fe39a6efbab6f03bdfd76a9c74a12b3 100644 (file)
--- a/akamaru.h
+++ b/akamaru.h
@@ -88,6 +88,7 @@ void object_init (Object *object, double x, double y, double mass);
 void offset_spring_init (OffsetSpring *spring,
                         Object *a, Object *b, double dx, double dy);
 void spring_init (Spring *spring, Object *a, Object *b, double length);
+void string_init (String *string, Object *a, Object *b, double length);
 
 void polygon_init (Polygon *p, int num_points, ...);
 void polygon_init_diamond (Polygon *polygon, double x, double y);
diff --git a/main.c b/main.c
index 3cef5e98772520c59d4c63ba2dd31974bbc13294..2423b4f05069ab9c557a691e110984a5a8aeff2b 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];