예제 #1
0
Node::Node(MToken *m) {
    setup(m->inputInfo, m->outputInfo, m->iconData, m->iconSize);
    nID = m->tID;
    mtkn = m;
    module.loadImage(ofBuffer(m->iconData, m->iconSize));
    resizeIcon(60);
}
예제 #2
0
void Node::nodeBig(MToken *m) {
    setup(m->inputInfo, m->outputInfo, m->iconData, m->iconSize);
    nID = m->tID;
    mtkn = m;
    x = 0;
    y = 0;
    radius *= 3;
    module.loadImage(ofBuffer(m->iconData, m->iconSize));
    resizeIcon(60*3);
}
예제 #3
0
void gpuPictoString::update(){

    float w = testApp::getInstance()->getW();
    float h = testApp::getInstance()->getH();
    
    if(bNeedUpdateCharPos){
        charPosList = calcCharPos();
        bNeedUpdateCharPos = false;
    }
    
    int total = gpuPicto::totalPicto;
    int totalPix = textureRes*textureRes;
    
    // manual mipmap
    //                              *** should check icon size
    
    resizeIcon(h);
    int iconSize = prm.iconSize * h;
    iconSize*=0.5;
    if(iconSize<1){ iconSize=1; }
    

    
    //
    //  nomad
    //
    bool bNomad = true;
    if(bNomad){
        if(total>0 && ofRandom(1.0)>0.95){
            
            if(gpchars.size()>2){
                int charIndexA = (int)ofRandom(2, gpchars.size()-2);
                int charIndexB = charIndexA + (int)ofRandom(-2, 2);
            
                if(charIndexA!=charIndexB){
                    int numPictoA = gpchars[charIndexA]->numPicto;
                    int numPictoB = gpchars[charIndexB]->numPicto;
                    int firstIdA = gpchars[charIndexA]->firstIndex;
                    int firstIdB = gpchars[charIndexB]->firstIndex;
                    
                    int indexA = ofRandom(firstIdA, numPictoA-1);
                    int indexB = ofRandom(firstIdB, numPictoB-1);
                    
                    float attractOnA = springPrmData[indexA*4+3];
                    float attractOnB = springPrmData[indexB*4+3];
                    
                    if(attractOnA<0 && attractOnB<0){
                        float Ax = finalTargetPosData[indexA*3 + 0];
                        float Ay = finalTargetPosData[indexA*3 + 1];
                        
                        finalTargetPosData[indexA*3 + 0] = finalTargetPosData[indexB*3 + 0];
                        finalTargetPosData[indexA*3 + 1] = finalTargetPosData[indexB*3 + 1];

                        finalTargetPosData[indexB*3 + 0] = Ax;
                        finalTargetPosData[indexB*3 + 1] = Ay;

                        finalTargetTex.loadData(finalTargetPosData, textureRes, textureRes, GL_RGB);
                    }
                }
            }
        }
    }
    
    
    {
//        offset = attractor::getPos();
        
        const ofVec2f& attr = attractor::getPos();
        float K = 20;
        float maxSpeed = 0.05;

        ofVec2f dir = attr - offset;
        ofVec2f acc =  K * 0.000167 * dir;
        offsetVel += acc;
        
        offsetVel.limit(maxSpeed);
        offset += offsetVel;
        
        ofVec2f dirf = attr - offset;
        if(dirf.length() > 0.1){
            offset += dirf - dirf.normalized() * 0.1;
        }
    }
    
    //
    //  check pictoChar
    //
    bool shouldUpdateSpringTexture = false;
    GPICTO_STR_ITR itr = gpchars.begin();
    int particleMax = textureRes*textureRes;
    for(; itr!=gpchars.end(); itr++){
        
        if((*itr)->update()){
            shouldUpdateSpringTexture = true;
            int index = (*itr)->firstIndex;
            int numPicto = (*itr)->numPicto;

            if(index<=particleMax){

                for(int i=0; i<numPicto; i++){
                    springPrmData[index*4 + 3] = -1;    // attractOn
                    
                    index++;
                    if(index>particleMax){
                        index = 0;
                    }
                }
            }
        }
    }
    
    if(clearCheck()){
        clearAll();
        bNeedUpdateCharPos = true;
    }

    if(testApp::gprm.bAutoPlay)
        shouldStartNextCheck();

    if(shouldUpdateSpringTexture){
        springPrmTex.loadData(springPrmData, textureRes, textureRes, GL_RGBA);
    }
    
    
    //
    // make random tex
    //
//    if(ofGetFrameNum()%3 == 0){
        for(int index=0; index<total; index++){
                randomData[index*3 + 0] = ofRandom(1.0);
                randomData[index*3 + 1] = ofRandom(1.0);
                randomData[index*3 + 2] = ofRandom(1.0);
//                randomData[index*4 + 3] = ofRandom(1.0);
        }
        randomTex.loadData(randomData, textureRes, textureRes, GL_RGB);
//    }


    //
    // 1. calc vel
    //
    velPingPong.dst->begin();{
        ofClear(0);
        updateVel.begin();{
            updateVel.setUniformTexture("backbuffer", velPingPong.src->getTextureReference(), 0);
            updateVel.setUniformTexture("posData", posPingPong.src->getTextureReference(), 1);
            updateVel.setUniformTexture("springData", springPrmTex, 2);
            updateVel.setUniformTexture("randomData", randomTex, 3);
            updateVel.setUniformTexture("targetData", finalTargetTex, 4);
            
            updateVel.setUniform1i("resolution", (int)textureRes);
            updateVel.setUniform2f("screen", (float)width, (float)height);
            updateVel.setUniform2f("offset", (float)offset.x, (float)offset.y);
            updateVel.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y);

            updateVel.setUniform1f("timestep", (float)timeStep);
            updateVel.setUniform1f("ACCEL",(float) prm.accel );
            updateVel.setUniform1f("SPEED",(float) prm.speed);
            updateVel.setUniform1f("VIBRATION",(float) prm.vibration );
            
            // draw the source velocity texture to be updated
            velPingPong.src->draw(0, 0);
        }updateVel.end();
    }velPingPong.dst->end();
    
    velPingPong.swap();
    
    
    //
    // 2. calc pos
    //
    posPingPong.dst->begin();{
        ofClear(0);
        updatePos.begin();{
            updatePos.setUniformTexture("prevPosData", posPingPong.src->getTextureReference(), 0); // Previus position
            updatePos.setUniformTexture("velData", velPingPong.src->getTextureReference(), 1);  // Velocity
            updatePos.setUniformTexture("springData", springPrmTex, 2);

            updatePos.setUniform1f("timestep",(float) timeStep );
//            updatePos.setUniform2f("offset", (float)offset.x, (float)offset.y);
//            updatePos.setUniform2f("pastOffset", (float)pastOffset.x, (float)pastOffset.y);
            posPingPong.src->draw(0, 0);
        }updatePos.end();
    }posPingPong.dst->end();
    
    posPingPong.swap();
    
    
    
    //
    // 3. render
    //
    renderFBO.begin();{

        ofClear(testApp::getBackgroundColor()); // ofClear(0);
        //ofClear(0, 0, 0, 0);

        updateRender.begin();{
            updateRender.setUniformTexture("posTex", posPingPong.dst->getTextureReference(), 0);
            updateRender.setUniformTexture("sparkTex", img->getTextureReference() , 1);
            updateRender.setUniformTexture("iconPrmTex", iconPrmTex, 2);
            updateRender.setUniformTexture("springData", springPrmTex, 3);

            updateRender.setUniform1i("resolution", (float)textureRes);
            updateRender.setUniform2f("screen", (float)testApp::getInstance()->getW(), (float)testApp::getInstance()->getH());
            updateRender.setUniform1i("size", (int)iconSize);
            updateRender.setUniform1f("imgWidth", imgSize);
            updateRender.setUniform1f("imgHeight", imgSize);
            // updateRender.setUniform2f("offset", (float)offset.x, (float)offset.y);

            ofPushStyle();
            //ofEnableBlendMode( OF_BLENDMODE_ADD );
            ofEnableBlendMode( OF_BLENDMODE_ALPHA);
            ofEnableAlphaBlending();
            ofEnableSmoothing();

            ofSetColor(255);
            ofFill();

            glBegin( GL_POINTS );{
                int count = 0;
                for(int y = 0; y < textureRes; y++){
                    for(int x = 0; x < textureRes; x++){
                      if(count >= total) break;
                        count++;
                        glVertex2d(x,y);
                        glTexCoord2i(x, y);
                    }
                    if(count >= total) break;
                }
            }glEnd();

            ofPopStyle();

        }updateRender.end();

        if(testApp::getDebugDraw()){
            {
                // Attractor
                const ofVec2f& attr = attractor::getPos();
                ofFill();
                ofSetColor(255, 55, 0);
                ofRect(attr.x*w, attr.y*h, 10, 10);

                ofFill();
                ofSetColor(5, 255, 0);
                ofRect(pastOffset.x*w, pastOffset.y*h, 10, 10);

                ofFill();
                ofSetColor(0, 5, 220);
                ofRect(offset.x*w, offset.y*h, 10, 10);
            }

            {
                // + line
                if(testApp::gprm.bWallMapMouseAdjust){
                    ofSetColor(0, 255, 0);
                }else{
                    ofSetColor(255, 0, 0);
                }
                glBegin(GL_LINES);
                glVertex3f(w/2, 0, 0); glVertex3f(w/2, h, 0);
                glVertex3f(0, h/2, 0); glVertex3f(w, h/2, 0);

                glVertex3f(1, 1, 0); glVertex3f(w-1, 1, 0);
                glVertex3f(1, h-1, 0); glVertex3f(w-1, h-1, 0);

                glVertex3f(1, 1, 0); glVertex3f(1, h-1, 0);
                glVertex3f(w-1, 1, 0); glVertex3f(w-1, h-1, 0);

                glVertex3f(1, 1, 0); glVertex3f(w-1, h-1, 0);
                glVertex3f(w-1, 1, 0); glVertex3f(1, h-1, 0);

                glEnd();
            }
        }

        if(testApp::gprm.bShowInfo){
            ofPushMatrix();{
                ofTranslate(0,0);
                ofSetColor(ofColor(255,255,255)-testApp::gprm.bg);
                ofFill();
                ofRect(0, 0, w, 30);
                ofSetColor(testApp::gprm.bg);
                int y = 23;
                ofDrawBitmapString("fps: " + ofToString(ofGetFrameRate()),20,y);
                ofDrawBitmapString("picto num: " + ofToString(gpuPicto::totalPicto), 200, y);

                ofDrawBitmapString("Frame num: " + ofToString(ofGetFrameNum()), 400, y);
            }ofPopMatrix();
        }
    }renderFBO.end();
    
    pastOffset = offset;

}