Cleaned up a bit. SimpleWindow now embed the cairo fields to allow proper deallocatio...
[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 #ifdef CAIRO_SUPPORT
12 #include <cairo.h>
13 #endif
14
15 using namespace std;
16
17 #include "misc.h"
18 #include "simple_window.h"
19 #include "polygon.h"
20
21 class Universe {
22   scalar_t _xmax, _ymax;
23 public:
24   int _nb_max_polygons, _nb_polygons;
25   Polygon **_polygons;
26
27   inline scalar_t width() { return _xmax; }
28   inline scalar_t height() { return _ymax; }
29
30   Universe(int nb_max_polygons, scalar_t xmax, scalar_t ymax);
31   // The destructor deletes all the added polygons
32   ~Universe();
33
34   void initialize(Polygon *p);
35   void clear();
36   void add_polygon(Polygon *p);
37   bool collide(Polygon *p);
38
39   // Compute collisions between projections of the polygons on a few
40   // axis to speed up the computation
41   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
42   void apply_collision_forces(scalar_t dt);
43   bool update(scalar_t dt);
44
45   Polygon *pick_polygon(scalar_t x, scalar_t y);
46
47   void print_xfig(XFigTracer *tracer);
48   void draw(SimpleWindow *window);
49
50 #ifdef CAIRO_SUPPORT
51   void draw(cairo_t *context_resource);
52 #endif
53 };
54
55 #endif