X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=akamaru.c;h=76f00583bb58da68b926a761e224a6c1cf0fbffd;hb=05af0909cc976c183e82d8392107ef11d77bb4ec;hp=ae01a27223ba5896eefe5ec53fed9b25c33f0849;hpb=ac886f983a984a951187fae89c530858013ef118;p=akamaru diff --git a/akamaru.c b/akamaru.c index ae01a27..76f0058 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 = 8; +const double gravity = 50; void object_init (Object *object, double x, double y, double mass) @@ -77,7 +77,15 @@ spacer_init (Spacer *spacer, Object *a, Object *b, double length) } void -polygon_init (Polygon *p, int num_points, ...) +anchor_init (Anchor *anchor, Object *object, double x, double y) +{ + anchor->object = object; + anchor->x = x; + anchor->y = y; +} + +void +polygon_init (Polygon *p, int enclosing, int num_points, ...) { double dx, dy, length; int i, j; @@ -89,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); @@ -112,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, @@ -124,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 @@ -268,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 @@ -289,7 +305,6 @@ polygon_reflect_object (Polygon *polygon, Object *object) if (d > distance) { distance = d; edge = i; - polygon->edge = i; n = &polygon->normals[i]; } } @@ -316,6 +331,15 @@ model_constrain_polygon (Model *model, Polygon *polygon) } } +static void +model_constrain_anchor (Model *model, Anchor *anchor) +{ + anchor->object->position.x = anchor->x; + anchor->object->position.y = anchor->y; + anchor->object->previous_position.x = anchor->x; + anchor->object->previous_position.y = anchor->y; +} + static void model_constrain_offset (Model *model, Offset *offset) { @@ -344,13 +368,10 @@ model_constrain (Model *model) double dx, dy, x, y, distance, fraction; int i; - /* Anchor object constraint. */ - if (model->anchor_object != NULL) { - model->anchor_object->position.x = model->anchor_position.x; - model->anchor_object->position.y = model->anchor_position.y; - model->anchor_object->previous_position.x = model->anchor_position.x; - model->anchor_object->previous_position.y = model->anchor_position.y; - } + if (model->mouse_anchor.object != NULL) + model_constrain_anchor (model, &model->mouse_anchor); + for (i = 0; i < model->num_anchors; i++) + model_constrain_anchor (model, &model->anchors[i]); /* String constraints. */ for (i = 0; i < model->num_strings; i++) { @@ -414,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;