Пример #1
0
void MainWindow::on_btn_start_clicked()
{
    rsim->reset();
    scene->clear();
    graphicalInit();
    ui->liste_tributs_1->clear();
    ui->liste_tributs_2->clear();
    g_billes.clear();
    photos_g.clear();
    outlight_g.clear();

    int n = ui->nbilles_dial->value();

    for(int i=0;i<n;i++) {
        if(i%2 == 0) {
            ui->liste_tributs_1->addItem("Palmer?");
        } else if(i%2 == 1) {
            ui->liste_tributs_2->addItem("Palmer?");
        }
    }

    rsim->start(n);
    QVector<b2Body*> b=rsim->getBalls();

    for(int i=0;i<b.size();i++) {
        QGraphicsEllipseItem* g_bille = scene->addEllipse(-10,-10,35,35,QPen(), QBrush(QColor(200,86,23)));
        g_billes.append(g_bille);

        QGraphicsPixmapItem* p = scene->addPixmap(unknown);

        if(n<= 12) {
            p->setScale(0.5f);

            int total_height = (ceil(b.size()/2.0))*150+40;
            p->setPos(i%2==0? -540 : 520-100, -total_height/2+(i/2)*150);
        } else {
            float scale = 0.5*12/(float)n;
            p->setScale(scale);

            float height = 150*12/(float) n;
            int total_height = (ceil(b.size()/2.0))*height+40;
            p->setPos(i%2==0? -540 : 520-100*12/(float)n, -total_height/2+(i/2)*height);

        }
        photos_g.append(p);

        QVector<QPointF> points;
        points.append(QPointF(0,0));
        points.append(QPointF(1500,0));
        points.append(QPointF(1500*cos(1/48.0*2*3.14159),1500*sin(1/48.0*2*3.14159)));

        QGraphicsPolygonItem* outlight = scene->addPolygon(QPolygonF(points),QPen(QColor(255,255,255,128)),QBrush(QColor(255,192+(rand()%64 - 32),0,96)));
        outlight->setZValue(-1);
        outlight->setTransformOriginPoint(QPointF(0,0));
        outlight->setVisible(false);
        outlight_g.append(outlight);

    }

}
void
rce::gui::RImageMarkerScene::
setAllPolygonsVisible(bool value)
{
    for(auto it = polygonItems_.begin();
        it != polygonItems_.end();
        ++it)
    {
        QGraphicsPolygonItem *item = it.value();
        item->setVisible(value);
    }
}
Пример #3
0
void cbSimulator::showGraph(int id)
{
    unsigned int w,c;
    QGraphicsPolygonItem *wallCanvas;
    QGraphicsRectItem *grCanvas;

	if(id<1 || id > (int)robots.size()) {
		cerr << "Cannot show graph of robot " << id << "\n";
		return;
	}

	labCanvasWidth=(int)(lab->Width()*30);
	labCanvasHeight=(int)(lab->Height()*30);

    labScene=new QGraphicsScene(0, 0, labCanvasWidth,labCanvasHeight);

    labView=new cbGraphView(labScene,this);
    labView->viewport()->setMouseTracking(true);

    QPolygon *pa;

    for(w=1; w<lab->nWalls();w++) {
        vector<cbPoint> &corners=lab->Wall(w)->Corners();
        //pa.resize(corners.size());
        pa = new QPolygon(corners.size());
        for(c=0; c<corners.size();c++)
            pa->setPoint(c,(int)(corners[c].X()*labCanvasWidth/lab->Width()),
                         (int)(labCanvasHeight-corners[c].Y()*labCanvasHeight/lab->Height()) );
        wallCanvas = new QGraphicsPolygonItem(0, labScene);
        wallCanvas->setPolygon(*pa);
        wallCanvas->setBrush(QBrush(Qt::black));
		wallCanvas->setVisible(true);
	}


	unsigned int x,y;
	double distMax=0.0;

	//grAux=graph;  Tentativa de optimizacao
	for(x = 0; x < GRIDSIZE; x++)
	    for(y = 0; y < GRIDSIZE; y++) {
		    *grAux=*graph;

		    //grAux->resetInitState();  Tentativa de optimizacao - testes indicam que fica muito mais lento!!
		    //grAux->writeGraph();

		    cbPoint p((0.5+x)*lab->Width()/GRIDSIZE, (GRIDSIZE-0.5-y)*lab->Height()/GRIDSIZE);
		    grAux->addFinalPoint(id,p);
		    distGrid[x][y]=grAux->dist(id);
		    if(distGrid[x][y] < 2000 && distGrid[x][y]>distMax)
			    distMax=distGrid[x][y];
	    }

//        fprintf(stderr,"distmax=%f labCanvasWidth=%d labCanvasHeight=%d\n",
//			 distMax,labCanvasWidth,labCanvasHeight);

	for(x = 0; x < GRIDSIZE; x++)
	    for(y = 0; y < GRIDSIZE; y++) {

            if(distGrid[x][y]<2000) {
                grCanvas = new QGraphicsRectItem(x*labCanvasWidth/GRIDSIZE,y*labCanvasHeight/GRIDSIZE,
                                                 (x+1)*labCanvasWidth/GRIDSIZE - x*labCanvasWidth/GRIDSIZE,
                                                 (y+1)*labCanvasHeight/GRIDSIZE -y*labCanvasHeight/GRIDSIZE,
                                                 0, labScene);
                QColor color((int)(0+distGrid[x][y]/distMax*250),
                             (int)(0+distGrid[x][y]/distMax*250),
                             (int)(0+distGrid[x][y]/distMax*250));
                grCanvas->setBrush(QBrush(color));
                grCanvas->setPen(QPen(color));
			    grCanvas->setVisible(true);
			    //debug
			    //distGrid[x][y]=(int)(0+distGrid[x][y]/distMax*250);
		    }

        }
    labScene->update();

}