#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)
}
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;
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);
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,
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
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
if (d > distance) {
distance = d;
edge = i;
- polygon->edge = i;
n = &polygon->normals[i];
}
}
}
}
+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)
{
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++) {
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;