struct quadtree_ops planet_ops;
+static int draw_lines = 0;
+
static void putpixel(struct SDL_Surface *screen, const int x, const int y,
const unsigned char r, const unsigned char g,
const unsigned char b)
buf[offset] = r;
}
+static void draw_line(SDL_Surface *screen, const struct vector *p1,
+ const struct vector *p2,
+ const unsigned char r, const unsigned char g,
+ const unsigned char b, const struct camera *cam)
+{
+ struct vector dir, v;
+ float len;
+ int i;
+
+ vector_sub(p2, p1, &dir);
+
+ len = vector_abs(&dir);
+ vector_scale(&dir, 1 / len, &dir);
+ len *= cam->zoom;
+
+ vector_sub(p1, &cam->pos, &v);
+ vector_scale(&v, cam->zoom, &v);
+
+ v.x += screen->w / 2;
+ v.y += screen->h / 2;
+
+ for (i = 0; i < len ; i++) {
+ if (v.x >= 0 && v.x < screen->w &&
+ v.y >= 0 && v.y < screen->h)
+ putpixel(screen, v.x, v.y, r, g, b);
+ vector_add(&v, &dir, &v);
+ }
+}
+
static void reshape_planet(struct planet *p)
{
p->radius = pow(p->mass / 100, 1 / 3.0);
pos.x += screen->w / 2;
pos.y += screen->h / 2;
+ if (draw_lines) {
+ for (i = 0; i < 4; i++) {
+ if (!p->tree.child[i])
+ continue;
+
+ struct planet *q = tree_to_planet(p->tree.child[i]);
+
+ draw_line(screen, &p->pos, &q->pos,
+ p->r, p->g, p->b, cam);
+ }
+ }
+
draw_circle(screen, &pos, radius, p->r, p->g, p->b, 0);
}