4ea8f2eddf5f76aabb74b5c55d9f0e47484e3288
[universe.git] / universe.h
1
2 ////////////////////////////////////////////////////////////////////////////////
3 // This program is free software; you can redistribute it and/or              //
4 // modify it under the terms of the GNU General Public License                //
5 // version 2 as published by the Free Software Foundation.                    //
6 //                                                                            //
7 // This program is distributed in the hope that it will be useful, but        //
8 // WITHOUT ANY WARRANTY; without even the implied warranty of                 //
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          //
10 // General Public License for more details.                                   //
11 //                                                                            //
12 // Written and (C) by François Fleuret                                        //
13 // Contact <francois.fleuret@epfl.ch> for comments & bug reports              //
14 ////////////////////////////////////////////////////////////////////////////////
15
16 #ifndef UNIVERSE_H
17 #define UNIVERSE_H
18
19 #include <iostream>
20 #include <cmath>
21
22 using namespace std;
23
24 #include "misc.h"
25 #include "simple_window.h"
26 #include "polygon.h"
27
28 class Universe {
29   scalar_t _xmax, _ymax;
30 public:
31   int _nb_max_polygons, _nb_polygons;
32   Polygon **_polygons;
33   Universe(int nb_max_polygons, scalar_t xmax, scalar_t ymax);
34   // The destructor deletes all the added polygons
35   ~Universe();
36   void initialize(Polygon *p);
37   void clear();
38   void add_polygon(Polygon *p);
39   bool collide(Polygon *p);
40   // Compute collisions between projections of the polygons on a few
41   // axis to speed up the computation
42   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
43   void apply_collision_forces(scalar_t dt);
44   bool update(scalar_t dt);
45   Polygon *pick_polygon(scalar_t x, scalar_t y);
46   void print_fig(ostream &os);
47   void draw(SimpleWindow *window);
48 };
49
50 #endif