コード例 #1
0
// ----------------------------------------------------
void CellScene::keyPressed(int key) {
    switch (key) { 
        case ' ': {
                addCells();
                break;
            }    
        case 'r': {
            for (vector<CellNode>::iterator it=cells.begin(); it!=cells.end(); ++it) {
                it->radius = ofRandom(10, separationDistance);
            }    
            break;
            }
        case 'b': {
            bgColorTarget = ofRandomColor();
            break;
        }
        
        case 'g': {
            mustDrawGui = !mustDrawGui;
            break;
        }
        default:{
            break;
        }
	}  
}
コード例 #2
0
ファイル: cells.cpp プロジェクト: subratv/DynamO
  void
  GCells::reinitialise()
  {
    GNeighbourList::reinitialise();
      
    dout << "Reinitialising on collision " << Sim->eventCount << std::endl;

    //Create the cells
    addCells((_maxInteractionRange 
	      * (1.0 + 10 * std::numeric_limits<double>::epsilon()))
	     * _oversizeCells / overlink);

    BOOST_FOREACH(const initSlot& nbs, sigReInitNotify)
      nbs.second();

    if (isUsedInScheduler)
      Sim->ptrScheduler->initialise();
  }
コード例 #3
0
ファイル: ship.cpp プロジェクト: npo6ka/OPP
Ship4::Ship4 (list <shared_ptr<GameBoardCell>> bufCells): Ship() {
    addCells(bufCells);
}
コード例 #4
0
// ----------------------------------------------------
void CellScene::update() {
    
    // reset the forces & remove deads
    for (vector<CellNode>::iterator it=cells.begin(); it!=cells.end(); ++it) {
        it->frc = 0;
        it->bRemove = isPointInScreen(it->pos, 100) == false;
    }
    ofRemove(cells, shouldRemove);
    
    
    float t = ofGetElapsedTimef()*0.02;
    
    ofVec2f dirVec = 0;    
    for(int i=0; i<4; i++) {
        
        float amp = audioPtr->getVolume(i) * 10.0;
        
        if(i == AudioManager::TOP) {
            dirVec.y -= amp;
        }
        else if(i == AudioManager::BOTTOM) {
             dirVec.y += amp;
        }
        else if(i == AudioManager::LEFT) {
             dirVec.x -= amp;
        }
        else if(i == AudioManager::RIGHT) {
             dirVec.x += amp;
        }
        
    }
    
    dirVec *= 100;
    //printf("%f %f\n", dirVec.x, dirVec.y);
    
    for (vector<CellNode>::iterator itA=cells.begin(); itA!=cells.end(); ++itA) {
        
        ofVec2f pos = itA->pos;
        float frwX  = ofNoise(pos.x * 0.003, pos.y * 0.006, ofGetElapsedTimef() * 0.6);
        
        ofVec2f noiseFrc;
     	noiseFrc.x = ofSignedNoise(t, pos.y * 0.04) * 0.6;
		noiseFrc.y = ofSignedNoise(itA->uniquef, pos.x * 0.006, t);
        noiseFrc *= damping;
        
        ofVec2f sepFrc = 0;
        for (vector<CellNode>::iterator itB = itA; itB!=cells.end(); ++itB) {
            if (itA==itB) continue;
            ofVec2f v = itA->pos - itB->pos;
            float   d = v.length();
            float minRad = separationDistance + (itA->radius+itB->radius);
            if(d < minRad) {
                v.normalize();
                sepFrc += v;
            }
        }
        sepFrc.normalize();
        //sepFrc.limit(1.9);
        
        
        
        // add forces
        itA->frc += noiseFrc;
        itA->frc += sepFrc;
        
        itA->frc += dirVec;
        
        itA->frc.limit(maxParticleSpeed);
        
        // applu the forces
		itA->vel *= itA->drag; 
		itA->vel += itA->frc;
        itA->pos += itA->vel;
        
        // wrap the screen
        //itA->wrapScreen(-200, -200, CUBE_SCREEN_WIDTH+400, CUBE_SCREEN_HEIGHT+400);
    }
    
    
    // voronoi up this scene
    if(cells.size() > 0) {
        
      
        voronoi.clear();

        voronoi.put(0, 0, 0);
        voronoi.put(1, 1, 0);
        voronoi.put(2, 1, 1);
        voronoi.put(3, 0, 1);
        
        int inc = 4;
        for (vector<CellNode>::iterator it=cells.begin(); it!=cells.end(); ++it) {
            voronoi.put(inc, it->pos.x/(float)CUBE_SCREEN_WIDTH, it->pos.y/(float)CUBE_SCREEN_HEIGHT);
            inc ++;
            
            //cout << "i:" << inc << " x:" << it->pos.x << " y:" << it->pos.y << endl;
        }
    }
    
    
    // add some more
    int nRelease = MAX(1, 50 * releaseRate);
    for(int i=0; i<nRelease; i++) {
        addCells();
    }
}