Renaming.
[flatland.git] / universe.h
1
2 /*
3
4    flatland is a simple 2d physical simulator
5
6    Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
7    Written by Francois Fleuret <francois.fleuret@idiap.ch>
8
9    This file is part of flatland
10
11    flatland is free software: you can redistribute it and/or modify it
12    under the terms of the GNU General Public License version 3 as
13    published by the Free Software Foundation.
14
15    flatland is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with flatland.  If not, see <http://www.gnu.org/licenses/>.
22
23 */
24
25 #ifndef UNIVERSE_H
26 #define UNIVERSE_H
27
28 #include <iostream>
29 #include <cmath>
30
31 #include "misc.h"
32 #include "canvas.h"
33 #include "polygon.h"
34
35 using namespace std;
36
37 class Universe {
38   scalar_t _width, _height;
39 public:
40   int _nb_max_polygons, _nb_polygons;
41   Polygon **_polygons;
42
43   inline scalar_t width() { return _width; }
44   inline scalar_t height() { return _height; }
45
46   Universe(int nb_max_polygons, scalar_t width, scalar_t height);
47   // The destructor deletes all the added polygons
48   ~Universe();
49
50   void initialize_polygon(Polygon *p);
51   void clear();
52   void add_polygon(Polygon *p);
53
54   bool collide_with_borders(Polygon *p, scalar_t padding);
55   bool collide(Polygon *p);
56
57   // Compute collisions between projections of the polygons on a few
58   // axis to speed up the computation
59   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
60
61   void apply_gravity(scalar_t dt, scalar_t fx, scalar_t fy);
62   void apply_collision_forces(scalar_t dt);
63   bool update(scalar_t dt, scalar_t padding);
64
65   Polygon *pick_polygon(scalar_t x, scalar_t y);
66
67   void draw(Canvas *canvas);
68 };
69
70 #endif