diff options
author | Kristian Høgsberg <krh@redhat.com> | 2006-05-24 15:42:48 -0400 |
---|---|---|
committer | Kristian Høgsberg <krh@dinky.bitplanet.net> | 2006-05-24 15:42:48 -0400 |
commit | 1c5cfec7a396c39cfcdeadfcf48c2dd15ba21ea8 (patch) | |
tree | b49e36c22979d0d74975a3b8fd601987305670b0 | |
parent | 4ea6cfd18613d299d62dc95a4d53161d89745935 (diff) |
Add init function for springs and clean up grid init.
-rw-r--r-- | akamaru.c | 8 | ||||
-rw-r--r-- | akamaru.h | 1 | ||||
-rw-r--r-- | main.c | 32 |
3 files changed, 21 insertions, 20 deletions
@@ -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) { @@ -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); @@ -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]; |