Initial commit
[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 // $Id: universe.h,v 1.21 2006-12-17 19:22:19 fleuret Exp $
17
18 #ifndef UNIVERSE_H
19 #define UNIVERSE_H
20
21 #include <iostream>
22 #include <cmath>
23
24 using namespace std;
25
26 #include "misc.h"
27 #include "simple_window.h"
28 #include "polygon.h"
29
30 class Universe {
31   scalar_t _xmax, _ymax;
32 public:
33   int _nb_max_polygons, _nb_polygons;
34   Polygon **_polygons;
35   Universe(int nb_max_polygons, scalar_t xmax, scalar_t ymax);
36   // The destructor deletes all the added polygons
37   ~Universe();
38   void initialize(Polygon *p);
39   void clear();
40   void add_polygon(Polygon *p);
41   bool collide(Polygon *p);
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   Polygon *pick_polygon(scalar_t x, scalar_t y);
48   void print_fig(ostream &os);
49   void draw(SimpleWindow *window);
50 };
51
52 #endif