//--------------------------------------------------------------
void ofApp::draw(){

    ofBackground(0,0,0);
    ofSetColor(255,255,255);

    if(resolPantalla == 1 ){
        pantallaFBOKaleidoscopeA.begin();
    } else if (resolPantalla == 2 ){
        pantallaFBOKaleidoscopeB.begin();
    }else if (resolPantalla == 4 ){
        pantallaFBOKaleidoscopeC.begin();
    }
    ofClear(0,0,0,0);
    ofBackground(0,0,0);
    ofSetColor(255,255,255);
        ofEnableAlphaBlending();
        pingPong.dst->draw(0,0);

    if(resolPantalla == 1 ){
        pantallaFBOKaleidoscopeA.end();
    } else if (resolPantalla == 2 ){
        pantallaFBOKaleidoscopeB.end();
    }else if (resolPantalla == 4 ){
        pantallaFBOKaleidoscopeC.end();
    }

    if (bKaleidoscope == false){
        if(resolPantalla == 1 ){
            pantallaFBOKaleidoscopeA.draw(0,ofGetWindowHeight(),ofGetWindowWidth(),-ofGetWindowHeight());
        } else if (resolPantalla == 2 ){
            pantallaFBOKaleidoscopeB.draw(0,ofGetWindowHeight(),ofGetWindowWidth(),-ofGetWindowHeight());
        }else if (resolPantalla == 4 ){
            pantallaFBOKaleidoscopeC.draw(0,ofGetWindowHeight(),ofGetWindowWidth(),-ofGetWindowHeight());
        }

    } else {
        float distCentro = ofGetWindowHeight()/2;
        float nSlices = KaleidoscopeSlices*2;
        float angleTemp = 360/nSlices;
        float catOpuesto = tan(angleTemp*(PI/180))*distCentro;
        if(resolPantalla == 1 ){
            pantallaFBOKaleidoscopeA.getTextureReference().bind();
        } else if (resolPantalla == 2 ){
            pantallaFBOKaleidoscopeB.getTextureReference().bind();
        }else if (resolPantalla == 4 ){
            pantallaFBOKaleidoscopeC.getTextureReference().bind();
        }
            ofPushMatrix();
                ofTranslate((ofGetWindowWidth())/2,(ofGetWindowHeight())/2);
                for (int slice = 0; slice  < nSlices/2; slice++){
                    ofPushMatrix();
                    ofRotateZ(slice*angleTemp*2);
                        glBegin( GL_TRIANGLES );
                            glTexCoord2d( ((resolVert/resolPantalla)/2),                 ((resolVert/resolPantalla)/2)            ); glVertex2d(           0,           0);
                            glTexCoord2d( ((resolVert/resolPantalla)/2)+catOpuesto/resolPantalla+80/(float)resolPantalla , ((resolVert/resolPantalla)/2)+((float)distCentro/(float)resolPantalla) ); glVertex2d(  catOpuesto, -distCentro);
                            glTexCoord2d( ((resolVert/resolPantalla)/2)-catOpuesto/resolPantalla+80/(float)resolPantalla , ((resolVert/resolPantalla)/2)+((float)distCentro/(float)resolPantalla) ); glVertex2d( -catOpuesto, -distCentro);
                        glEnd();
                    ofPopMatrix();
                }
            ofPopMatrix();
        if(resolPantalla == 1 ){
            pantallaFBOKaleidoscopeA.getTextureReference().unbind();
        } else if (resolPantalla == 2 ){
            pantallaFBOKaleidoscopeB.getTextureReference().unbind();
        }else if (resolPantalla == 4 ){
            pantallaFBOKaleidoscopeC.getTextureReference().unbind();
        }
        ofSetColor(255,255,255);
        ofPushMatrix();
            ofTranslate(ofGetWindowWidth()/2,ofGetWindowHeight()/2);
            for (int slice = 0; slice  < nSlices/2; slice++){
                ofPushMatrix();
                ofRotateZ(slice*angleTemp*2);
                ofLine(  catOpuesto, -distCentro, -catOpuesto, -distCentro);
                ofPopMatrix();
            }
        ofPopMatrix();
    }

    
    if (show_fps == true){
        ofFill();
        ofSetColor(0,0,10,200);
        ofRect(0,0,300,190);
        ofSetColor(180,180,180);
        ofNoFill();
        ofRect(0,0,300,190);
        ofSetColor(255,255,255);
        ofDrawBitmapString("FPS: "+ofToString(ofGetFrameRate(), 2), 10, 1*15);
        ofDrawBitmapString("Some shader use your mouse movement!", 10, 2*15);
        ofDrawBitmapString("'f' Toggle Fullscreen.", 10, 3*15);
        ofDrawBitmapString("'s' Toggle Show INFO.", 10, 4*15);
        ofDrawBitmapString("'r' Change Resolution Divider: " +ofToString(resolPantalla), 10, 5*15);
        if( bKaleidoscope == true){
            ofDrawBitmapString("'k' Toggle Kaleidoscope: ON!", 10, 6*15);
            ofDrawBitmapString("'1' y '2' Kaleidoscope Slices: " +ofToString(KaleidoscopeSlices), 10, 7*15);
        } else {
            ofDrawBitmapString("'k' Toggle Kaleidoscope: OFF", 10, 6*15);
            ofSetColor(100,100,100);
            ofDrawBitmapString("'1' y '2' Kaleidoscope Slices: " +ofToString(KaleidoscopeSlices), 10, 7*15);
        }
        ofSetColor(255,255,255);
        ofDrawBitmapString("'Up' y 'Down' Cambia Shader", 10, 8*15);
        ofDrawBitmapString("Shader "+ofToString(nFrag+1)+ " de " +ofToString(frags.size()), 10, 9*15);
        if( bFine == true){
            ofSetColor(0,120,255);
            ofDrawBitmapString(ofToString(fragNames[nFrag]), 10,10*15);
            ofDrawBitmapString("Shader Loaded Correctly!", 10, 11*15);
        } else {
            ofSetColor(255,0,0);
            ofDrawBitmapString(ofToString(fragNames[nFrag]), 10,10*15);
            ofDrawBitmapString("Shader Loaded Incorrectly!", 10,11*15);
        }
        ofSetColor(255,255,255);
        ofDrawBitmapString("'h' Toggle hide Cursor.", 10, 12*15);
    }
    

}
Example #2
0
Particle::Particle() {
    mass = 20.0;
    pos.x = ofGetWindowWidth()/2;
    pos.y = 20;
    image.loadImage("card.png");
}
Example #3
0
Mover::Mover()
{
	location = ofPoint(ofRandom(ofGetWindowWidth()),ofRandom(ofGetWindowHeight()));
	velocity = ofVec2f(0,0);
	topSpeed = 5;
}
Example #4
0
// Other methods
void Particle::update(){ // main method that controls all necessary movement
    // attraction and repulsion
    float dy = (ofGetWindowHeight() - ofGetMouseY()) - getY();
    float dx = ofGetMouseX() - getX();
    if (getAttract() && !getRepel()){
        float desired = atan2(dy,dx);
        float angdiff = desired-getAngle();
        if ((angdiff > 0 && abs(angdiff) <= PI) || (angdiff < 0 && abs(angdiff) > PI)){
            setAngle(getAngle() + getAlpha());
        }
        else if ((angdiff > 0 && abs(angdiff)>PI) || (angdiff < 0 && abs(angdiff) <= PI)){
            setAngle(getAngle() - getAlpha());
        }
//        if (desired+getAlpha()>getAngle() && desired-getAlpha()<getAngle()){
//            setSpeed(getSpeed()+getFlow());
//        }
//        else {
//            if (getSpeed()>ORBITAL_FACTOR*getFlow()){
//                setSpeed(getSpeed()-getFlow());
//            }
//        }
    }
    else if (getRepel() && !getAttract() && sqrt(pow(dy,2) + pow(dx,2)) <= BARRIER){
        float desired = atan2(dy,dx) > 0 ? atan2(dy,dx) - PI : atan2(dy,dx) + PI;
        float angdiff = desired - getAngle();
        if ((angdiff > 0 && abs(angdiff) <= PI) || (angdiff < 0 && abs(angdiff) > PI)){
            setAngle(getAngle() + getAlpha());
        }
        else if ((angdiff > 0 && abs(angdiff) > PI) || (angdiff < 0 && abs(angdiff) <= PI)){
            setAngle(getAngle() - getAlpha());
        }
//        if (desired+getAlpha()>getAngle() && desired-getAlpha()<getAngle()){
//            setSpeed(getSpeed()+getFlow());
//        }
//        else {
//            if (getSpeed()>ORBITAL_FACTOR*getFlow()){
//                setSpeed(getSpeed()-getFlow());
//            }
//        }
    }
    else if (getAttract() && getRepel()){
        if (getSpeed() > 0){
            setSpeed(getSpeed() - getFlow());
        }
    }
    // life
    if (getAlive()){
        setAngle(getAngle() + ofRandomf() * getAlpha());
        setSpeed(getSpeed() + ofRandomf() * getFlow());
        setRadius(getRadius() + ofRandomf() * RADIUS_NOISE);
    }
    // bounds
    if (getX() > ofGetWindowWidth() - getRadius() || getX() < getRadius()){
        setAngle(-getAngle() + PI);
    }
    if (getY() > ofGetWindowHeight() - getRadius() || getY() < getRadius()){
        setAngle(-getAngle());
    }
    // position + motion
    position += velocity;
    // color
    float r = getAttract() && getRepel() ? getColor().r + 1 : (getSpeed()/MAX_SPEED) * 255;
    float g = getAttract() ? getColor().g + 1 : (getY()/ofGetWindowHeight()) * 255;
    float b = getRepel() ? getColor().b + 1 : (1-getY()/ofGetWindowHeight()) * 255;
    setColor(r,g,b);
}
void kinactorApp::guiEvent(ofxUIEventArgs &e)
{
    if(e.widget->getName() == "NEAR THRESHOLD")
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        nearThreshold = (int) slider->getScaledValue();
#ifdef DEBUG
        std::cerr << "slider event: " << slider -> getScaledValue() << " , threshold: " << nearThreshold << std::endl;
#endif
        
    } 
    else if(e.widget->getName() == "FAR THRESHOLD") 
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        farThreshold = (int) slider->getScaledValue();
    }
    else if(e.widget->getName() == "TILT UP [>]")
    {
        ofxUIButton *button = (ofxUIButton *) e.widget;
        upKinectAngle();
    }
    else if(e.widget->getName() == "TILT DOWN [<]")
    {
        ofxUIButton *button = (ofxUIButton *) e.widget;
        downKinectAngle();
    }
    else if(e.widget->getName() == "DEPTH NEAR VALUE WHITE")
    {
        ofxUIToggle *toggle = (ofxUIToggle *) e.widget; 
        kinect.enableDepthNearValueWhite(toggle->getValue());
#ifdef DEBUG
        std::cerr << "Depth Near Value is now: " << kinect.isDepthNearValueWhite() << std::endl;
#endif
    }
    else if(e.widget->getName() == "CONNECT [o]")
    {
        ofxUIButton *button = (ofxUIButton *) e.widget;
        kinectConnect();
    }
    else if(e.widget->getName() == "DISCONNECT [c]")
    {
        ofxUIButton *button = (ofxUIButton *) e.widget;
        kinectDisconnect();
    }
    else if(e.widget->getName() == "TRANSLATE")
    {
        ofxUI2DPad *pad = (ofxUI2DPad *) e.widget;
#ifdef DEBUG
        std::cerr << "PAD % VALUES x:" << pad->getPercentValue().x << " y:" << pad->getPercentValue().y << std::endl;
        std::cerr << "Conversion x:" << pad->getPercentValue().x * ofGetWindowWidth() << " y:" << pad->getPercentValue().y * ofGetWindowHeight() << std::endl;
#endif
        mtrx = pad->getPercentValue().x * ofGetWindowWidth();
        mtry = pad->getPercentValue().y * ofGetWindowWidth();
    }
    else if(e.widget->getName() == "SCALE")
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        scaleFactor = slider->getScaledValue();
    }
    else if(e.widget->getName() == "CONTOUR MIN")
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        contour_min = (int) slider->getScaledValue();
    }
    else if(e.widget->getName() == "CONTOUR MAX")
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        contour_max = (int) slider->getScaledValue();
    }
    else if(e.widget->getName() == "MAX BLOBS")
    {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        blobMax = (int) slider->getScaledValue();
    }
    
}
void AudioPaintingVisualOscReceiver::receiveMessagges()
{
    bool setSameFriction = false;
    
    bool setSameSpring = false;
    
	while( receiver.hasWaitingMessages() )
	{
		ofxOscMessage m;
		receiver.getNextMessage( &m );
        
       // cout <<  m.getAddress() << endl;
        /*
		if ( m.getAddress() == "/changeDistancePointToPoint" )
		{
            cout << "changeDistancePointToPoint" << endl;
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.distancePointToPoint = ofMap(m.getArgAsFloat( 0 ), 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minDistancePointToPoint, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxDistancePointToPoint);
        }
        if ( m.getAddress() == "/changeTriangleCoefficent" )
		{
             ((testApp*)ofGetAppPtr())->audioPaintingVisual.triangleCoefficent = ofMap(m.getArgAsFloat( 0 ), 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minTriangleCoefficent, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxTriangleCoefficent);
        }*/
        if ( m.getAddress() == "/output" )
		{
            
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bDrawPoint = m.getArgAsInt32( 0 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bDrawTriangle = m.getArgAsInt32( 1 );
            
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bSameColorTriangle = m.getArgAsInt32( 2 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bTimeAlphaTriangle = m.getArgAsInt32( 3 );
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bDrawLinePointToPoint = m.getArgAsInt32( 4 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bConnectPointToPrev = m.getArgAsInt32( 5 );
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.repulsionFromTarget = m.getArgAsInt32( 6 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.distancePointToPoint = ofMap(m.getArgAsFloat( 7 ), 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minDistancePointToPoint, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxDistancePointToPoint);
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.triangleCoefficent = ofMap(m.getArgAsFloat( 8 ), 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minTriangleCoefficent, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxTriangleCoefficent);
            
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxDistancePointToPoint = m.getArgAsFloat( 9 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxTriangleCoefficent = m.getArgAsFloat( 10 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.volumeLimitToInvert = m.getArgAsFloat( 11 );
		}
        else if ( m.getAddress() == "/triangle/sameColor" )
        {
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.sameColorTriangle.r =  m.getArgAsInt32( 0 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.sameColorTriangle.g =  m.getArgAsInt32( 1 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.sameColorTriangle.b =  m.getArgAsInt32( 2 );
        }  
        else if ( m.getAddress() == "/emitterMode" )
        {
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.setNewEmitterMode(m.getArgAsInt32( 0 ), true);
        }
        else if ( m.getAddress() == "/fastEmitterMode" )
        {
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.setNewEmitterMode(true, false);
        }
        else if ( m.getAddress() == "/addSinglePoint" )
        {
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.addSinglePoint(m.getArgAsFloat( 0 ) * ofGetWindowWidth(), m.getArgAsFloat( 1 ) * ofGetWindowHeight(), false);
        }
        else if ( m.getAddress() == "/removePoint" )
        {
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.removePoint(m.getArgAsFloat( 0 ) * ofGetWindowWidth(), m.getArgAsFloat( 1 ) * ofGetWindowHeight());
        }
        else if ( m.getAddress() == "/clear" )
        {
            cout << "CLEAR" << endl;
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.clear();
        }
        else if ( m.getAddress() == "/setFullscreen" )
        {
            cout << "CAmbio full" << endl;
            if(isFullscreen) return;
            //cout << "Change " << endl;
            if( m.getArgAsInt32( 0 ) == 0)
                cout << "Non esce mai dal fullscreen una volta entrato" << endl;
                //      ofSetFullscreen(false);
            else
            {
                cout << "Vado full" << endl;
                isFullscreen = true;
                ofSetFullscreen(true);
            }
        }
        else if ( m.getAddress() == "/setWindowSize" )
        {
          //  ofSetWindowShape(m.getArgAsInt32( 0 ), m.getArgAsInt32( 1 ));
        }
        else if ( m.getAddress() == "/loadShape" )
        {
            
            int totPointBefore = ((testApp*)ofGetAppPtr())->audioPaintingVisual.points.size();
            cout << "**************************" << endl;
            cout << "TOT PREV POINT " <<  totPointBefore << endl;
            cout << "TOT NEW POINT " <<  m.getArgAsInt32( 0 )<< endl;
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.totNewPointToDraw = m.getArgAsInt32( 0 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPointAlreadyDraw = 0;
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPrevPoint = ((testApp*)ofGetAppPtr())->audioPaintingVisual.points.size();
            
            
//   if( ((testApp*)ofGetAppPtr())->audioPaintingVisual.totNewPointToDraw >  ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPrevPoint)
            
            if(((testApp*)ofGetAppPtr())->audioPaintingVisual.totPrevPoint - m.getArgAsInt32( 0 ) > 0)
            {
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.clearLastPoints(((testApp*)ofGetAppPtr())->audioPaintingVisual.totPrevPoint - m.getArgAsInt32( 0 ));
            }
            
        }
        else if ( m.getAddress() == "/loadDirect" )
        {
            int totPointBefore = ((testApp*)ofGetAppPtr())->audioPaintingVisual.points.size();
            for(int a = 0; a < m.getArgAsInt32( 0 ); a++)
            {
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.addPointToNewForm(m.getArgAsFloat( 1 + (a * 2) ) * ofGetWindowWidth(), m.getArgAsFloat( (1 + (a * 2) + 1) ) * ofGetWindowHeight(), a);
            }
            int diff = totPointBefore - m.getArgAsInt32( 0 );
            
            if(diff > 0)
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.clearLastPoints(diff);
        }
        else if ( m.getAddress() == "/addPoint" )
        {
            //cout << "TOT PUNTI = " << m.getArgAsInt32( 0 ) << endl;
            
          //  int totPointToDraw = m.getArgAsInt32( 0 );
           // int totPointFree = m.getArgAsInt32( 0 ) - m.getArgAsInt32( 1 );
           
            cout << "PUNTI DA DISEGNARE = " <<  m.getArgAsFloat( 0 ) << endl;
            
            float pointToDrawNow = m.getArgAsFloat( 0 );
            
            // ((testApp*)ofGetAppPtr())->audioPaintingVisual.points.size()
            
            int totPointToDraw = ((testApp*)ofGetAppPtr())->audioPaintingVisual.totNewPointToDraw;
            int totPointAlreadyDraw = ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPointAlreadyDraw;
            int totPrevPoint = ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPrevPoint;
            
            if(totPrevPoint > 0 && totPrevPoint > totPointAlreadyDraw)
            {
                cout << "CAMBIO TARGET " << endl;
                int cont = 0;
              //  errore qui sotto
                for(int a = totPointAlreadyDraw; a < ((testApp*)ofGetAppPtr())->audioPaintingVisual.totNewPointToDraw; a++)
                {
                    if(cont <= pointToDrawNow)
                    {
                        if(a < totPrevPoint)
                        {
                            ofPoint tempPoint;
                            tempPoint.x = m.getArgAsFloat( 1 + (cont * 2) ) * ofGetWindowWidth();
                            tempPoint.y = m.getArgAsFloat( (1 + (cont * 2) + 1) ) * ofGetWindowHeight();
                            ((testApp*)ofGetAppPtr())->audioPaintingVisual.points[a]->setTarget(tempPoint);
                            ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPointAlreadyDraw++;
                            
                        }
                        else
                        {
                            cout << "DENTRO QUI" << endl;
                            ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPointAlreadyDraw++;
                            ((testApp*)ofGetAppPtr())->audioPaintingVisual.addSinglePoint(m.getArgAsFloat( 1 + (cont * 2) ) * ofGetWindowWidth(), m.getArgAsFloat( (1 + (cont * 2) + 1) ) * ofGetWindowHeight(), true); 
                        }
                        cont++;
                    }
                }
            }
            else
            {
                for(int a = 0; a < m.getArgAsFloat( 0 ); a++)
                {
                    ((testApp*)ofGetAppPtr())->audioPaintingVisual.totPointAlreadyDraw++;
                    ((testApp*)ofGetAppPtr())->audioPaintingVisual.addSinglePoint(m.getArgAsFloat( 1 + (a * 2) ) * ofGetWindowWidth(), m.getArgAsFloat( (1 + (a * 2) + 1) ) * ofGetWindowHeight(), true);
                }
            }
            
            
            /*
            if(totPointFree > 0  )
            {
                if(totPointFree
            }
             */
            /*
            
            cout << "DISEGNO PUNTI RIMANENTI " <<  m.getArgAsInt32( 1 ) << endl;
            for(int a = 0; a < m.getArgAsInt32( 0 ); a++)
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.addSinglePoint(m.getArgAsFloat( 1 + (a * 2) ) * ofGetWindowWidth(), m.getArgAsFloat( (1 + (a * 2) + 1) ) * ofGetWindowHeight());
            */
        }
        else if ( m.getAddress() == "/particle/timeSpring" )
        {
            setSameSpring = m.getArgAsInt32( 0 );
            
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bTimeSpring = setSameSpring;
        }
        else if ( m.getAddress() == "/particle/newSpring" )
        {
            //cout << "TIME STRING = " << setSameSpring << endl;
            if(!setSameSpring)
            {
                //cout << "SET SAME SPRING " << m.getArgAsFloat( 0 ) << endl;
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.setSpring(m.getArgAsFloat( 0 ));
            }
        }
        else if ( m.getAddress() == "/particle/timeFriction" )
        {
            setSameFriction = m.getArgAsInt32( 0 );
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.bTimeFriction = setSameFriction;
        }
        else if ( m.getAddress() == "/particle/newFriction" )
        {
            if(!setSameFriction)
                ((testApp*)ofGetAppPtr())->audioPaintingVisual.setFriction(m.getArgAsFloat( 0 ));
        }
        else if ( m.getAddress() == "/particle/newSpeed" )
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.setSpeed(ofMap(m.getArgAsFloat( 0 ) / 100, 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minSameSpeed, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxSameSpeed)); 
        else if ( m.getAddress() == "/particle/newRepulsionForce" )
        {  //cout << m.getArgAsFloat( 0 ) << endl;
            ((testApp*)ofGetAppPtr())->audioPaintingVisual.setRepulsionForce(ofMap(m.getArgAsFloat( 0 ), 0, 1, ((testApp*)ofGetAppPtr())->audioPaintingVisual.minRepulsionForce, ((testApp*)ofGetAppPtr())->audioPaintingVisual.maxRepulsionForcce)); 
        }
        else
        {
         //   //cout << m.getAddress() << endl;
        //    if( m.getAddress() == "/midi/cc7/1")
         //       audioPaintingVisual->maxDistance = (m.getArgAsFloat( 0 ) * 200) + 1;
        }
         
	}
    
}
Example #7
0
//--------------------------------------------------------------
void testApp::setup(){
    myField.setup( ofGetWindowWidth(), ofGetWindowHeight(), 20 );
    
    ofBackground(0);
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
    for (int i = 0; i < NUM_RECTS; i++) {
        myRectangle[i].pos.x = ofRandom(ofGetWindowWidth());
        myRectangle[i].pos.y = ofRandom(ofGetWindowHeight());
    }
}
Example #9
0
float Ball::xForDraw(){
  return ofGetWindowWidth()/2 - HALF_BLOCK_SIZE * FIELD_WIDTH + x;
}
Example #10
0
Bubble::Bubble() {
    x = ofGetWindowWidth() * 0.5;
    y = ofGetWindowHeight() * 0.5;
    xVel = ofRandom(-5,5);
    yVel = ofRandom(-5,5);
}
Example #11
0
void Renderer::draw()
{
	ofClear(0);

	image->draw(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
}
Example #12
0
//--------------------------------------------------------------
void Trons::windowResized(int w, int h){
    fbo.allocate(ofGetWindowWidth(), ofGetWindowHeight(), GL_RGBA32F_ARB); // with alpha, 8 bits red, 8 bits green, 8 bits blue, 8 bits alpha, from 0 to 255 in 256 steps
    fbo.begin();
    ofClear(255,255,255, 0);
    fbo.end();
}
Example #13
0
//--------------------------------------------
particle::particle(){
    setInitialCondition(ofGetWindowWidth(), ofGetWindowHeight(), ofGetWindowWidth(), ofGetWindowHeight());
    damping = 0.09f;
}
SingleImagePage* GoofyLeapImageGallery::loadImage(int id, SingleImagePage* img)
{
  img = new SingleImagePage();
  img->setup(urlImages[id], ofVec2f(ofGetWindowWidth(), ofGetWindowHeight()));
  return img;
}
Example #15
0
void Boid::draw() {
    
    // Draw a triangle rotated in the direction of velocity
	
    
    if(loc.x == 0 || loc.x == ofGetWindowWidth()) vel.x *= -1;
    if(loc.y == 0 || loc.y == ofGetWindowHeight()) vel.y *= -1;


	
	float angle = (float)atan2(-vel.y, vel.x);
    float theta =  -1.0*angle;
	float heading2D = ofRadToDeg(theta)+90;
	
	ofEnableAlphaBlending();
    ofSetColor(255, 255, 255);
    ofFill();
    ofPushMatrix();
    ofTranslate(loc.x, loc.y);
    ofRotateZ(heading2D);
    
	/* DRAW BOID ARROW - REPLACED WITH PNG IN FINAL VERSION
    ofBeginShape();
    ofVertex(0, -r*2);
    ofVertex(-r, r*2);
    ofVertex(r, r*2);
    ofEndShape(true);
    */
    
    // DRAW PNG IMAGE FOR AIRPLANE
    i.setAnchorPoint(10, 12);
    i.draw(0,0);
    
    ofPopMatrix();
	ofDisableAlphaBlending();
    
    
    // Draw the predicted location
    if (debug) {
		ofFill();
        
		ofSetColor(0,191,255); // BLUE
		ofLine(loc.x,loc.y,predictLoc.x, predictLoc.y);
        
        // PREDICTED LOCATION 
		ofEllipse(predictLoc.x, predictLoc.y,4,4);

		// Draw normal location
		ofSetColor(255, 69, 0); //ORANGE
		ofLine(predictLoc.x, predictLoc.y, target.x, target.y);
		ofEllipse(target.x,target.y,4,4);
		
		// Draw actual target (red if steering towards it)
		ofLine(predictLoc.x,predictLoc.y,target.x,target.y);
		

        // VIOLET CIRCLE IS TARGET + DIR
		ofSetColor(255, 20, 147);
		ofEllipse(target.x+dir.x, target.y+dir.y, 8, 8);
    }

    
}
Example #16
0
//--------------------------------------------------------------
void testApp::setup() {
    ofBackground(0);
    \
    ofEnableAlphaBlending();
    ofSetLogLevel(OF_LOG_VERBOSE);
    //ofSetFrameRate(60);
    ofSetVerticalSync(false);
    // Setup UDP socket to receive data from OpenGazer
    udpSocket.Create();
    udpSocket.Bind(OG_UDP_PORT);
    udpSocket.SetNonBlocking(true);

    // initialise gaze coords
    gazeCoords[0] = -1;
    gazeCoords[1] = -1;
    gazeCoords[2] = -1;
    gazeCoords[3] = -1;

    //create an event listener for eye movement
    //ofAddListener(onEyeMoved, this, &testApp::eyeMoved);
    ofAddListener(gazeMove, (blenderWindow*)&mypropWindow, &blenderWindow::onGazeMoved);
    ofAddListener(gazeMove, (blenderWindow*)&mytdWindow, &blenderWindow::onGazeMoved);
    ofAddListener(gazeMove, (TXTWindow*)&mytxtWindow1, &TXTWindow::onGazeMoved);
    ofAddListener(gazeMove, (TXTWindow*)&mytxtWindow2, &TXTWindow::onGazeMoved);

    // Set windows positions & dimensions
    mypropWindow.set(0, 0, ofGetWindowWidth()/4, ofGetWindowHeight()/4*3);
    mytdWindow.set(ofGetWindowWidth()/4, 0, ofGetWindowWidth()/2, ofGetWindowHeight()/4*3);
    mytxtWindow1.set(ofGetWindowWidth()/4*3, 0, ofGetWindowWidth()/4, ofGetWindowHeight()/4*3);
    mytxtWindow2.set(0, ofGetWindowHeight()/4*3, ofGetWindowWidth(), ofGetWindowHeight()/4);

    //position buttons
    float posX = ofGetWindowWidth() - 64;
    float posY = ofGetWindowHeight() - 32;
    gazeTrackBtn.setImage("gaze.png");
    gazeTrackBtn.enableMouseEvents();
    gazeTrackBtn.set(posX, posY, 16, 16);
    startBtn.setImage("record.png");
    startBtn.enableMouseEvents();
    startBtn.set(posX+20, posY, 16, 16);
    cursorBtn.setImage("cursor.png");
    cursorBtn.enableMouseEvents();
    cursorBtn.set(posX+40, posY, 16, 16);


    // Initiase tasks & corresponding windows
    blenderTask* t0 = new blenderTask();
    t0->setCorrespondingWindow((blenderWindow&)mypropWindow);
    t0->setIdentifier("PROP");
    blenderTask* t1 = new blenderTask();
    t1->setCorrespondingWindow((blenderWindow&)mytdWindow);
    t1->setIdentifier("TDWN");
    //t1->timeOut = 10.f;
    blenderTask* t2 = new blenderTask();
    t2->setCorrespondingWindow((blenderWindow&)mytxtWindow1);
    t2->setIdentifier("TXT1");
    // Add the initialised task to the broker
    blenderTask* t3 = new blenderTask();
    t3->setCorrespondingWindow((blenderWindow&)mytxtWindow2);
    t3->setIdentifier("TXT2");
    broker.addTask(*t0);
    broker.addTask(*t1);
    broker.addTask(*t2);
    broker.addTask(*t3);
}
Example #17
0
//--------------------------------------------------------------
void ofApp::draw(){
	 shader.begin();
	 ofRect(0,0,ofGetWindowWidth(),ofGetWindowHeight());
     shader.end();
}
//--------------------------------------------------------------
void testApp::setup(){
    particleSize = 30.0f;
    timeStep = 0.005f;
    numParticles = 1000;
    
    // Width and Heigth of the windows
    width = ofGetWindowWidth();
    height = ofGetWindowHeight();
    
    string shadersFolder;
    if(ofGetGLProgrammableRenderer()){
    	shadersFolder="shaders_programmable";
    }else{
    	shadersFolder="shaders";
    }

    // Loading the Shaders
    updatePos.load("",shadersFolder+"/posUpdate.frag");// shader for updating the texture that store the particles position on RG channels
    updateVel.load("",shadersFolder+"/velUpdate.frag");// shader for updating the texture that store the particles velocity on RG channels
    
    // Frag, Vert and Geo shaders for the rendering process of the spark image
    updateRender.setGeometryInputType(GL_POINTS);
	updateRender.setGeometryOutputType(GL_TRIANGLE_STRIP);
	updateRender.setGeometryOutputCount(6);
    updateRender.load(shadersFolder+"/render.vert",shadersFolder+"/render.frag",shadersFolder+"/render.geom");
    
    // Seting the textures where the information ( position and velocity ) will be
    textureRes = (int)sqrt((float)numParticles);
    numParticles = textureRes * textureRes;
    
    // 1. Making arrays of float pixels with position information
    float * pos = new float[numParticles*3];
    for (int x = 0; x < textureRes; x++){
        for (int y = 0; y < textureRes; y++){
            int i = textureRes * y + x;
            
            pos[i*3 + 0] = ofRandom(1.0); //x*offset;
            pos[i*3 + 1] = ofRandom(1.0); //y*offset;
            pos[i*3 + 2] = 0.0;
        }
    }
    // Load this information in to the FBO�s texture
    posPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    posPingPong.src->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    posPingPong.dst->getTextureReference().loadData(pos, textureRes, textureRes, GL_RGB);
    delete [] pos;    // Delete the array
    
    
    // 2. Making arrays of float pixels with velocity information and the load it to a texture
    float * vel = new float[numParticles*3];
    for (int i = 0; i < numParticles; i++){
        vel[i*3 + 0] = ofRandom(-1.0,1.0);
        vel[i*3 + 1] = ofRandom(-1.0,1.0);
        vel[i*3 + 2] = 1.0;
    }
    // Load this information in to the FBO�s texture
    velPingPong.allocate(textureRes, textureRes,GL_RGB32F);
    velPingPong.src->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    velPingPong.dst->getTextureReference().loadData(vel, textureRes, textureRes, GL_RGB);
    delete [] vel; // Delete the array
    
    // Loading and setings of the variables of the textures of the particles
    sparkImg.loadImage("spark.png");
    imgWidth = sparkImg.getWidth();
    imgHeight = sparkImg.getHeight();
    
    // Allocate the final 
    renderFBO.allocate(width, height, GL_RGB32F);
    renderFBO.begin();
    ofClear(0, 0, 0, 255);
    renderFBO.end();


    mesh.setMode(OF_PRIMITIVE_POINTS);
    for(int x = 0; x < textureRes; x++){
        for(int y = 0; y < textureRes; y++){
            mesh.addVertex(ofVec3f(x,y));
            mesh.addTexCoord(ofVec2f(x, y));
        }
    }

}
//--------------------------------------------------------------
void testApp::draw(){
    
    // gray rectangle
    ofSetColor(240);
    ofRect(0, 430, ofGetWindowWidth(), 40);
    
    // black dot
    ofSetColor(0);
    ofCircle(50, 450, 15);
    
    // red dot
    ofSetColor(255, 0, 0);
    ofCircle(100, 450, 15);
    
    // green dot
    ofSetColor(0, 255, 0);
    ofCircle(150, 450, 15);
    
    // blue dot
    ofSetColor(0, 0, 255);
    ofCircle(200, 450, 15);
    
    // heart indicator
    ofSetColor(255);
    gHeart.draw(400, 450);
    
    // if the drawer has requested to save, draw a half-heart
    // (will just draw on top of other one
    if ( bSaveRequestSent ) {
        rHeart.draw(400, 450);
    }
    if ( bSaveRequestReceived ) {
        lHeart.draw(400, 450);
    }
    
    if (bSaveRequestSent && bSaveRequestReceived ) {
        fullHeart.draw(400, 450);
    }
    
    // drawing indicator for what color is selected
    ofNoFill();
    ofSetColor(100);
    if (penColor == ofColor(0, 0, 0) ) {
        ofCircle(50, 450, 18);
    } else if (penColor == ofColor(255, 0, 0) ) {
        ofCircle(100, 450, 18);
    } else if (penColor == ofColor(0, 255, 0) ) {
        ofCircle(150, 450, 18);
    } else if (penColor == ofColor(0, 0, 255) ) {
        ofCircle(200, 450, 18);
    }
    ofFill();
    
    ofSetColor( penColor );
    
    // local drawing
    if ( bIsDrawing ) {
        ofLine(lastX, lastY, mouseX, mouseY);
        
        // every time we draw a line, send a message to the remote app
        spacebrew.sendRange("lastPosX", lastX);
        spacebrew.sendRange("lastPosY", lastY);
        spacebrew.sendRange("posX", mouseX);
        spacebrew.sendRange("posY", mouseY);
        
        lastX = mouseX;
        lastY = mouseY;
    }
    
    // draw remote information
    // note, the remote variables will update only when
    // the app receives all four within one frame
    ofSetColor(remoteColor);
    ofLine(remoteLastX, remoteLastY, remoteX, remoteY);
    
    if ( bSaveRequestReceived && bSaveRequestSent ) {
        // fullHeart.draw(400, 450); // note: if draw heart here, is black in saved .png file
        ofSaveFrame();
        bSaveRequestReceived = false;
        bSaveRequestSent = false;
        ofSetColor( 255, 255, 255 );
        ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
    }
}
Example #20
0
void testApp::setup(){
    Particle* p;
    //Particles_Container* g;
    //ofSetFrameRate(1);
    ofSetVerticalSync(true);
    ofEnableSmoothing();
    // 15 pixels given for particle regular grid distance
    //mouseWave.min_dist = regularGrid_interactions_system.grid_ds*2;
    //mouseWaveGenerator.setup();
    mouse.startThread(true, false);
    managerInterface.start(&world);
    
    p = world.create_particle("MP_RegGrid");

    if(strncmp("MP_RegGrid","MP_",3) == 0){
        managerInterface.update_availableItems_names(&(managerInterface.group_name),"C_MP_RegGrid");
    }




    Tag* t0 = world.create_tag();

    t0->add_particles(world.particles.get_itemsByName("P_Circle"));
    t0->add_behavior("B_GravityGlue");

    p = world.create_particle("P_Circle");
    
    Tag* t1 = world.create_tag();

    t1->add_behavior("B_MouseTracking");
    Interaction* i0 = t1->add_interaction("I_ElectRepulsion");
    i0->add_tag(t0);

    t1->add_particle(p);

    cout << "hello dynamicWorld!!" << endl;
    // testing remove particle
    world.remove_particle(p);

    p = world.create_particle("P_Circle");
    *(p->ofColorPtr_map["color"]) = ofColor(255,0,0);
    *(p->ofVec3fPtr_map["loc"]) = ofVec3f(ofGetWindowWidth()/2,ofGetWindowHeight()/2,0);
    *(p->intPtr_map["rad"]) = 10;

    t1->add_particle(p);


    //p->behaviors.add_itemByName("B_MouseTracking",p);

    //p->set_var( b->name+"_loc", *(p->ofVec3fPtr_map["loc"]) );
    //ofVec3f* v_ptr;
    //p->get_var( b->name+"_loc",v_ptr);

//    g = world.create_group("G_dancers");
//    managerInterface.update_availableItems_names(&(managerInterface.group_name),"G_dancers");
//    g->add(p,false);

    //world.remove_particle(p);
    //for (u_int i=0; i<world.groups.itemsVector.size(); i++){
    //    cout<<world.groups.itemsVector[i]->id;
    //}

}
Example #21
0
void Canvas::draw()
{
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    ofSetColor(ResourceManager::getInstance().getBackgroundColor());
    ofFill();
    ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
    ofDisableBlendMode();
    
//    bgImg.draw(0, 0);

    if (Params::colorMode == 0)
    {
        ofEnableBlendMode(OF_BLENDMODE_SUBTRACT);
    }
    else {
        ofEnableBlendMode(OF_BLENDMODE_ADD);
    }
    
    // Draw normal strokes (#1)
    for (int i=0; i<strokes.size(); i++)
    {
        strokes[i]->draw();
    }
    if (currentStroke) {
        currentStroke->draw();
    }
    
    // Draw surface strokes (#2)
    ofSetColor(Params::surfaceColor);
    ofFill();
    for (int i=0; i<surfaceStrokes.size(); i++)
    {
        surfaceStrokes[i]->drawSurface();
    }
    if (currentSurfaceStroke) {
        currentSurfaceStroke->drawSurface();
    }

    // Draw particle strokes (#3)
    for (int i=0; i<particleStrokes.size(); i++)
    {
        particleStrokes[i]->draw();
    }
    if (currentParticleStroke) {
        currentParticleStroke->draw();
    }
    
    // Draw repeatable strokes (#4)
    for (int i=0; i<repeatableStrokes.size(); i++)
    {
        repeatableStrokes[i]->draw();
    }
    if (currentRepeatableStroke) {
        currentRepeatableStroke->draw();
    }

    // Draw spring strokes (#5)
    for (int i=0; i<springStrokes.size(); i++)
    {
        springStrokes[i]->draw();
    }
    if (currentSpringStroke) {
        currentSpringStroke->draw();
    }
    
    // Draw particle emitters (#7)
    for (int i=0; i<emitters.size(); i++)
    {
        emitters[i]->draw();
    }
    
    // Draw flow field ('f')
    if (bShowFlowfield) {
        flowField.draw();
    }

    
    // draw cursor
    ofSetColor(ResourceManager::getInstance().getStrokeColor());
    ofNoFill();
    if (strokeType == 4) {
        ofLine(ofGetMouseX()-7, ofGetMouseY()-7, ofGetMouseX()+7, ofGetMouseY()+7);
        ofLine(ofGetMouseX()+7, ofGetMouseY()-7, ofGetMouseX()-7, ofGetMouseY()+7);
        ofLine(bladePrev, blade);
    }
    else {
        ofEllipse(ofGetMouseX(), ofGetMouseY(), 15, 15);
    }
    
    ofDisableBlendMode();

}
Example #22
0
Skeleton::Skeleton()
{ posX=ofGetWindowWidth() *0.5;
posY = ofGetWindowWidth() * 0.5; 
}
Example #23
0
// Setters
void Particle::setX(float x){
    position.x = ofClamp(x,getRadius(),ofGetWindowWidth() - getRadius());
}
void ParticleVisualization::makeBubble(float x, float y, float dx, float dy){
	screenBubble b(x * ofGetWindowWidth(), y * ofGetWindowHeight(), dx * ofGetWindowWidth(), dy * ofGetWindowHeight());
	bubbles.push_back(b);
}
Example #25
0
//--------------------------------------------------------------
void testApp::setup() {

	// SYSTEM
	ofSetLogLevel(OF_LOG_VERBOSE);
	ofHideCursor();
	ofSetFrameRate(60);
	
	// SCREEN
    ofEnableAlphaBlending();
    ofBackground(100);
    width = ofGetWindowWidth();
    height = ofGetWindowHeight();
	
	// KINECT
	kinect.setRegistration(true);
	kinect.init();	
	kinect.open();
	if(kinect.isConnected()) {
		ofLogNotice() << "sensor-emitter dist: " << kinect.getSensorEmitterDistance() << "cm";
		ofLogNotice() << "sensor-camera dist:  " << kinect.getSensorCameraDistance() << "cm";
		ofLogNotice() << "zero plane pixel size: " << kinect.getZeroPlanePixelSize() << "mm";
		ofLogNotice() << "zero plane dist: " << kinect.getZeroPlaneDistance() << "mm";
	}
	angle = 23;
	kinect.setCameraTiltAngle(angle);
	
	// OPENCV
	colorImg.allocate(kinect.width, kinect.height);
	grayImage.allocate(kinect.width, kinect.height);
	grayThreshNear.allocate(kinect.width, kinect.height);
	grayThreshFar.allocate(kinect.width, kinect.height);
	grayBg.allocate(kinect.width, kinect.height);
	grayDiff.allocate(kinect.width, kinect.height);
	closePoints.allocate(kinect.width, kinect.height, GL_RGBA32F_ARB); 

	nearThreshold = 250;
	farThreshold = 112;
	bLearnBakground = true;
	threshold = 80;
	bThreshWithOpenCV = false;
	minBlob = 25; 
	maxBlob = (kinect.width*kinect.height)/2; 
	
	// STATE
	presenting = true;
	tooSunny = true;
	fboAge = 0; 
	imageTimer = 0; 
	playState = 1;
	currentBrightness = 0;
	targetAlpha = 155;
	
    // XML ASSETS
    assets.loadFile("xml/assets.xml");
    if( assets.loadFile("xml/assets.xml") ) {
        ofLog(OF_LOG_NOTICE, "Loaded xml file !!! \n");
        // Load Fonts
        loadFonts();
        // Load Artist Names
        loadArtists();
        // Load Media Names
        loadAssets();
    }
    else {
        ofLog(OF_LOG_ERROR, "UNABLE to load xml file :( \n");
    }

    //  INDEX
    currentIndex = 0;
    updateCurrentIndex();

    // ASSETS
    brush.loadImage("images/brush.png");
	stamp.loadImage("logo/stamp_white2.png");
	demo.loadMovie("demo/studio_in_the_city_6_promo.mp4");

    // FBO & GLSL SHADER
    setupGL(width, height);
    
    // MEMORY
    checkMemory();

	cout << "Setup Is Done \n" << endl;

}
Example #26
0
void ofxComposer::load(string _fileConfig){
    if (_fileConfig != "default")
        configFile = _fileConfig;
    
    ofxXmlSettings XML;
    
    patches.clear();
    if (XML.loadFile(_fileConfig)){
        int totalPatchs = XML.getNumTags("surface");
        
        // Load each surface present on the xml file
        //
        for(int i = 0; i < totalPatchs ; i++){
            ofxPatch *nPatch = new ofxPatch();
            bool loaded = nPatch->loadSettings(i, "config.xml");
            
            if (loaded){
                if (nPatch->getType() == "ofxGLEditor"){
                    ofLog(OF_LOG_NOTICE,"ofxComposer: ofxGLEditor loaded");
                    editor.setup("menlo.ttf");
                    editor.setCurrentEditor(1);
                    editorFbo.allocate(ofGetWindowWidth(), ofGetWindowHeight());
                    editorFbo.begin();
                    ofClear(0, 150);
                    editorFbo.end();
                    
                    nPatch->setTexture( editorFbo.getTextureReference(), 0);
                    
                    bGLEditor = true;
                }
                
                if (nPatch->getType() == "input"){
                    nPatch->setTexture( editorFbo.getTextureReference(), 0);
                }
                
                // Insert the new patch into the verctor
                //
                patches.push_back(nPatch);
                
                // Listen to close bottom on the titleBar
                //
                ofAddListener( patches[ patches.size()-1 ]->title->close , this, &ofxComposer::closePatch);
            }
        }
        
        
        // Load links between Patchs
        //
        for(int i = 0; i < totalPatchs ; i++){
            if (XML.pushTag("surface", i)){
                if (XML.pushTag("out")){
                    
                    int totalLinks = XML.getNumTags("dot");
                    for(int j = 0; j < totalLinks ; j++){
                        
                        if (XML.pushTag("dot",j)){
                            int toId = XML.getValue("to", 0);
                            int toTex = XML.getValue("tex", 0);
                            
                            // If everything goes ok "i" will match the position of the vector
                            // with the position on the XML, in the same place of the vector array
                            // defined on the previus loop
                            //
                            connect( i , fromIDtoArrayPos( toId ), toTex);
                            
                            XML.popTag();
                        }
                    }
                    XML.popTag();
                }
                XML.popTag();
            }
        }
    }
}
Example #27
0
//--------------------------------------------------
ofRectangle	ofGetWindowRect() {
	return ofRectangle(0, 0, ofGetWindowWidth(), ofGetWindowHeight());
}
Example #28
0
//--------------------------------------------------------------
void ofApp::update(){
    //clear and update the renderer
    spriteRenderer->clear();
    spriteRenderer->update(ofGetElapsedTimeMillis());
    
    //add the Link sprite to the renderer.
    spriteRenderer->addCenteredTile(&player->animation, player->pos.x - cameraCenter.x, player->pos.y - cameraCenter.y, 1, F_NONE, SCALE);
    
    //if there are backgrounds, loop through it and add each one to the renderer.
    if (backgrounds.size() > 0) {
        for (int i = backgrounds.size()-1; i>=0; i--) {
            //this line isn't necessary and in fact is imperfect, but uncomment to see how we might limit drawing to only the current screen area.
            //if (backgrounds[i]->pos.x > 0 && backgrounds[i]->pos.x < ofGetWindowWidth() && backgrounds[i]->pos.y > 0 && backgrounds[i]->pos.y < ofGetWindowHeight()) {
                spriteRenderer->addCenteredTile(backgrounds[i]->tileName, 0, backgrounds[i]->pos.x, backgrounds[i]->pos.y, 0, 1, 1, F_NONE, SCALE);
            //}
        }
    }
    
    //update the background position based on the grid and the camera position.
    for (int i = 0; i < GRIDH; i++) {
        for (int j = 0; j < GRIDW; j++) {
            backgrounds[i * GRIDW + j]->pos.set(j*spriteRenderer->getTileSize()*SCALE - cameraCenter.x, i*spriteRenderer->getTileSize()*SCALE - cameraCenter.y);
        }
    }
    
    //update the player's position and animation index based on key presses.
    if (leftPressed) {
        player->pos.x -= player->speed * spriteRenderer->getTileSize()*SCALE;
        player->animation.index = 4;
    }
    if (rightPressed) {
        player->pos.x += player->speed * spriteRenderer->getTileSize()*SCALE;
        player->animation.index = 2;
    }
    if (upPressed) {
        player->pos.y -= player->speed * spriteRenderer->getTileSize()*SCALE;
        player->animation.index = 0;
    }
    if (downPressed) {
        player->pos.y += player->speed * spriteRenderer->getTileSize()*SCALE;
        player->animation.index = 6;
    }
    
    //if no keys are being pressed, stop animating.
    //if keys are being pressed, animate Link's sprite.
    if (!leftPressed && !rightPressed && !upPressed && !downPressed) {
        player->animation.loops = 0;
    } else {
        player->animation.loops = -1;
        
        //this is an application of how we could check the player's position against the tiles.
        //we could use this approach to do collision detection for example.
        
        int tilePosX = floor((player->pos.x + (spriteRenderer->getTileSize() * SCALE)/2) / (spriteRenderer->getTileSize() * SCALE));
        int tilePosY = floor((player->pos.y + (spriteRenderer->getTileSize() * SCALE)/2) / (spriteRenderer->getTileSize() * SCALE));
        
        cout << "pos.x relative to tiles: " <<  tilePosX << ", pos.y relative to tiles: " <<  tilePosY << endl;
        
        cout << "background sprite index: " << getTileName(tilePosX, tilePosY) << endl;
    }

    //update the camera position to focus on the player's position.
    cameraCenter.x = player->pos.x - ofGetWindowWidth()/2;
    cameraCenter.y = player->pos.y - ofGetWindowHeight()/2;
}
Example #29
0
void Renderer::TestCreateOctahedron()
{
	Object3D* obj = new Object3D("models/octahedron/octahedron.obj");
    obj->glTranslate(ofGetWindowWidth()*0.5, ofGetWindowHeight()*0.5, 0);
	this->sceneStructure->AddElement(obj);
}
void ofApp::draw(){
    //double cur_frame_rate = frame_rate;
    //if(realtime) cur_frame_rate = ofGetFrameRate();

    //special nodes with hardcoded names
    ofFbo &render_fbo = forward_graph->getFbo("render");
    ofFbo &agent_input_fbo = forward_graph->getFbo("agent_input");
    int aw = agent_input_fbo.getWidth(), ah = agent_input_fbo.getHeight();


    vwt->setAgentRate(params.getFloat("agent_rate"), params.getFloat("agent_rate_scale"));
    vwt->setMomentumTime(params.getFloat("agent_momentum_time"));
    vwt->setPathJitter(params.getFloat("agent_path_jitter"));
    vwt->setAgentCombFrequencyP(params.getFloat("comb_freq_p"), params.getFloat("comb_freq_p_scale"));
    vwt->setAgentCombFrequencyV(params.getFloat("comb_freq_v"), params.getFloat("comb_freq_v_scale"));
    vwt->setAgentCombFeedbackP(params.getFloat("comb_fb_p"));
    vwt->setAgentCombFeedbackV(params.getFloat("comb_fb_v"));
    vwt->getVideoVolume()->setAspectRatio(double(aw)/ah);

    //draw agent path
    fill(agent_input_fbo, ofFloatColor(.5,.5,.5,0), OF_BLENDMODE_DISABLED);
    agent_input_fbo.begin();
    vwt->draw(0, 0, aw, ah);
    agent_input_fbo.end();


    //main video process
    forward_graph->update();

    //feedback
    forward_graph->swapFbos();

    //draw to window
    int ww = ofGetWindowWidth(), wh = ofGetWindowHeight();
    string display_node_name = display_sequence[disp_mode];
    // cout<<"<"<<display_node_name<<">"<<endl;
    ofFbo &display_fbo = forward_graph->getFbo(display_node_name);
    display_fbo.draw(0,0,ww,wh);

/*
    beginShader("torus_shift");
    setShaderParam("state", display_fbo.getTextureReference(0), 0);
    setShaderParam("shift", draw_offset);
    setShaderParam("size", ww, wh);
    display_fbo.draw(0,0,ww,wh);
    endShader();
    //resampleToWindow(display_fbo);
*/
    if(recording || save_frame){
        //ofFloatPixels pix;
        ofPixels pix;

        //quick hack to record flicker;
        //proper way would be to have conditional graph structure?
        mov(display_fbo, render_fbo);

        // time = ofGetSystemTimeMicros();
        //render_fbo.readToPixels(pix,0);
        record_reader.readToPixels(render_fbo, pix);
        // cout<<"readback time: "<<ofGetSystemTimeMicros()-time<<" us"<<endl;

        if(save_frame){
            ofImage(pix).save("capture-"+ofGetTimestampString()+".png");
            save_frame = false;
        }
        if(recording){
            bool success = vr.addFrame(pix);
            if (!success) {
                ofLogWarning("This frame was not added!");
            }
        }
    }

    ofFbo &readback_fbo = forward_graph->getFbo("readback");

    shared_ptr<ofFloatPixels> pix(new ofFloatPixels());
    //readback_fbo.readToPixels(*pix,0);
    vwt_reader.readToFloatPixels(readback_fbo, *pix); 
    //the ofxVideoWaveTerrain is responsible for deleting pix
    //it automatically deletes the oldest frame when it has too many
    vwt->insert_frame(pix);

    //test readback
    // ofImage(*pix).draw(0,0,ww,wh);
    // ofFloatPixels ivv_pix;
    // ivv_pix.allocate(ww,wh,3);
    // for(size_t i=0;i<ww;i++){
    //     for(size_t j=0;j<wh;j++){
    //         double vwt_time = 1 + vwt->getElapsedTime() - vwt->getAudioDelay();
    //         ofFloatColor c = vwt->getVideoVolume()->getColor((i+.5)/ww,(j+.5)/wh,vwt_time);
    //         ivv_pix.setColor(i,j,c);
    //     }
    // }
    // if(!disp_mode) ofImage(ivv_pix).draw(0,0,ww,wh);

    //if in render mode, compute audio in the draw loop
    //delay should be equal to frame duration
    /*if(!realtime){
        int frame_duration_samps = audio_sample_rate/frame_rate;
        int nsamps = frame_duration_samps*audio_channels;
        float * samps = (float*)malloc(nsamps*sizeof(float));
        vwt->audioOut(samps, frame_duration_samps, audio_channels);
        writeAudioSamps(samps, nsamps);
        free((void*)samps);

        string timestamp = ofGetTimestampString();

        //save frame to disk
        //render_fbo->begin();
        //display_fbo.draw(0,0,render_fbo->getWidth(), render_fbo->getHeight());
        //render_fbo->end();
        ofImage img;
        img.allocate(display_fbo.getWidth(), display_fbo.getHeight(), OF_IMAGE_COLOR);
        display_fbo.readToPixels(img.getPixelsRef());
        stringstream feedback_fname;
        feedback_fname<<cur_save_dir.path()<<ofToDataPath("/feedback-")<<frame<<".png";
        img.saveImage(feedback_fname.str());
*/
        /*render_fbo->begin();
        agent_fbo.draw(0,0,render_fbo->getWidth(), render_fbo->getHeight());
        render_fbo->end();
        render_fbo->readToPixels(pix);
        stringstream waveform_fname;
        waveform_fname<<cur_save_dir.path()<<ofToDataPath("/waveform-")<<frame<<".png";
        ofImage(pix).saveImage(waveform_fname.str());

        if(use_camera){
            render_fbo->begin();
            camera.draw(0,0,render_fbo->getWidth(), render_fbo->getHeight());
            render_fbo->end();
            render_fbo->readToPixels(pix);
            stringstream camera_fname;
            camera_fname<<cur_save_dir.path()<<ofToDataPath("/camera-")<<frame<<".png";
            ofImage(pix).saveImage(camera_fname.str());
        }*/

    //}

    frame++;
    drawing = true;
}