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);
}
}
-void draw_planet(SDL_Surface *screen, struct planet *p,
+void draw_planet(SDL_Surface *screen, const struct planet *p,
const struct camera *cam)
{
struct vector pos;
y = MAX(pos.y - radius, 0);
+ for (x = 0; x < 4; x++) {
+ if (!p->tree.child[x])
+ continue;
+
+ struct planet *q = tree_to_planet(p->tree.child[x]);
+
+ draw_line(screen, &p->pos, &q->pos,
+ p->r, p->g, p->b, cam);
+ }
+
if (radius * 2 <= 1) {
if (pos.x >= 0 && pos.x < screen->w &&
pos.y >= 0 && pos.y < screen->h)
offset = y * screen->pitch + x_start * 4;
for (x = x_start; x < x_end; x++) {
- buf[offset++] = p->b;
- buf[offset++] = p->g;
- buf[offset++] = p->r;
+ buf[offset++] += p->b;
+ buf[offset++] += p->g;
+ buf[offset++] += p->r;
offset++;
}
}
return tree_to_planet(tree_parent);
}
+ planet_ops.recalculate_stats(&p->tree);
+
return tree_to_planet(quadtree_find_parent(&p->tree));
}
void init_planet(struct planet *p);
void create_planets(struct planet *p, int num, double total_mass,
double radius);
-void draw_planet(SDL_Surface *screen, struct planet *p, const struct camera *);
+void draw_planet(SDL_Surface *screen, const struct planet *p,
+ const struct camera *);
void gravitize_planet_tree(struct planet *p, double time);
struct planet *merge_planets(struct planet *a, struct planet *b);
struct planet *move_planet(struct planet *p, const double time);