Пример #1
0
void SpringStroke::addPoint(float x, float y)
{
    line->addPoint(x, y);
    
    vector<Particle*> particles = line->getPoints();
    int newIndex = particles.size()-1;
    Particle* newPar = particles[newIndex];
    if (newIndex > 0) {
        Spring *s = new Spring();
        Particle *prevPar = particles[newIndex-1];
        s->setup(prevPar, newPar);
        springs.push_back(s);
        
        // lock particle if close to previous one
        if ((*prevPar - *newPar).length() < lockDistance) {
            newPar->stickiness = 100;
//            newPar->locked = true;
        }
        
    }
    else {
        newPar->stickiness = 100;
//        newPar->locked = true;
    }
}
Пример #2
0
void wave::setupSpring(){
    points.clear();
    springs.clear();
    for (int i = 0; i < amount; i++) {
        Spring spring;
        spring.setup( strength, restLength, invMass);
        springs.push_back( spring );
        
        Point_ point;
        
        float step = width/(amount*1.0-1.0);
        
        ofVec2f pos(i*step , ypos);
        
        point.p = pos;
        point.pp = pos;
        if(i == 0 || i == amount-1 ){
            point.isFixed = true;
        }else{
            point.isFixed = false;
        }
        points.push_back(point);
    }
}
Пример #3
0
void Demo::setupVerlet() {
    
    physic.integrator = new Verlet();
    
    mouse.setMass(10);
    
    //add gravity
    physic.vBehaviour.push_back(&force);
    
    // add integrator
    physic.integrator = new Verlet();
    
    //weave particles
    NUM_PARTICLES = CLOTH_ROW * CLOTH_COLS;
    physic.particles = new Particle[NUM_PARTICLES];
    
    short sx = (ofGetWindowWidth() - (CLOTH_COLS * CLOTH_SIZE)) * 0.5;
    short sy = (ofGetWindowHeight() - (CLOTH_ROW * CLOTH_SIZE)) * 0.5;
    
    short x, y, count = 0;
    
    
    // add vector for the verlet
    vector< vector<Particle> > vParticle;
    
    for (x = 0; x < CLOTH_COLS; x++) {
        
        vector<Particle> row;
        
        for (y = 0; y < CLOTH_ROW; y++) {
            
            
            physic.particles[count].fixed = (y == 0) ? true : false;
            
            physic.particles[count].pos = new Vector();
            physic.particles[count].acc = new Vector();
            physic.particles[count].vel = new Vector();
            
            physic.particles[count].moveTo(
                (sx + x * CLOTH_SIZE),
                (sy + y * CLOTH_SIZE)
           );
            
            physic.particles[count].setRadius(DOT_SIZE);
            physic.particles[count].setMass(10);
            
            row.push_back(physic.particles[count]);
            
            count++;
            
        }
        
        vParticle.push_back(row);
        
    }
    
    count = 0;
    
    //cout << vParticle.size() << " " << vParticle[0].size() << endl;
    
    for (x = 0; x < vParticle.size(); x++) {
        
        for (y = 0; y < vParticle[x].size(); y++) {
            
            if (x > 0) {
                
                Spring spring;
                
                spring.setup(
                    physic.particles[count],
                    vParticle[x-1][y],
                    CLOTH_SIZE,
                    0.5
                );
                
                physic.vSpring.push_back(spring);
                
            }
            
            if (y > 0) {
                
                Spring spring;
                
                spring.setup(
                              physic.particles[count],
                              vParticle[x][y-1],
                              CLOTH_SIZE,
                              0.5
                              );

                physic.vSpring.push_back(spring);                
            }
            
            count++;
            
            
        }
    }
        
    Spring spring;
    
    spring.setup(mouse, vParticle[CLOTH_COLS/2][CLOTH_ROW/2], 4, 4);
    physic.vSpring.push_back(spring);
    
    //vParticle[0][0].fixed = true;
//    vParticle[CLOTH_COLS - 1][0].fixed = true;
    

}