int main(int argc, char *argv[]) { QApplication a(argc, argv); QImage texture("pics/nana.jpg"); if (texture.isNull()) { qDebug() << "Couldn't read the default texture. Shadow building, but forgot to set the run directory?"; return 0; } QPixmap *canvas = new QPixmap(texture.width(), texture.height()); QGraphicsScene scene; scene.setItemIndexMethod(QGraphicsScene::NoIndex); Boids boids(&scene, canvas, &texture); SettingsPanel settings; settings.move(1250, 200); BoidsView view(canvas); QGLWidget* viewport = new QGLWidget(); view.setViewport(viewport); view.setOptimizationFlag(QGraphicsView::DontSavePainterState); view.setAutoFillBackground(false); view.setGeometry(50, 100, texture.width(), texture.height()); view.setScene(&scene); view.setSceneRect(-view.width() / 2, -view.height() / 2, view.width(), view.height()); view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view.setWindowTitle("Boids"); QObject::connect(&view, SIGNAL(mousePositionChanged(float,float)), &boids, SLOT(setTargetLocation(float,float))); QObject::connect(&view, SIGNAL(enableSimulation(bool)), &boids, SLOT(enableSimulation(bool))); QObject::connect(&settings, SIGNAL(boidCountChanged(int)), &boids, SLOT(setBoidCount(int))); QObject::connect(&settings, SIGNAL(trailOpacityChanged(int)), &boids, SLOT(setTrailOpacity(int))); QObject::connect(&settings, SIGNAL(textureChanged(QString)), &boids, SLOT(loadTexture(QString))); QObject::connect(&settings, SIGNAL(clearCanvas()), &boids, SLOT(clearCanvas())); QObject::connect(&settings, SIGNAL(saveCanvas(QString)), &boids, SLOT(saveCanvas(QString))); QObject::connect(&settings, SIGNAL(colorEvolutionRateChanged(int)), &boids, SLOT(setColorEvolutionRate(int))); QObject::connect(&settings, SIGNAL(coloringModeChanged(Boids::ColoringMode)), &boids, SLOT(setColoringMode(Boids::ColoringMode))); QObject::connect(&boids, SIGNAL(canvasChanged(QPixmap*)), &view, SLOT(canvasChanged(QPixmap*))); QObject::connect(&settings, SIGNAL(maximumSpeedChanged(int)), &boids, SLOT(setMaxBoidSpeed(int))); QObject::connect(&settings, SIGNAL(minimumDistanceChanged(int)), &boids, SLOT(setMinimumDistance(int))); QObject::connect(&settings, SIGNAL(inertiaChanged(int)), &boids, SLOT(setInertia(int))); boids.setBoidCount(settings.boidCount()); boids.setColorEvolutionRate(settings.colorEvolutionRate()); boids.setColoringMode(settings.coloringMode()); boids.setTrailOpacity(settings.trailOpacity()); boids.setMaxBoidSpeed(settings.maximumSpeed()); boids.setMinimumDistance(settings.minimumDistance()); boids.setInertia(settings.inertia()); view.show(); settings.show(); return a.exec(); }
// =========================================================================== // The Main // =========================================================================== int main(int argc, char* argv[]) { srand(time(NULL)); boids Boids = boids(); individue Individue = individue(); //parameter //=============================================================== Boids.Set_dt(0.1); //0.001 Boids.Set_population(100); //100 Boids.Set_disti(60); Boids.Set_distc(10); Boids.Set_distp(40); Boids.Set_distk(5); Boids.Set_g1(5); //5 Boids.Set_g2(1); //1 Boids.Set_g3(35); //35 Boids.Set_g4(10); Boids.Set_nb_object(0); Boids.Set_width(700); Boids.Set_height(700); Boids.Set_speed_init(10); //10 Boids.Set_nb_predator(1); Boids.Set_speed_predator(50); Boids.Set_wait(50); Boids.Set_wind_force(10); Boids.Set_speed_limit(200); //initialisation //============================================================== int w = Boids.Get_width(); int h = Boids.Get_height(); bwindow win(w,h); printf("%d\n",win.init()); win.map(); Boids.initialization(); int nbo = Boids.Get_nb_object(); double* tabo = Boids.Get_tab_object(); individue* tabp = Boids.Get_predator(); int nbp = Boids.Get_nb_predator(); individue* tab = Boids.Get_tab(); //inifinite loop //============================================================ for (;;) { int ev = win.parse_event(); switch(ev) { case BKPRESS : printf("keypressed\n"); printf("key : %s\n",win.get_lastkey()); break; case BBPRESS: printf("buttonpressed\n"); break; case BEXPOSE: printf("expose\n"); break; case BCONFIGURE: printf("configure\n"); break; } int pop = Boids.Get_population(); //for the object win.draw_fsquare(0,0,w,h,0xFFFFFF); for (int i = 0; i < nbo; i++) { win.draw_fsquare(-2+tabo[2*i],-2+tabo[2*i+1],2+tabo[2*i],2+tabo[2*i+1],0x0000FF); } //for the population for (int i = 0; i < pop; ++i) { double x = tab[i].Get_x(); double y = tab[i].Get_y(); win.draw_fsquare(-1+x,-1+y,1+x,1+y,0xFF0000); } //for the predator for (int i = 0; i < nbp; ++i) { double x = tabp[i].Get_x(); double y = tabp[i].Get_y(); win.draw_fsquare(-2+x,-2+y,2+x,2+y,0x00FF00); } Boids.deplacement(); usleep(100000); //100000 } // Boids.initialization(); // individue* t = Boids.Get_tab(); // for (int i = 0; i < pop; ++i) // { // printf("%lg %lg %lg %lg\n", t[i].Get_x(),t[i].Get_y(),t[i].Get_vx(),t[i].Get_vy()); // } // printf("\n"); // for (int i = 0; i < 7; ++i) // { // Boids.deplacement(); // for (int i = 0; i < pop; ++i) // { // printf("%lg %lg %lg %lg\n", t[i].Get_x(),t[i].Get_y(),t[i].Get_vx(),t[i].Get_vy()); // } // printf("\n"); // } return 0; }