summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2006-05-19 22:23:50 -0400
committerKristian Høgsberg <krh@dinky.bitplanet.net>2006-05-19 22:23:50 -0400
commit3f5cdf3d255b9c1a5d96bb93b5e481787efe5547 (patch)
tree4bff3ace9a2e2b8636ab761d1a864910b1fd1170
parent758f31020accdd5904c4ceb517f296fe2e22977e (diff)
Version that doesn't segfault.
-rw-r--r--akamaru.c19
1 files 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 <gdk/gdkx.h>
#include <math.h>
-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);