]> git.cworth.org Git - akamaru/commitdiff
Version that doesn't segfault.
authorKristian Høgsberg <krh@redhat.com>
Sat, 20 May 2006 02:23:50 +0000 (22:23 -0400)
committerKristian Høgsberg <krh@dinky.bitplanet.net>
Sat, 20 May 2006 02:23:50 +0000 (22:23 -0400)
akamaru.c

index 7e3c3488c2200c58f099a63e9f29e29f494b421a..f6375e8438666566e0e0b0c1a3d9443c0ff4c4d5 100644 (file)
--- 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);