X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=akamaru.c;h=c667c371fade45e09ca49cdd274e177723dc9e1d;hb=5443c3705048a110ece3acd77d0ecb1b5bf3619d;hp=804545411e5c4227f2e5a0e6982fe3d3cd5d2a1d;hpb=4be5b6593af8db64cd39dba290a2c64193bcdabd;p=akamaru diff --git a/akamaru.c b/akamaru.c index 8045454..c667c37 100644 --- a/akamaru.c +++ b/akamaru.c @@ -21,8 +21,8 @@ #include "akamaru.h" const double elasticity = 0.7; -const double friction = 1; -const double gravity = 20; +const double friction = 4; +const double gravity = 50; void object_init (Object *object, double x, double y, double mass) @@ -85,7 +85,7 @@ anchor_init (Anchor *anchor, Object *object, double x, double y) } void -polygon_init (Polygon *p, int num_points, ...) +polygon_init (Polygon *p, int enclosing, int num_points, ...) { double dx, dy, length; int i, j; @@ -97,6 +97,7 @@ polygon_init (Polygon *p, int num_points, ...) va_start (ap, num_points); p->num_points = num_points; p->points = g_new (Point, num_points); + p->enclosing = enclosing; for (i = 0; i < num_points; i++) { p->points[i].x = va_arg (ap, double); @@ -120,7 +121,7 @@ polygon_init (Polygon *p, int num_points, ...) void polygon_init_diamond (Polygon *polygon, double x, double y) { - return polygon_init (polygon, 5, + return polygon_init (polygon, FALSE, 5, x, y, x + 10, y + 40, x + 90, y + 40, @@ -132,7 +133,14 @@ void polygon_init_rectangle (Polygon *polygon, double x0, double y0, double x1, double y1) { - return polygon_init (polygon, 4, x0, y0, x0, y1, x1, y1, x1, y0); + return polygon_init (polygon, FALSE, 4, x0, y0, x0, y1, x1, y1, x1, y0); +} + +void +polygon_init_enclosing_rectangle (Polygon *polygon, double x0, double y0, + double x1, double y1) +{ + return polygon_init (polygon, TRUE, 4, x0, y0, x0, y1, x1, y1, x1, y0); } void @@ -276,10 +284,10 @@ polygon_contains_point (Polygon *polygon, Point *point) dy = point->y - polygon->points[i].y; if (polygon->normals[i].x * dx + polygon->normals[i].y * dy >= 0) - return FALSE; + return polygon->enclosing; } - return TRUE; + return !polygon->enclosing; } static void @@ -297,7 +305,6 @@ polygon_reflect_object (Polygon *polygon, Object *object) if (d > distance) { distance = d; edge = i; - polygon->edge = i; n = &polygon->normals[i]; } } @@ -428,7 +435,7 @@ model_step (Model *model, double delta_t) model_accumulate_forces (model); model_integrate (model, delta_t); - for (i = 0; i < 2; i++) + for (i = 0; i < 20; i++) model_constrain (model); model->theta += delta_t;