From 3f5cdf3d255b9c1a5d96bb93b5e481787efe5547 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Fri, 19 May 2006 22:23:50 -0400 Subject: [PATCH] Version that doesn't segfault. --- akamaru.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/akamaru.c b/akamaru.c index 7e3c348..f6375e8 100644 --- a/akamaru.c +++ b/akamaru.c @@ -23,7 +23,7 @@ #include #include -const double stick_length = 10; +const double stick_length = 30; const double ground_friction = 0.1, ground_level = 400; const double box_left = 200, box_top = 200, box_bottom = 210; const double elasticity = 0.7; @@ -91,8 +91,8 @@ model_init (Model *model) model->sticks[i * 2].b = &model->objects[i + 1]; } if (i + 2 < num_objects) { - model->sticks[i * 2 + 1].a = &model->objects[i]; - model->sticks[i * 2 + 1].b = &model->objects[i + 2]; + model->sticks[i * 2 + 1].a = &model->objects[i]; + model->sticks[i * 2 + 1].b = &model->objects[i + 2]; } } @@ -136,7 +136,7 @@ static void model_constrain (Model *model, double step) { double dx, dy, x, y, distance, fraction, squared; - int i, j; + int i; /* Anchor object constraint. */ if (model->anchor_object != NULL) { @@ -185,14 +185,14 @@ model_constrain (Model *model, double step) for (i = 0; i < model->num_sticks; i++) { x = model->sticks[i].a->position.x; y = model->sticks[i].a->position.y; - dx = model->sticks[j].b->position.x - x; - dy = model->sticks[j].b->position.y - y; + dx = model->sticks[i].b->position.x - x; + dy = model->sticks[i].b->position.y - y; distance = sqrt (dx * dx + dy * dy); fraction = (distance - stick_length) / distance / 2; model->sticks[i].a->position.x = x + dx * fraction; model->sticks[i].a->position.y = y + dy * fraction; - model->sticks[j].b->position.x = x + dx * (1 - fraction); - model->sticks[j].b->position.y = y + dy * (1 - fraction); + model->sticks[i].b->position.x = x + dx * (1 - fraction); + model->sticks[i].b->position.y = y + dy * (1 - fraction); } #else /* Stick constraints, without square roots. */ @@ -220,7 +220,7 @@ model_step (Model *model, double delta_t) model_accumulate_forces (model); model_integrate (model, delta_t); - for (i = 0; i < 10; i++) + for (i = 0; i < 50; i++) model_constrain (model, delta_t); model->theta += delta_t; @@ -345,7 +345,6 @@ sproing_expose_event (GtkWidget *widget, gpointer data) { Model *model = data; - int i; cairo_t *cr; cr = gdk_cairo_create (widget->window); -- 2.43.0