Seems to work quite well.
[flatland.git] / universe.h
1
2 /*
3  *  dyncnn is a deep-learning algorithm for the prediction of
4  *  interacting object dynamics
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 dyncnn.
10  *
11  *  dyncnn 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  *  dyncnn 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 dyncnn.  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   bool collide(Polygon *p);
54
55   // Compute collisions between projections of the polygons on a few
56   // axis to speed up the computation
57   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
58   void apply_collision_forces(scalar_t dt);
59   bool update(scalar_t dt, scalar_t padding);
60
61   Polygon *pick_polygon(scalar_t x, scalar_t y);
62
63   void draw(Canvas *canvas);
64 };
65
66 #endif