]> git.itanic.dy.fi Git - sdl-planets/blobdiff - planet.c
quadtree: Only use the validator when debugging is enabled
[sdl-planets] / planet.c
index eb2881b50649c1c0daada225f064de42e29743fa..f72b1b0087a523fe76e0f10979fe5cd8d842d7de 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -51,7 +51,7 @@ static void setup_planet(struct planet *p, double mass, double total_mass,
        double velocity;
        double distance;
 
-       distance = radius * get_random_double();
+       distance = radius * pow(get_random_double(), 2);
        velocity = sqrt(total_mass / radius);
 
        velocity *= pow(distance / radius, 0.2);
@@ -73,7 +73,12 @@ void create_planets(struct planet *p, int num, double total_mass, double radius)
        double sum = 0;
        struct planet *new_planet;
 
-       for (i = 1; i < num; i++) {
+       setup_planet(p,
+                    total_mass / num * 2 * get_random_double(),
+                    total_mass,
+                    radius);
+
+       for (i = 0; i < num; i++) {
                new_planet = malloc(sizeof(*new_planet));
                init_planet(new_planet);
                list_add(&new_planet->list, &p->list);
@@ -84,8 +89,6 @@ void create_planets(struct planet *p, int num, double total_mass, double radius)
 
                sum += new_planet->mass;
        }
-
-       printf("Requested mass: %f, got %f\n", total_mass, sum);
 }
 
 void draw_planet(SDL_Surface *screen, struct planet *p,
@@ -94,7 +97,7 @@ void draw_planet(SDL_Surface *screen, struct planet *p,
        struct vector pos;
        float radius = p->radius * cam->zoom;
        float r2 = radius * radius;
-       int x, x_start, y, x_end, y_end;
+       int x, x_start, y, x_end;
 
        vector_sub(&p->pos, &cam->pos, &pos);
        vector_scale(&pos, cam->zoom, &pos);
@@ -103,7 +106,7 @@ void draw_planet(SDL_Surface *screen, struct planet *p,
 
        y = MAX(pos.y - radius, 0);
 
-       if (radius * 2 <= 1 ) {
+       if (radius * 2 <= 1) {
                if (pos.x >= 0 && pos.x < screen->w &&
                    pos.y >= 0 && pos.y < screen->h)
                        putpixel(screen, (int)pos.x, (int)pos.y,