summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2006-05-24 15:42:48 -0400
committerKristian Høgsberg <krh@dinky.bitplanet.net>2006-05-24 15:42:48 -0400
commit1c5cfec7a396c39cfcdeadfcf48c2dd15ba21ea8 (patch)
treeb49e36c22979d0d74975a3b8fd601987305670b0
parent4ea6cfd18613d299d62dc95a4d53161d89745935 (diff)
Add init function for springs and clean up grid init.
-rw-r--r--akamaru.c8
-rw-r--r--akamaru.h1
-rw-r--r--main.c32
3 files changed, 21 insertions, 20 deletions
diff --git a/akamaru.c b/akamaru.c
index d158f3e..eee05e2 100644
--- a/akamaru.c
+++ b/akamaru.c
@@ -43,6 +43,14 @@ spring_init (Spring *spring, Object *a, Object *b, double 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)
{
diff --git a/akamaru.h b/akamaru.h
index 81eeb85..1d4796c 100644
--- 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 3cef5e9..2423b4f 100644
--- 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];