Cosmetics + started to prepare use without X11.
[universe.git] / universe.h
1
2 // Written and (C) by Francois Fleuret
3 // Contact <francois.fleuret@idiap.ch> for comments & bug reports
4
5 #ifndef UNIVERSE_H
6 #define UNIVERSE_H
7
8 #include <iostream>
9 #include <cmath>
10
11 #include "misc.h"
12 #include "polygon.h"
13
14 #ifdef X11_SUPPORT
15 #include "simple_window.h"
16 #endif
17
18 #ifdef CAIRO_SUPPORT
19 #include <cairo.h>
20 #endif
21
22 using namespace std;
23
24 class Universe {
25   scalar_t _xmax, _ymax;
26 public:
27   int _nb_max_polygons, _nb_polygons;
28   Polygon **_polygons;
29
30   inline scalar_t width() { return _xmax; }
31   inline scalar_t height() { return _ymax; }
32
33   Universe(int nb_max_polygons, scalar_t xmax, scalar_t ymax);
34   // The destructor deletes all the added polygons
35   ~Universe();
36
37   void initialize(Polygon *p);
38   void clear();
39   void add_polygon(Polygon *p);
40   bool collide(Polygon *p);
41
42   // Compute collisions between projections of the polygons on a few
43   // axis to speed up the computation
44   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
45   void apply_collision_forces(scalar_t dt);
46   bool update(scalar_t dt);
47
48   Polygon *pick_polygon(scalar_t x, scalar_t y);
49
50   void print_xfig(XFigTracer *tracer);
51
52 #ifdef X11_SUPPORT
53   void draw(SimpleWindow *window);
54 #endif
55
56 #ifdef CAIRO_SUPPORT
57   void draw(cairo_t *context_resource);
58 #endif
59 };
60
61 #endif