From 407da16255fcc13f0510f7149bafe4484c4491a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Sat, 20 May 2006 01:45:00 -0400 Subject: [PATCH] Add grid model. --- akamaru.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/akamaru.c b/akamaru.c index 58d9e5d..8fa2ec0 100644 --- 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; -- 2.43.0