b164d0b9c8b55447a74deb265e3d82fb842c49fa
[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 "canvas.h"
13 #include "polygon.h"
14
15 #ifdef X11_SUPPORT
16 #include "simple_window.h"
17 #endif
18
19 using namespace std;
20
21 class Universe {
22   scalar_t _width, _height;
23 public:
24   int _nb_max_polygons, _nb_polygons;
25   Polygon **_polygons;
26
27   inline scalar_t width() { return _width; }
28   inline scalar_t height() { return _height; }
29
30   Universe(int nb_max_polygons, scalar_t width, scalar_t height);
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
49 #ifdef X11_SUPPORT
50   void draw(SimpleWindow *window);
51 #endif
52
53   void draw(Canvas *canvas);
54 };
55
56 #endif