Update.
authorFrancois Fleuret <francois@fleuret.org>
Fri, 31 Mar 2017 18:42:43 +0000 (20:42 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Fri, 31 Mar 2017 18:42:43 +0000 (20:42 +0200)
sequence_generator.cc
universe.cc
universe.h

index bfba036..cd4d313 100644 (file)
@@ -108,6 +108,9 @@ extern "C" void fl_generate_sequence(int nb_images,
     canvases[s] = new CanvasCairo(scaling, universe->width(), universe->height());
   }
 
+  scalar_t gravity_fx = 0.0;
+  scalar_t gravity_fy = 1.0;
+
   scalar_t grab_start_x, grab_start_y;
 
   int failed;
@@ -214,9 +217,12 @@ extern "C" void fl_generate_sequence(int nb_images,
       }
 
       if(s < nb_simulated_frames - 1) {
+
         // Run the simulation
+
         for(int i = 0; i < nb_iterations_per_steps; i++) {
           if(pulling) {
+            // Pulling the grabbed rectangle
             scalar_t xf = grabbed_polygon->absolute_x(grab_relative_x, grab_relative_y);
             scalar_t yf = grabbed_polygon->absolute_y(grab_relative_x, grab_relative_y);
             if (xf < 0 || xf >= world_width || yf < 0 || yf >= world_height) {
@@ -225,7 +231,9 @@ extern "C" void fl_generate_sequence(int nb_images,
             grabbed_polygon->apply_force(dt, xf, yf, 0.0, -1.0);
           } else {
             // Gravity
+            universe->apply_gravity(dt, gravity_fx, gravity_fy);
           }
+
           universe->update(dt, 1.0 / scaling);
         }
       }
@@ -234,7 +242,9 @@ extern "C" void fl_generate_sequence(int nb_images,
     total_nb_attempts++;
 
     if(total_nb_attempts >= max_total_nb_attempts) {
-      cerr << "There was " << max_total_nb_attempts << " attempts at generating the sequences." << endl;
+      cerr << "There was "
+           << max_total_nb_attempts
+           << " attempts at generating the sequences, aborting." << endl;
       abort();
     }
 
index 32e6f33..ad3ebf7 100644 (file)
@@ -159,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];
index 3537750..2758ad6 100644 (file)
@@ -58,6 +58,7 @@ public:
   // axis to speed up the computation
   void compute_pseudo_collisions(int nb_axis, int *nb_colliding_axis);
 
+  void apply_gravity(scalar_t dt, scalar_t fx, scalar_t fy);
   void apply_collision_forces(scalar_t dt);
   bool update(scalar_t dt, scalar_t padding);