Example #1
0
/** Computes a point over the line that are at x distance of a to b*/
Cpoint Cline::chunk(float d)
{
    Cpoint increment;

    //adjust();
    if (d > length) return bb;

    increment.setPolar(d, getRads());

    return (aa + increment);
}
Example #2
0
bool Cline::chunk(float d, Cpoint &p)
{
    //adjust();
    if (d > length)
    {
        p = bb;
        return false;
    }
    else
    {
        p.setPolar(d, getRads()); // increment
        p = p + aa;
        return true;
    }
}
//---------------------------------------------------------------------------------
void particleManager::update() {
    //if we are meant to be in formation


    if (ofGetFrameNum() % 4 == 0) {
        computeStatistics();
    }


    if (mode == 2) {
        if (ofRandom(0, 1) > 0.91f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            particles[pos].peakMe(1);

            ofxOscMessage msg;
            msg.setAddress("/bang");								//	bang
            msg.addStringArg("explosion");					//	handTrigger
            msg.addIntArg(4);									//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);								// centroid x
            msg.addFloatArg(y);								// centroid y


            //DAITO --- >   /bang /explosion /4 /x(noramlized) /y(noramlized)

            ofxDaito::sendCustom(msg);


        }
    }

    if (mode == 3) {
        if (ofRandom(0, 1) > 0.85f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());

            float angle = ofRandom(0, TWO_PI);
            particles[pos].directionallyPeakMe(1, angle);

            ofxOscMessage msg;
            msg.setAddress("/bang");									//	bang
            msg.addStringArg("explosionDirectional");					//	handTrigger
            msg.addIntArg(4);											//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);											// centroid x
            msg.addFloatArg(y);											// centroid y
            msg.addFloatArg(angle / TWO_PI);								// angle of explosion (0-1)


            //DAITO --- >   /bang /explosionDirectional /4 /x(noramlized) /y(noramlized) /angle

            ofxDaito::sendCustom(msg);



        }
    }

    if (mode == 4) {
        if (ofRandom(0, 1) > 0.82f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            float angle = ofRandom(0, TWO_PI);
            particles[pos].directionallyPeakMe(1, angle);
            ofxOscMessage msg;
            msg.setAddress("/bang");									//	bang
            msg.addStringArg("explosionDirectional");					//	handTrigger
            msg.addIntArg(4);											//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);											// centroid x
            msg.addFloatArg(y);											// centroid y
            msg.addFloatArg(angle / TWO_PI);								// angle of explosion (0-1)


            //DAITO --- >   /bang /explosionDirectional /4 /x(noramlized) /y(noramlized) /angle

            ofxDaito::sendCustom(msg);
        }

        if (ofRandom(0, 1) > 0.91f) {
            int pos = (int)(ofRandom(0, 0.99) * particles.size());
            particles[pos].peakMe(1);
            ofxOscMessage msg;
            msg.setAddress("/bang");								//	bang
            msg.addStringArg("explosion");					//	handTrigger
            msg.addIntArg(4);									//	SCENE 4 (?)

            float x = ofClamp(particles[pos].pos.x / OFFSCREEN_WIDTH, 0, 1);
            float y = ofClamp(particles[pos].pos.y / OFFSCREEN_HEIGHT, 0, 1);

            msg.addFloatArg(x);								// centroid x
            msg.addFloatArg(y);								// centroid y


            //DAITO --- >   /bang /explosion /4 /x(noramlized) /y(noramlized)

            ofxDaito::sendCustom(msg);
        }
    }


    if (mode != 5) {
        for (int j = 0; j < particles.size(); j ++) {
            particles[j].radius = 2 + 20 * particles[j].energy;
            particles[j].fiveEnergy *= 0.50;
        }


    } else {
        for (int j = 0; j < particles.size(); j ++) {
            particles[j].radius = 1;

            particles[j].fiveEnergy = 0.94f * particles[j].fiveEnergy + 0.06f * 1.0;
        }
    }


    if (VFs.size() == 0) {
        if (ofRandom(0, 1) > 0.16) {
            vfAdder VA;
            VFs.push_back(VA);
            VFs[VFs.size()-1].setup();
        }
    } else {

        bool bErase = false;
        if (ofGetElapsedTimef() - VFs[0].startTime > VFs[0].timeOn) {
            bErase = true;
        }
        if (bErase == true) {
            VFs.erase(VFs.begin());
        }
    }

    if (VFs.size() > 0 && ofGetFrameNum() % 4 == 0) {


        ofxOscMessage msg;
        msg.setAddress("/continuous");									//	bang
        msg.addStringArg("particlePusher");					//	handTrigger
        msg.addIntArg(4);											//	SCENE 4 (?)

        float x = ofClamp(VFs[0].point.x / OFFSCREEN_WIDTH, 0, 1);
        float y = ofClamp(VFs[0].point.y / OFFSCREEN_HEIGHT, 0, 1);

        msg.addFloatArg(x);											// centroid x
        msg.addFloatArg(y);											// centroid y

        //DAITO --- >   /continuous /particlePusher /4 /x(noramlized) /y(noramlized)

        ofxDaito::sendCustom(msg);
    }



    VF.fade(0.99f);

    for (int i = 0; i < particles.size(); i++) {

        ofxVec2f velFromVF = VF.readFromField(particles[i].pos.x / (float)OFFSCREEN_WIDTH, particles[i].pos.y / (float)OFFSCREEN_HEIGHT);

        particles[i].resetForce();
        particles[i].bitFlagW = 0;
        particles[i].bitFlagH = 0;
        computeBinPosition((int)(particles[i].pos.x), (int)(particles[i].pos.y), &particles[i].bitFlagW, &particles[i].bitFlagH);

        if (!particles[i].bBeenChosen) {
            particles[i].vel.x += velFromVF.x * 3;
            particles[i].vel.y += velFromVF.y * 3;
        }

        /*
        // get the pos from the particle system
        if(i < NUM_PARTICLES_VBO) {
        	vboPts[i][0] = particles[i].pos.x;
        	vboPts[i][1] = particles[i].pos.y;
        	vboPts[i][2] = particles[i].pos.z;

        	vboPtsSize[i] = MIN(particles[i].radius/5.0, 1.0) * maxPtsSize;


        	vboColor[i][0] = 1.0;
        	vboColor[i][1] = MIN(particles[i].radius/5.0, 1.0);
        	vboColor[i][2] = 1.0;
        	vboColor[i][3] = MIN(particles[i].radius/5.0, maxAlpha);


        }*/
    }



    //---------------------------- delauny based forces??
    Delaunay::Point tempP;
    if ( v.size() == 0) {
        for (int i = 0; i < particles.size(); i++) {
            tempP[0] = particles[i].pos.x;
            tempP[1] = particles[i].pos.y;
            v.push_back(tempP);
        }
    } else {
        for (int i = 0; i < particles.size(); i++) {
            v[i][0] = particles[i].pos.x;
            v[i][1] = particles[i].pos.y;
        }
    }
    Delaunay delobject(v);
    delobject.Triangulate();


    //------------------------------------------ peak
    if (ofGetFrameNum() % 5 == 0)
        for (Delaunay::fIterator fit  = delobject.fbegin();
                fit != delobject.fend();
                ++fit) {
            for (int i = 0; i < 3; ++i) {

                int pta = delobject.Org(fit);
                int ptb = delobject.Sym(fit, i);
                if (ptb != -1) {
                    if (particles[pta].bBeenPeaked) {
                        particles[ptb].peakMe(particles[pta].energy * 0.86f);
                        if (i == 2) particles[pta].bBeenPeaked = false;
                    }
                }
            }
        }


    if (ofGetFrameNum() % 2 == 0)
        for (Delaunay::fIterator fit  = delobject.fbegin();
                fit != delobject.fend();
                ++fit) {

            int pta = delobject.Org(fit);

            if (particles[pta].bBeenDirectionallyPeaked) {

                float angle = particles[pta].direction;

                int minIndex = -1;
                float minAngle = 10000;
                for (int i = 0; i < 3; ++i) {

                    int ptb = delobject.Sym(fit, i);
                    if (ptb != -1) {

                        float angleB = atan2( particles[ptb].pos.y -  particles[pta].pos.y, particles[ptb].pos.x -  particles[pta].pos.x);
                        float diffAngle = angle - angleB;
                        if (diffAngle < -PI) diffAngle += TWO_PI;
                        if (diffAngle > PI) diffAngle -= TWO_PI;
                        if (fabs(diffAngle) < minAngle) {
                            minAngle = fabs(diffAngle);
                            minIndex = delobject.Sym(fit, i);;
                        }

                    }
                }

                particles[pta].bBeenDirectionallyPeaked = false;

                if (minIndex != -1) {
                    particles[minIndex].directionallyPeakMe(particles[pta].energy*0.96, angle);
                }


            }
        }






    for (Delaunay::fIterator fit  = delobject.fbegin();
            fit != delobject.fend();
            ++fit) {
        for (int i = 0; i < 3; ++i) {

            int pta = delobject.Org(fit);
            int ptb = delobject.Sym(fit, i);
            if (ptb != -1) {
                if (!(particles[pta].bBeenChosen && particles[ptb].bBeenChosen)) {

                    bool bAnyArrow = particles[ptb].bBeenChosen || particles[ptb].bBeenChosen;

                    float radius = particles[pta].radius + particles[ptb].radius;

                    if (mode != 5) radius *= 2.5;


                    float distance = (particles[pta].pos - particles[ptb].pos).length();

                    if (!bAnyArrow) {
                        if ( distance < radius) {
                            if (mode != 5) particles[pta].addRepulsionForce(particles[ptb], radius, 0.1f);
                            else particles[pta].addRepulsionForce(particles[ptb], radius, 0.026f);
                        }
                        if ( distance < 100)  particles[pta].addAttractionForce(particles[ptb], 100, 0.001f);
                    } else {
                        if ( distance < 33) particles[pta].addRepulsionForce(particles[ptb], 33, 0.2f);
                    }


                }
            }
        }
    }
    for (int i = 0; i < particles.size(); i++) {

        if (mode == 4) {
            if (!particles[i].bBeenChosen) particles[i].addAttractionForce(
                    OFFSCREEN_WIDTH / 2, OFFSCREEN_HEIGHT / 2 + OFFSCREEN_HEIGHT / 4, 6000, 0.008);
        } else {
            if (mode != 5) {
                if (!particles[i].bBeenChosen) particles[i].addAttractionForce(
                        OFFSCREEN_WIDTH / 2, OFFSCREEN_HEIGHT / 2 + OFFSCREEN_HEIGHT / 4, 6000, 0.003);
            } else {
                particles[i].addAttractionForce( particles[i].lockTarget.x, particles[i].lockTarget.y, 6000, 0.06); //0.2f -0.2*sin(ofGetElapsedTimef()));
                //cout << particles[i].lockTarget.x <<  " " <<  particles[i].lockTarget.y << endl;

            }
        }

    }



    // some perlin forces:


    if (mode == 1) {
        for (int i = 0; i < particles.size(); i++) {
            if (!particles[i].bBeenChosen) {

                float xyRads = getRads(particles[i].pos.x / 3.0f, particles[i].pos.y / 3.0f, ofGetElapsedTimef() / 100, 10.f, 15.f);
                //float yRads = getRads(xLoc, yLoc, 10.f, 15.f);

                particles[i].addForce( cos(xyRads) * .05, -sin(xyRads) * .05);
            }
        }
    }

    for (int i = 0; i < particles.size(); i++) {


        /*for(int j = 0; j < i; j++){
        if (particles[i].bInSameBin(particles[j])){

        if (particles[i].bBeenChosen && particles[j].bBeenChosen) continue;

        if (particles[i].bBeenChosen || particles[j].bBeenChosen)  particles[i].addRepulsionForce(particles[j], 60, 0.8f);
        else particles[i].addRepulsionForce(particles[j], 20, 0.2f);
        particles[i].addAttractionForce(particles[j], 100, 0.0001f);
        }
        }*/
        particles[i].addDampingForce();
        particles[i].update();
        particles[i].update();
        if (ofGetFrameRate() < 22) particles[i].update();

    }

    for (int i = 0; i < particles.size(); i++) {

    }

    for (int i = 0; i < VFs.size(); i++) {
        VFs[i].update();
    }


    for (int i = 0; i < VFs.size(); i++) {

        if (mode != 5) {
            VF.addIntoField( (VFs[i].point.x) / (float)OFFSCREEN_WIDTH, VFs[i].point.y / (float)OFFSCREEN_HEIGHT, VFs[i].diffPoint*0.001  , 0.093 * 1.6);
        }
    }

}