Esempio n. 1
0
int main (int argc, char * argv[]) {
  bool restart;
  unsigned long int particles_n;

  if (argc < 2) {
    particles_n = NUMBER_OF_PARTICLES;
  } else {
    errno = 0;

    particles_n = strtoul(argv[1], NULL, 0);

    if (errno) {
      perror(__func__);
      exit(EXIT_FAILURE);
    }
  }

  n = particles_n;

  px =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);
  py =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  vx =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);
  vy =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  m  =
    align_padded_malloc(ALIGN_BOUNDARY, n*sizeof(value), ALLOC_PADDING);

  if (px == NULL || py == NULL ||
      vx == NULL || vy == NULL || m == NULL) {
    perror("main");
    exit(EXIT_FAILURE);
  }

  draw_init(SCREEN_WIDTH, SCREEN_HEIGHT, FRAME_RATE, n);
  physics_init(n);
  rng_init();

  do {
    draw_reset(n);
    physics_reset(n);
    restart = main_loop();
  } while (restart);

  rng_free();
  physics_free();
  draw_free();

  align_free(m);
  align_free(vy);
  align_free(vx);
  align_free(py);
  align_free(px);

  exit(EXIT_SUCCESS);
}
Esempio n. 2
0
 /** Called for GLFW_PRESSED and GLFW_REPEAT */
 void on_key_pressed( int key, int action ) 
 {
   
   //std::cout << "GLWindow::key_pressed key=" << key << std::endl;
   if( key == GLFW_KEY_R and action == GLFW_PRESS ) {
     // toggle _is_running
     _physics_running = !_physics_running;
   }
   else if( key == GLFW_KEY_E and action == GLFW_PRESS ) {
     // stop and reset
     _physics_running = false;
     physics_reset();
   }
 }
Esempio n. 3
0
  // ********************************************* GLBoidsScreen::physics_init
  void physics_init()
  {
    _physics_eng = new physics::Engine( false /* no gravity */ );

    _boid_list.clear();
    auto pt = BoidBodyPtr( new BoidBody() );
    _physics_eng->_bodies.push_back( pt );
    _boid_list.push_back( pt );

    pt = BoidBodyPtr( new BoidBody() );
    _physics_eng->_bodies.push_back( pt );
    _boid_list.push_back( pt );

    physics_reset();
  }