MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    m_ui(new Ui::MainWindow)
{
    m_ui->setupUi(this);
    m_gl=new GLWindow(this);
    m_ui->s_mainwindowgridlayout->addWidget(m_gl,0,0,2,1);
    connect(m_ui->m_wireframe,SIGNAL(toggled(bool)),m_gl,SLOT(toggleWireframe(bool)));
    connect(m_ui->m_animateBoids ,SIGNAL(toggled(bool)),m_gl,SLOT(toggleBoidAnimation(bool)));
    connect(m_ui->m_animateGoal ,SIGNAL(toggled(bool)),m_gl,SLOT(toggleGoalAnimation(bool)));
    connect(m_ui->m_mass,SIGNAL(valueChanged(double)),m_gl,SLOT(setMass(double)));
    connect(m_ui->m_speed,SIGNAL(valueChanged(double)),m_gl,SLOT(setMaxSpeed(double)));
    connect(m_ui->m_force,SIGNAL(valueChanged(double)),m_gl,SLOT(setMaxForce(double)));
    connect(m_ui->m_seperation,SIGNAL(valueChanged(double)),m_gl,SLOT(setSepDist(double)));
    connect(m_ui->m_cohesion,SIGNAL(valueChanged(double)),m_gl,SLOT(setCohDist(double)));
    connect(m_ui->m_alignment,SIGNAL(valueChanged(double)),m_gl,SLOT(setAliDist(double)));
    connect(m_ui->m_addBoid,SIGNAL(pressed()),m_gl,SLOT(addBoid()));
    connect(m_ui->m_removeBoid,SIGNAL(pressed()),m_gl,SLOT(removeBoid()));

    connect(m_ui->m_goalInfluence,SIGNAL(sliderMoved(int)),m_gl,SLOT(setGoalInf(int)));
    connect(m_ui->m_resetGoals,SIGNAL(pressed()),m_gl,SLOT(resetGoals()));

    connect(m_ui->m_record ,SIGNAL(toggled(bool)),m_gl,SLOT(toggleRecord(bool)));

}
int GLWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0:
            toggleWireframe((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 1:
            toggleBoidAnimation((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 2:
            toggleGoalAnimation((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 3:
            toggleRecord((*reinterpret_cast< bool(*)>(_a[1])));
            break;
        case 4:
            setMass((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 5:
            setMaxSpeed((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 6:
            setMaxForce((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 7:
            setSepDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 8:
            setCohDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 9:
            setAliDist((*reinterpret_cast< double(*)>(_a[1])));
            break;
        case 10:
            setGoalInf((*reinterpret_cast< int(*)>(_a[1])));
            break;
        case 11:
            removeBoid();
            break;
        case 12:
            addBoid();
            break;
        case 13:
            resetGoals();
            break;
        default:
            ;
        }
        _id -= 14;
    }
    return _id;
}
示例#3
0
int Flocking::update()
{
    int i;
    Vec2f centroid(0,0);
    for(i = 0; i < boids.size(); i++)
    {
    	centroid+=boids[i].loc;

        if(boids[i].isHit(destination.x,destination.y,destinationArea))
        {
            boids[i].reachedDestination = true;
        }

        if(useCollisionFromSDF)
        {
            Vec2f dir = partialDerivaties[(int)boids[i].loc.x][(int)boids[i].loc.y];

            float val = collisionSDF[(int)boids[i].loc.x][(int)boids[i].loc.y];
            
            if(val==0)
            	val=0.001;

			boids[i].seek(dir+boids[i].loc,dir.length()*collisionWeight/val);

        }

	
        if(sceneMap->getCell(boids[i].loc.x,boids[i].loc.y))
        {
        /*	
            vector<Vec2f> path;
            path = pathFinder.getPath(sceneMap,boids[i].loc);
            if(path.size()>1)
            {
                Vec2f dest = path[min((int)path.size()-1,10)]; //!@#
                boids[i].seek(dest,destWeight); //seek the Goal !@#
            }
	*/		

            
        }
        else
        {
            boids[i].hitObstacle = true;
        }


        //boids[i].seek(destinationSeek,destWeight); //seek the Goal !@#
	       boids[i].seek(destination,destWeight); //seek the Goal !@#
        boids[i].update(boids);

        if(boids[i].reachedDestination)
            removeBoid(boids[i].loc.x,boids[i].loc.y,1);  //ineffcient way to remove boids

    }

    centroid /=flockSize();

    /*
    if(sceneMap->getCell(centroid.x,centroid.y))
    	{
        	
            vector<Vec2f> path;
            path = pathFinder.getPath(sceneMap,centroid);
            if(path.size()>1)
            {
                destinationSeek = path[min((int)path.size()-1,5)]; 
                
            }
			

            
        }
*/
        

    if(flockSize()==0)
        return 0;
    else
        return 1;
}