]> git.itanic.dy.fi Git - sdl-planets/blob - planet.h
planet.c: Use the quadtree_move function from quadtree lib
[sdl-planets] / planet.h
1 #ifndef _PLANET_H
2 #define _PLANET_H
3
4 #include <SDL.h>
5
6 #include "vector.h"
7 #include "list.h"
8 #include "utils.h"
9 #include "camera.h"
10 #include "quadtree.h"
11
12 struct planet {
13         struct vector speed;
14         struct list_head list;
15         struct quadtree tree;
16         double mass;
17         float radius;
18         unsigned char r, g, b;
19
20         /* info about the planets in sub branches */
21         float tree_area;        /* total area occupied by the tree */
22         double tree_mass;       /* total mass occupied by the tree */
23 };
24
25 struct planet_search_iterator {
26         struct quadtree_iterator qt_iterator;
27         struct vector limit[2];
28         struct camera *cam;
29         SDL_Surface *screen;
30 };
31
32 #define list_to_planet(list_head) container_of((list_head), struct planet, list)
33
34 #define tree_to_planet(qt) container_of((qt), struct planet, tree)
35
36 #define qt_itr_to_planet_itr(qt)                                        \
37         container_of((qt), struct planet_search_iterator, qt_iterator)
38
39 void init_planet(struct planet *p);
40 void create_planets(struct planet *p, int num, double total_mass,
41                     double radius);
42 void draw_planet(SDL_Surface *screen, struct planet *p, const struct camera *);
43 int gravitize_planets(struct planet *a, struct planet *b, const double time);
44 struct planet *merge_planets(struct planet *a, struct planet *b);
45 struct planet *move_planet(struct planet *p, const double time);
46 void print_planet(const struct planet *p);
47
48 int planet_spatial_compare(struct quadtree *a, struct quadtree *b);
49 int planet_search_rectangular(struct quadtree *node,
50                               struct quadtree_iterator *itr);
51 void planet_draw_iterator(struct quadtree *node, struct quadtree_iterator *it);
52
53 #endif