summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2006-05-20 01:45:00 -0400
committerKristian Høgsberg <krh@dinky.bitplanet.net>2006-05-20 01:45:00 -0400
commit407da16255fcc13f0510f7149bafe4484c4491a9 (patch)
treeabf199f3810c3b6c3ec5ab59c1f518d56b67c1b9
parentde1df294bc699a797290ca4e84318f8c7315eb3b (diff)
Add grid model.
-rw-r--r--akamaru.c64
1 files changed, 61 insertions, 3 deletions
diff --git a/akamaru.c b/akamaru.c
index 58d9e5d..8fa2ec0 100644
--- a/akamaru.c
+++ b/akamaru.c
@@ -189,6 +189,63 @@ model_init_curtain (Model *model)
}
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)
{
g_free (model->objects);
@@ -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;