Renaming.
[flatland.git] / universe.cc
index 2b1383d..02f189c 100644 (file)
@@ -1,26 +1,26 @@
 
 /*
- *  dyncnn is a deep-learning algorithm for the prediction of
- *  interacting object dynamics
- *
*  Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
*  Written by Francois Fleuret <francois.fleuret@idiap.ch>
- *
- *  This file is part of dyncnn.
- *
*  dyncnn is free software: you can redistribute it and/or modify it
*  under the terms of the GNU General Public License version 3 as
*  published by the Free Software Foundation.
- *
*  dyncnn is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*  General Public License for more details.
- *
*  You should have received a copy of the GNU General Public License
*  along with dyncnn.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
+
+   flatland is a simple 2d physical simulator
+
+   Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
+   Written by Francois Fleuret <francois.fleuret@idiap.ch>
+
+   This file is part of flatland
+
  flatland is free software: you can redistribute it and/or modify it
+   under the terms of the GNU General Public License version 3 as
+   published by the Free Software Foundation.
+
  flatland is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
  along with flatland.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
 
 #include <string.h>
 
@@ -62,6 +62,11 @@ void Universe::add_polygon(Polygon *p) {
   }
 }
 
+bool Universe::collide_with_borders(Polygon *p, scalar_t padding) {
+  return p->collide_with_borders(padding, padding,_width - padding, _height - padding);
+
+}
+
 bool Universe::collide(Polygon *p) {
   for(int n = 0; n < _nb_polygons; n++)
     if(_polygons[n] && _polygons[n]->collide(p)) return true;
@@ -122,11 +127,13 @@ void Universe::compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis) {
   }
 }
 
-bool Universe::update(scalar_t dt) {
+bool Universe::update(scalar_t dt, scalar_t padding) {
   bool result = false;
   apply_collision_forces(dt);
   for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) {
-    _polygons[n]->apply_border_forces(dt, _width, _height);
+      _polygons[n]->apply_border_forces(dt,
+                                        padding, padding,
+                                        _width - padding, _height - padding);
     result |= _polygons[n]->update(dt);
   }
   return result;
@@ -152,6 +159,14 @@ void Universe::draw(Canvas *canvas) {
   }
 }
 
+void Universe::apply_gravity(scalar_t dt, scalar_t fx, scalar_t fy) {
+  for(int n = 0; n < _nb_polygons; n++)
+    if(_polygons[n])
+      _polygons[n]->apply_force(dt,
+                                _polygons[n]->_center_x, _polygons[n]->_center_y,
+                                fx, fy);
+}
+
 void Universe::apply_collision_forces(scalar_t dt) {
   const int nb_axis = 2;
   int nb_collision[_nb_polygons * _nb_polygons];