Added gravity.
[universe.git] / universe.cc
index 55e1a6d..8dec7f5 100644 (file)
@@ -16,11 +16,11 @@ Universe::Universe(int nb_max_polygons,
 }
 
 Universe::~Universe() {
-  for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) delete _polygons[n];
+  clear();
   delete[] _polygons;
 }
 
-void Universe::initialize(Polygon *p) {
+void Universe::initialize_polygon(Polygon *p) {
   p->initialize(_nb_max_polygons);
 }
 
@@ -118,6 +118,7 @@ Polygon *Universe::pick_polygon(scalar_t x, scalar_t y) {
   return 0;
 }
 
+#ifdef XFIG_SUPPORT
 void Universe::print_xfig(XFigTracer *tracer) {
   for(int n = 0; n < _nb_polygons; n++) {
     if(_polygons[n]) {
@@ -130,6 +131,7 @@ void Universe::print_xfig(XFigTracer *tracer) {
     }
   }
 }
+#endif
 
 #ifdef X11_SUPPORT
 void Universe::draw(SimpleWindow *window) {
@@ -161,6 +163,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];