]> git.cworth.org Git - akamaru/blobdiff - akamaru.c
Add init functions for various objects, clean up model initializations.
[akamaru] / akamaru.c
index 8a9e587b40e66da2259011549be4fd2e97820e14..d158f3e2da5b3728882025fb3ce9c3598def2aef 100644 (file)
--- a/akamaru.c
+++ b/akamaru.c
  *   corrections at the end instead of meaning as it goes.
  */
 
-#include <gtk/gtk.h>
-#include <cairo.h>
-#include <cairo-xlib.h>
-#include <gdk/gdkx.h>
+#include <glib.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/time.h>
+#include <stdarg.h>
 #include <math.h>
 
 #include "akamaru.h"
@@ -27,6 +24,34 @@ const double elasticity = 0.7;
 const double friction = 1;
 const double gravity = 20;
 
+void
+object_init (Object *object, double x, double y, double mass)
+{
+  object->position.x = x;
+  object->position.y = y;
+  object->previous_position.x = x;
+  object->previous_position.y = y;
+  object->mass = mass;
+}
+
+void
+spring_init (Spring *spring, Object *a, Object *b, double length)
+{
+  spring->a = a;
+  spring->b = b;
+  spring->length = length;
+}
+
+void
+offset_spring_init (OffsetSpring *spring, Object *a, Object *b,
+                   double dx, double dy)
+{
+  spring->a = a;
+  spring->b = b;
+  spring->dx = dx;
+  spring->dy = dy;
+}
+
 void
 polygon_init (Polygon *p, int num_points, ...)
 {
@@ -157,7 +182,7 @@ model_accumulate_forces (Model *model)
       model->objects[i].force.x * model->objects[i].force.x +
       model->objects[i].force.y * model->objects[i].force.y;
 
-    if (f > 1000000)
+    if (f > 100000000)
       abort();
   }
 }