4 flatland is a simple 2d physical simulator
6 Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
7 Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 This file is part of flatland
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.
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.
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/>.
38 scalar_t _width, _height;
40 int _nb_max_polygons, _nb_polygons;
43 inline scalar_t width() { return _width; }
44 inline scalar_t height() { return _height; }
46 Universe(int nb_max_polygons, scalar_t width, scalar_t height);
47 // The destructor deletes all the added polygons
50 void initialize_polygon(Polygon *p);
52 void add_polygon(Polygon *p);
54 bool collide_with_borders(Polygon *p, scalar_t padding);
55 bool collide(Polygon *p);
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);
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);
65 Polygon *pick_polygon(scalar_t x, scalar_t y);
67 void draw(Canvas *canvas);