+static void
+polygon_init (Polygon *p, int num_points, ...)
+{
+ double dx, dy, length;
+ int i, j;
+ va_list ap;
+
+ /* Polygons are defined counter-clock-wise in a coordinate system
+ * with the y-axis pointing down. */
+
+ va_start (ap, num_points);
+ p->num_points = num_points;
+ p->points = g_new (Point, num_points);
+
+ for (i = 0; i < num_points; i++) {
+ p->points[i].x = va_arg (ap, double);
+ p->points[i].y = va_arg (ap, double);
+ }
+ va_end (ap);
+
+ p->normals = g_new (Vector, p->num_points);
+ /* Compute outward pointing normals. p->normals[i] is the normal
+ * for the edged between p->points[i] and p->points[i + 1]. */
+ for (i = 0; i < p->num_points; i++) {
+ j = (i + 1) % p->num_points;
+ dx = p->points[j].x - p->points[i].x;
+ dy = p->points[j].y - p->points[i].y;
+ length = sqrt (dx * dx + dy * dy);
+ p->normals[i].x = -dy / length;
+ p->normals[i].y = dx / length;
+ }
+}
+
+static void
+polygon_init_diamond (Polygon *polygon, double x, double y)
+{
+ return polygon_init (polygon, 5,
+ x, y,
+ x + 10, y + 40,
+ x + 90, y + 40,
+ x + 100, y,
+ x + 50, y - 20);
+}
+
+static 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);
+}
+
+static void
+model_init_polygons (Model *model)
+{
+ const int num_polygons = 5;
+
+ model->polygons = g_new (Polygon, num_polygons);
+ polygon_init_diamond (&model->polygons[0], 250, 300);
+ polygon_init_diamond (&model->polygons[1], 400, 150);
+ polygon_init_rectangle (&model->polygons[2], -100, 200, 200, 250);
+ polygon_init_rectangle (&model->polygons[3], -200, ground_level,
+ 1200, ground_level + 400);
+
+ polygon_init_rectangle (&model->polygons[4], 300, 320, 400, 350);
+
+
+ model->num_polygons = num_polygons;
+}
+