//--------------------------------------------------------------
void testApp::setup(){
		
    radius = 400;
    max = 60;
    
    glEnable(GL_DEPTH_TEST); //make sure we test depth for 3d
    
		ofSetVerticalSync(true);
    ofEnableLighting();
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofEnableBlendMode(ofBlendMode(OF_BLENDMODE_ALPHA));
    
    mesh.addVertex(ofPoint(0,0,0)); // add center vertex
    mesh.addColor(ofColor(137,137,140,255)); // center is same as bg
    mesh.addNormal(ofVec3f(0,0,1)); // center normal points up
    
    zfreq = 3.;
    zamt = .3;
    
    //loop around and make verts in a circle, with a bit of a z-wave
    for (int i = 0; i < max; i++){
        float step = 2*PI/max; // step size around circle
        float theta = ofMap(i, 0, max-1, 0, 2*PI - step); //map i as circle divisions to actual radian values around the circle (note we don't go quite all the way around by one step, because it will be the same as where we started, so we'll just index that starting vertex when we make faces)
 
        float prevTheta = theta - step; //one step back
        float nextTheta = theta + step; // one step forward
        
        // create vertices in polar coordinates, plus a sine wave for z
        ofVec3f p(radius*cos(theta),radius*sin(theta), radius*zamt*sin(zfreq*theta) );
        // add this vertex
        mesh.addVertex(p);
        
        // we need these for calculating normals
        ofVec3f prev(radius*cos(prevTheta),radius*sin(prevTheta),radius*zamt*sin(zfreq*prevTheta) );        
        ofVec3f next(radius*cos(nextTheta),radius*sin(nextTheta),radius*zamt*sin(zfreq*nextTheta) );
        
        // our normals for each triangle face is the cross product of the two vectors making up that sliver 
        ofVec3f previousFaceNormal = prev.crossed(p);
        ofVec3f nextFaceNormal = p.crossed(next);
        
        /* notice here we go in the same direction: previous->current,current->next;
           we could similarly go next->current,current-prev, which would flip all of our normals;
           this might not be the best idea, but its certainly better than going previous->current,next->current, which would end up being quite awful.
           This is the concept of an "orientable mesh" or "face winding order", to be googled for more information.
         */
        
        // since we want smooth normals, we'll sum the two adjacent face normals, then normalize (since usually, only the direction and not the magnitude of the normal is what matters)
        mesh.addNormal((previousFaceNormal + nextFaceNormal).normalize());
        
        //add a color too
        ofColor c;
        c.setHsb(40 + 30*sin(2*theta+PI),255,255,255);        
        mesh.addColor(c);
    }
    
    //index our verts/normals/colors as a triangle fan
    for (int i=0, j = max-1; i < max; j=i++){
        mesh.addIndex(0);
        mesh.addIndex(i+1);
        mesh.addIndex(j+1);
    }
    
    // light the scene to show off why normals are important
    light.enable();
    light.setPointLight();
    light.setPosition(0,0,300);
		
}
bool BarGraph::draw(unsigned int x,unsigned int y,unsigned int w,unsigned int h){
    
    if( !initialized ) return false;
    if( data.size() == 0 || data.size() != numDimensions ) return false;
    
    ofPushMatrix();
    ofEnableAlphaBlending();
    ofTranslate(x, y);
    
    //Draw the background
    ofFill();
    ofSetColor(backgroundColor[0],backgroundColor[1],backgroundColor[2]);
    ofRect(0,0,w,h);
    
    //Draw the grid if required
    if( drawGrid ){
        ofSetColor(gridColor[0],gridColor[1],gridColor[2]);
        unsigned int numVLines = 20;
        unsigned int numHLines = 10;
        
        //Draw the horizontal lines
        for(unsigned int i=0; i<numHLines; i++){
            float xStart = 0;
            float xEnd = w;
            float yStart = ofMap(i,0,numHLines,0,h);
            float yEnd = yStart;
            ofLine(xStart,yStart,xEnd,yEnd);
        }
        
        //Draw the vertical lines
        for(unsigned int i=0; i<numVLines; i++){
            float xStart = ofMap(i,0,numVLines,0,w);
            float xEnd = xStart+1;
            float yStart = 0;
            float yEnd = h;
            ofLine(xStart,yStart,xEnd,yEnd);
        }
    }
    
    double barWidth = floor(w/(numDimensions+1.0));
    double barSpacer = (w-(barWidth*numDimensions))/numDimensions;
    
    //Draw the axis lines
    ofSetColor(255,255,255);
    ofLine(-5,h,w+5,h); //X Axis
    ofLine(0,-5,0,h+5); //Y Axis
    
    //Draw the bars
    ofSetColor(barColor[0],barColor[1],barColor[2]);
    ofFill();
    double x1 = barSpacer/2.0;
    double x2 = 0;
    double y1 = 0;
    double y2 = 0;
    double barHeight = 0;
    for(unsigned int n=0; n<numDimensions; n++){
        if( minRanges[n] != maxRanges[n] ){
            barHeight = ofMap(data[n],minRanges[n],maxRanges[n],1,h-1,constrainValuesToGraph);
            x2 = barWidth;
            y1 = 0 + h-barHeight-1;
            y2 = barHeight; 
            ofRect(x1,y1,x2,y2);
        }
        
        x1 += barWidth + barSpacer;
    }
    
    ofDisableAlphaBlending();
    ofPopMatrix();
    
    return true;
}
Ejemplo n.º 3
0
void ofApp::drawAlphabet(){
    ofEnableAlphaBlending();
    if (counterAlphabetsTitle<FRAME_RATE*introLength) {
        //facade title
        //blend in
        if(counterAlphabetsTitle<FRAME_RATE){
            blendInfoFacade+=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        }
        //blend out
        else if(counterAlphabetsTitle>FRAME_RATE*(introLength-1)){
            blendInfoFacade-=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        } else{
            ofSetColor(255);
        }
        alphabetTitleFacade.draw(37, 259);
        
        //LED2
        //blend in
        if(counterAlphabetsTitle<FRAME_RATE){
            blendInfoLED2+=8;
            ofSetColor(255, 255, 255, blendInfoLED2);
        }else{
            ofSetColor(255);
        }

        //title
        ofPushMatrix();
        ofTranslate(508, 77);
        
        alphabetTitleLED2.draw(0,0);
        //draw entire alphabet
        for (int i=0; i<allAlphabet.size(); i++) {
            allAlphabet[i].drawWholeLED2(i);
        }
        ofPopMatrix();

        
    } else if (counterDrawAlphabet<FRAME_RATE*alphabetLength) {
        //facade
        for (int i=0; i<NO_OF_ALPHABETS_RUNNING_THROUGH; i++) {
            allAlphabet[currImgNoAlphabet[i]].drawFacade();
        }
        //LED
        //blend out
        if(counterDrawAlphabet>FRAME_RATE*(alphabetLength-1)){
            blendInfoLED2-=8;
            ofSetColor(255, 255, 255, blendInfoLED2);
        } else{
            ofSetColor(255);
        }

        //title
        ofPushMatrix();
        ofTranslate(508, 77);
        
        
        //draw entire alphabet
        for (int i=0; i<allAlphabet.size(); i++) {
            allAlphabet[i].drawWholeLED2(i);
        }
        ofSetColor(255);
        alphabetTitleLED2.draw(0,0);

        ofPopMatrix();
        
        
    }else{
        //facade
        for (int i=0; i<NO_OF_ALPHABETS_RUNNING_THROUGH; i++) {
            allAlphabet[currImgNoAlphabet[i]].drawFacade();
        }
        //LED2
        for (int i=0; i<NO_OF_ALPHABETS_RUNNING_THROUGH_LED; i++) {
                       //LED2
            ofPushMatrix();
            ofTranslate(508, 77);
            alphabetTitleLED2.draw(0,0);

            allAlphabet[currImgNoAlphabetLED2[i]].drawLED2();
            
            ofPopMatrix();
        }

        
    }
    ofDisableAlphaBlending();
}
Ejemplo n.º 4
0
void TextWriter::draw(ofRectangle box, string text, bool centred) {
    text = ofToUpper(text);
    
	// added these lines otherwise you get horribleness! 
	if(box.height<=0) box.height = 1;
	if(box.width<=0) box.width = 1;
	
	
    ofPushStyle();

    ofEnableAlphaBlending();
    ofEnableBlendMode(OF_BLENDMODE_ADD);
    ofSetLineWidth(glyphLineWeight);
    
    ofPushStyle();
    ofSetColor(10, 10, 255, 128);
    ofNoFill();
	
    ofPopStyle();
    
    float boxRatio = box.height / (float)box.width;
    int textLength = text.length();
    string longestLine = "";
    vector<string> lines;
    
    int numRows = (int)sqrt(boxRatio * textLength / glyphRatio);
    if( (text.find(' ') == string::npos) || (numRows == 0) ) {
        longestLine = trim(text);
        lines.push_back(longestLine);
    } else {
        int numCols = textLength / numRows;
        int start = numCols;
        int index = 0;
        int last;
        
        for( int row = 0; row < numRows - 1; row++ ) {
            last = index;
            index = findBestBreak(text, start, numCols * 2);
            
            string linePart = trim(text.substr(last, index - last));
            
            if( linePart.length() > longestLine.length() ) {
                longestLine = linePart;
            }
            
            lines.push_back(linePart);
            
            start = index + numCols;
        }
        
          string linePart = trim(text.substr(index));
        lines.push_back(linePart);
        if( linePart.length() > longestLine.length() ) {
            longestLine = linePart;
        }
        
          }
    
    float glyphScaleFactor = (box.width / (float)longestLine.length()) / (float)(glyphWidth + glyphSpacing);
    float glyphRenderWidth = glyphWidth * glyphScaleFactor;
    float glyphRenderHeight = glyphHeight * glyphScaleFactor;
    float glyphRenderSpacing = glyphSpacing * glyphScaleFactor;
    
    float marginTop = ((box.height - ((glyphRenderHeight + glyphRenderSpacing) * lines.size())) / 2.0);
    float marginLeft = 0; //(int)((box.width - calculateBlockWidth(longestLine, glyphRenderWidth, glyphRenderSpacing)) / 2.0); 
    
    map <int, Letter>& letters = font.letters;
    
	ofMesh writingMesh; 
	
    float ofsX = marginLeft, ofsY = marginTop;
    for( int j = 0; j < lines.size(); j++ ) {
        string line = lines[j];
        float glyphMarginLeft = centred ? ((box.width - calculateBlockWidth(line, glyphRenderWidth, glyphRenderSpacing)) / 2.0) : 0;
        for( int i = 0; i < line.length(); i++ ) {
			addGlyphToMesh(letters[line[i]], ofRectangle(box.x + ofsX + glyphMarginLeft, box.y + ofsY, glyphRenderWidth, glyphRenderHeight), writingMesh);
            ofsX += glyphRenderWidth + glyphRenderSpacing;
        }
        ofsX = marginLeft;
        ofsY += glyphRenderHeight + glyphRenderSpacing;
    }
	
	writingMesh.setMode(OF_PRIMITIVE_LINES);
    writingMesh.draw();
    writingMesh.setMode(OF_PRIMITIVE_POINTS);
	writingMesh.draw();
    

	
    ofPopStyle();
	
	return writingMesh; 
}
Ejemplo n.º 5
0
//-------------------------------------------------------------- SETING
void testApp::setup(){
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofSetVerticalSync(false);
    
    open_flyout = false;
    
    //*** TRACKPAD SETUP ***//
    
    pad = ofxMultiTouchPad();
    
    
    //*** CAMERA SETUP ***//
    
    cam.setDistance(600);
    cam.disableMouseInput();
    cam.enableOrtho();
    cam.setVFlip(true);
    scale = 1.f;
    
    
    //*** TOP MENU ***//
    
    menu = new ofxUISuperCanvas("menu", 0, MENU_TOP_PADDING, ofGetWidth(), MENU_HEIGHT);
    menu->getCanvasTitle()->ofxUIWidget::setVisible(false);
    menu->setColorBack(ofxUIColor(140, 140, 140,255));
    ofxUISpacer* spacer;
    
    new menuItem(menu, "MultiImageButton", "New Patcher", "assets/new_file.png", false, 35, 20);
    new menuItem(menu, "MultiImageButton", "Open Patcher", "assets/open_file.png", false, 65, 20);
    new menuItem(menu, "MultiImageButton", "Save Patcher", "assets/save_file.png", false, 95, 20);
    spacer = new ofxUISpacer(130, 20, 1,25);
    menu->addWidget(spacer);
    spacer->setColorFill(ofxUIColor(120, 120, 120, 200));
    new menuItem(menu, "MultiImageButton", "Create Node", "assets/node.png", false, 140, 20);
    spacer = new ofxUISpacer(175, 20, 1,25);
    menu->addWidget(spacer);
    spacer->setColorFill(ofxUIColor(120, 120, 120, 200));
    new menuItem(menu, "MultiImageButton", "Save Snippet", "assets/save_snippet.png", false, 185, 20);
    new menuItem(menu, "MultiImageButton", "Open Snippet", "assets/open_snippet.png", false, 215, 20);
    spacer = new ofxUISpacer(250, 20, 1,25);
    menu->addWidget(spacer);
    spacer->setColorFill(ofxUIColor(120, 120, 120, 200));
    new menuItem(menu, "MultiImageToggle", "Straight Links", "assets/line.png", false, 260, 20);
    new menuItem(menu, "MultiImageToggle", "Curved Links", "assets/curve_line.png", false, 290, 20);
    new menuItem(menu, "MultiImageToggle", "Segmented Links", "assets/path_line.png", true, 320, 20);
    spacer = new ofxUISpacer(355, 20, 1,25);
    menu->addWidget(spacer);
    spacer->setColorFill(ofxUIColor(120, 120, 120, 200));
    new menuItem(menu, "MultiImageToggle", "Edit Mode on/off", "assets/edit_mode.png", false, 365, 20);
    ofAddListener(menu->newGUIEvent,this,&testApp::menuEvent);
    
    
    //*** RIGHT MENU ***//
    
    right_menu = new ofxUISuperCanvas("menu", 0, MENU_HEIGHT + MENU_TOP_PADDING, RIGHT_MENU_WIDTH, ofGetHeight() - (MENU_HEIGHT + MENU_TOP_PADDING));
    right_menu->getCanvasTitle()->ofxUIWidget::setVisible(false);
    right_menu->setColorBack(ofxUIColor(140, 140, 140,255));
    
    new menuItem(right_menu, "MultiImageButton", "Zoom In", "assets/zoom_in.png", false, 5, right_menu->getRect()->getHeight()-30);
    new menuItem(right_menu, "MultiImageButton", "Zoom Out", "assets/zoom_out.png", false, 5, right_menu->getRect()->getHeight()-60);
    new menuItem(right_menu, "MultiImageToggle", "Inspect", "assets/open_flyout.png", false, 5, right_menu->getRect()->getHeight()-100);
    
    ofAddListener(right_menu->newGUIEvent,this,&testApp::menuEvent);
    
    
    //*** MAIN CANVAS ***//
    
    gui = new ofxUISuperCanvas("", RIGHT_MENU_WIDTH, MENU_HEIGHT + MENU_TOP_PADDING, ofGetWidth() - RIGHT_MENU_WIDTH, ofGetHeight() - (MENU_HEIGHT +MENU_TOP_PADDING));
    gui->setColorBack(ofxUIColor(255,255,255,0));
    gui->setDraggable(false);
    gui->setOtherSelected(false);
    
    
    //*** COMPOSER AND PATCHES SETUP ***//
    
    composer = new ofxComposer();
    composer->setMainCanvas(gui);
    composer->load("config.xml");
    composer->setLinkType(PATH_LINKS);
    
    composer->setParent(cam);
    map<int,ofxPatch*> patches = composer->getPatches();
    for(map<int,ofxPatch*>::iterator it = patches.begin(); it != patches.end(); it++ ){
        it->second->setParent(cam);
    }
    
    
    //*** SCROLL BAR SETUP ***//
    
    this->scrollBars = new scrollBar(this->composer, &this->pad, SCROLL_BAR_EVENT_PRIORITY);
    scrollBars->setup();
}
Ejemplo n.º 6
0
/// \brief Callback de dessin
///
/// \return void
///
///
void Danseur::draw()
{
    if(Dessinable())
    {
        if(toBeDrawn)
        {
            ofPushStyle();
            ofEnableAlphaBlending();
            ofSetColor(255, 255, 255, Alpha() * 255);
            ofTrueTypeFont * text = _ttfText;

            if(bHugeText)
            {
                text = _ttfTextHuge;
            }

            float angleStep(0);
            float angle(0);

            if(Animable())
            {
                angleStep = 360 / 5.0f;
                angle = ofRadToDeg(_coteAngle.getCurrentValue()) + _coteAngleOffset;
            }

            ofPushStyle();
            ofPushMatrix();
            ofTranslate(x, y);

            if(toBeDrawn & DANSEUR_TIME)
            {
                angle += angleStep;
                ofPushMatrix();
                ofRotateZ(angle);
                text->drawString(_cote, offset(), 0);
                ofPopMatrix();
            }

            if(Animable())
            {
                if(toBeDrawn & DANSEUR_XPOS)
                {
                    angle += angleStep;
                    ofPushMatrix();
                    ofRotateZ(angle);
                    text->drawString("x=" + ofToString(x), offset(), 0);
                    ofPopMatrix();
                }

                if(toBeDrawn & DANSEUR_YPOS)
                {
                    angle += angleStep;
                    ofPushMatrix();
                    ofRotateZ(angle);
                    text->drawString("y=" + ofToString(y), offset(), 0);
                    ofPopMatrix();
                }

                if(toBeDrawn & DANSEUR_ANGLE)
                {
                    angle += angleStep;
                    ofPushMatrix();
                    ofRotateZ(angle);
                    ofVec2f O(ofGetWidth() / 2.0f, ofGetHeight() / 2.0f);
                    std::stringstream valeurAngle;
                    valeurAngle << std::fixed << std::setprecision(2) << Tools::getAngle((*this), O);
                    text->drawString("T=" + valeurAngle.str() + "°", offset(), 0);
                    ofPopMatrix();
                }

                if(toBeDrawn & DANSEUR_CONSTANTE)
                {
                    angle += angleStep;
                    ofPushMatrix();
                    ofRotateZ(angle);
                    text->drawString("a=" + ofToString(M_PI), offset(), 0);
                    ofPopMatrix();
                }
            }

            ofPopMatrix();
            ofDisableAlphaBlending();
            ofPopStyle();
        }
    }
}
Ejemplo n.º 7
0
void ofApp::setup()
{
    ofSetFrameRate(30);
    ofEnableAlphaBlending();

    const std::string TWITTER_DATE_FORMAT = "%w %b %f %H:%M:%S %Z %Y";

    std::string ts0 = "2000-01-01T12:00:00+01:00";        // Poco::DateTimeFormat::ISO8601_FORMAT
    std::string ts1 = "Wednesday, 1 Jan 20 12:00:00 GMT"; // Poco::DateTimeFormat::RFC1036_FORMAT
    std::string ts2 = "2018-01-01T17:00:00.000000+05:00"; // Poco::DateTimeFormat::ISO8601_FRAC_FORMAT
    std::string ts3 = "Tue Nov 12 23:14:54 +1100 2013";   // custom TWITTER_DATE_FORMAT

    int tzd0 = 0;
    int tzd1 = 0;
    int tzd2 = 0;
    int tzd3 = 0;

    Poco::DateTime min0;
    Poco::DateTime max0;
    Poco::DateTime min1;
    Poco::DateTime max1;

    try
    {
        // try to auto detect a known format
        min0 = Poco::DateTimeParser::parse(ts0, tzd0);

        // try to auto detect a known format
        max0 = Poco::DateTimeParser::parse(ts1, tzd1);

        // parse with a known format
        Poco::DateTimeParser::parse(Poco::DateTimeFormat::ISO8601_FRAC_FORMAT, ts2, min1, tzd2);

        // parse with a custom format
        Poco::DateTimeParser::parse(TWITTER_DATE_FORMAT, ts3, max1, tzd3);

        // we want to work with UTC time, rather than the local time parsed by
        // the Poco::DateTimeParser.  it is easy to convert by simply calling
        // Poco::DateTimeParser::makeUTC() with the time zone difference (in seconds)
        // calculated by the parser.

        min0.makeUTC(tzd0);
        max0.makeUTC(tzd1);
        min1.makeUTC(tzd2);
        max1.makeUTC(tzd3);
    }
    catch (const Poco::SyntaxException& exc)
    {
        ofLogError("ofApp::setup()") << "Syntax exception: " << exc.displayText();
    }

    // set up our ranges.  the Time::Range::set() function will order the
    // Poco::Timestamps appropriately.
    interval0.set(min0.timestamp(), max0.timestamp());
    interval1.set(min1.timestamp(), max1.timestamp());

    std::string range0Min = Utils::format(interval0.getStart());
    std::string range0Max = Utils::format(interval0.getEnd());
    std::string range1Min = Utils::format(interval1.getStart());
    std::string range1Max = Utils::format(interval1.getEnd());

    ofLogNotice("ofApp::setup()") << "range0: " << range0Min << " - " << range0Max;
    ofLogNotice("ofApp::setup()") << "range1: " << range1Min << " - " << range1Max;

}
void CloudsVisualSystemFireworks::selfDraw()
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	ofPushStyle();
	
	ofEnableDepthTest();
    glEnable(GL_NORMALIZE);
	
	ofEnableAlphaBlending();
	ofBlendMode( OF_BLENDMODE_ADD );
	ofEnablePointSprites();
	
	vector<ofFloatColor> fireworkColorArray;
	for (map<string, ofColor>::iterator it=fwColors.begin(); it!=fwColors.end(); it++)
	{
		fireworkColorArray.push_back( ofFloatColor(it->second) );
	}
	vector<ofFloatColor> fireworkDeathColorArray;
	for (map<string, ofColor>::iterator it=fwDeathColors.begin(); it!=fwDeathColors.end(); it++)
	{
		fireworkDeathColorArray.push_back( ofFloatColor(it->second) );
	}
	
	shader.begin();
	shader.setUniform4fv("fwColors", &fireworkColorArray[0].r, fireworkColorArray.size() );
	shader.setUniform4fv("fwDeathColors", &fireworkDeathColorArray[0].r, fireworkDeathColorArray.size() );
	shader.setUniform1f( "time", ofGetElapsedTimef() );
	shader.setUniform1f( "nearClip", getCameraRef().getNearClip() );
	shader.setUniform1f( "farClip", getCameraRef().getFarClip() );
	shader.setUniform1f( "speed", speed);
	shader.setUniform1f( "particleSize", particleSize);
	
	shader.setUniform3f("cameraPosition", camPos.x, camPos.y, camPos.z );
	
	ofFloatColor c0 = startColor;
	c0.setSaturation( startColorSaturation * 255 );
	
	ofFloatColor c1 = endColor;
	c1.setSaturation( endColorSaturation * 255 );
	shader.setUniform4f("startColor", c0.r, c0.g, c0.b, c0.a );
	shader.setUniform4f("endColor", c1.r, c1.g, c1.b, c1.a );
	
	shader.setUniform3f( "gravity", gravity.x, gravity.y, gravity.z );
	
	shader.setUniformTexture("dotMap", dotImage.getTextureReference(), 4 );
	shader.setUniformTexture("triangleMap", triangleImage.getTextureReference(), 3 );
	shader.setUniformTexture("squareMap", squareImage.getTextureReference(), 2 );
	shader.setUniformTexture("circleMap", circleImage.getTextureReference(), 1 );
	
	shader.setUniform1f( "useCircleMap", bUseCircle );
	shader.setUniform1f( "useSquareMap", bUseSquare );
	shader.setUniform1f( "useTriangleMap", bUseTriangle );
	shader.setUniform1f( "useDotMap", bUseDot );
	
	ofVec3f camPos = getCameraRef().getPosition();
	shader.setUniform3f("camearPosition", camPos.x, camPos.y, camPos.z);
	shader.setUniform1f("fogDistance", fogDistance);
	shader.setUniform1f("fogAttenuation", fogAttenuation);
	ofFloatColor fc = fogColor;
	fc.setSaturation(fogSaturation);
	shader.setUniform4f("fogColor", fc.r, fc.g, fc.b, fc.a );
	
	vbo.drawElements( GL_POINTS, indexCount );
	
	shader.end();
	
	glPopAttrib();
	ofPopStyle();
}
Ejemplo n.º 9
0
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    ofSetFrameRate(60);
    particle_system.init(256, 132, 512, 512);
}
Ejemplo n.º 10
0
//--------------------------------------------------------------
void testApp::draw(){


	ofBackground(0);
	
	ofEnableAlphaBlending();
	


	room.draw();

	//bloom.begin();
	glPushMatrix();
	{
		
		ofSetupScreen();

		
		
		glPushMatrix();
		{
			glScalef((float)ofGetWidth()/(float)kinect.getWidth(), (float)ofGetHeight()/(float)kinect.getHeight(), 1);
			ofSetHexColor(0xFFFFFF);

			//for(int i = 0; i < meshes.size(); i++) {
			//	meshes[i].draw();
			//}




			/*brushFbo.begin();
	
			ofEnableBlendMode(OF_BLENDMODE_ALPHA);
			glColor4f(0, 0, 0, backgroundAlpha);
			ofRect(0, 0, ofGetWidth(), ofGetHeight());

			glColor4f(1,1,1,imageAlpha);
				ofEnableBlendMode(OF_BLENDMODE_ADD);
	
			if (usingAdd) {
				glBlendFunc(GL_SRC_ALPHA, GL_ONE);
			}
			else {
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			}*/

			bloom.begin();
			map<int,RibbonSkeleton>::iterator it;
			for(it = skeletons.begin(); it != skeletons.end(); it++) {
				(*it).second.draw();
			}

			bloom.amount = ofMap(mouseX, 0, ofGetWidth(), 0, 1, true);
			bloom.end();
	
			/*brushFbo.end();

			ofEnableBlendMode(OF_BLENDMODE_ALPHA);
			glColor4f(1, 1, 1, 1);
			brushFbo.draw(0, 0);*/


		}
		glPopMatrix();
		
		glDisable(GL_DEPTH_TEST);
			
		
	}
	glPopMatrix();
	
	//bloom.end();
	//bloom.getOutput()->draw(0, ofGetHeight(), ofGetWidth(), -ofGetHeight());
	glColor4f(1,1,1,1);
	
	
	glPushMatrix();
	{
		ofSetupScreen();
	
	//	kinect.drawDebug();
		gui.draw();
	}
	glPopMatrix();
	
	
	//	output.getTextureReference(0).unbind();
}
//--------------------------------------------------------------------- draw
void ofxSimpleGuiColorPicker::draw(float x, float y) {
	
//	enabled = true;
	
	//update postion of gui object
	setPos(x, y);
	glPushMatrix();
	glTranslatef(x, y, 0);
	
	int startY = 0;
	for(int i=0; i<4; i++) {
		
		barwidth[i] = ofMap(getValue(i), 0, max, 0.0, (float)width);
		if(barwidth[i] > width)	barwidth[i] = width;
		else if(barwidth[i] < 0) barwidth[i] = 0;
		
		ofEnableAlphaBlending();
		ofFill();
		setEmptyColor();
		ofRect(0, startY, width, config->sliderTextHeight);
		
	if(max == 1){ 
		switch(i) {
			case 0:glColor3f(getValue(i), 0, 0); break;
			case 1:glColor3f(0, getValue(i), 0); break;
			case 2:glColor3f(0, 0, getValue(i)); break;
			case 3:glColor3f(getValue(i), getValue(i), getValue(i)); break;
		}
	} else {
		switch(i) {
			case 0:ofSetColor(getValue(i), 0, 0); break;
			case 1:ofSetColor(0, getValue(i), 0); break;
			case 2:ofSetColor(0, 0, getValue(i)); break;
			case 3:ofSetColor(getValue(i), getValue(i), getValue(i)); break;
		}
	}

		
		ofRect(0, startY, barwidth[i], config->sliderTextHeight);
		
		int iover = (getMouseY() - y) / (config->sliderTextHeight);
		bool isOver = iover == i;
		if(isOver) {
			glColor3f(1, 1, 1);
		} else {
			glColor3f(0.5, 0.5, 0.5);
		}
		
		if (max == 1 && displayInteger) {
			ofDrawBitmapString(ofToString(getValue(i)*255, 0), 3, startY + 14);
		} else {
			if(max == 255){
				ofDrawBitmapString(ofToString(getValue(i), 0), 3, startY + 14);
			} else {
				ofDrawBitmapString(ofToString(getValue(i), 4), 3, startY + 14);
			}
		}

		
		
		startY += config->sliderTextHeight;
	}
	
	ofFill();
	
	setTextBGColor();
	ofRect(0, startY, width, config->sliderTextHeight);

	if(max == 1){ 
		glColor3f(getValue(0), getValue(1), getValue(2));
	} else {
		ofSetColor(getValue(0), getValue(1), getValue(2));
	}
//	ofRect(0, startY+config->sliderTextHeight, width, config->sliderTextHeight * 1.5);
	ofRect(150, startY + 3, width - 150 -3, config->sliderTextHeight - 8);
	
	setTextColor();
	string s = name;
	ofDrawBitmapString(s, 3, startY + 14);
	ofDisableAlphaBlending();
	glPopMatrix();
}
void ofxIndustrialRobotVisualizer::drawside(int x, int y, int w, int h){	
	sideView.setPosAndSize(x,y,w, h);
	
	float aspect = (float)ofGetWidth()/ofGetHeight(); //1.333...
	float aspect2 = (float)w/h; //1.0000
	float mult = (float)aspect/aspect2; //Factor to multiply x coordinates with
	float scale = 0.17; // Same as to zoom
	ofxVec3f translate = ofxVec3f((ofGetWidth()/2.0)/mult-200, ofGetHeight()/2.0+200,0);
	
	if(sideView.click){
		float cx = ((float)app->mouseX - x)/w;
		float cy = ((float)app->mouseY - y)/h;
		float a = atan2(controller->targetPosition.x,controller->targetPosition.z)-HALF_PI;
		ofxVec3f target = ofxVec3f((float)((cx*ofGetWidth()/(float)mult)-translate.x)/scale,(float) -((cy*ofGetHeight())-translate.y)/scale, 0.0);
		target.rotateRad(a, ofxVec3f(0.0,1.0,0.0));
		controller->mousePressed(target);
		
		sideView.click = false;
	}
	
	glPushMatrix();
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity(); 
	glOrtho(0.0, (float)ofGetWidth(), 0.0, (float)ofGetHeight(), 10.0, 2500);
	
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity();
	gluLookAt(0.0, 0.0, 1000,
			  0.0, 0.0, 0.0,
			  0.0, 1.0, 0.0);
	
	glScalef(1, -1, 1);           // invert Y axis so increasing Y goes down.
	
	glViewport(x, ofGetHeight()- y-h, w, h);
	
	ofFill();
	ofSetColor(255, 255, 0);
	
	
	glScaled(1.0*mult, 1.0, 1.0);	
	glTranslated(0, -ofGetHeight(), 0);
	
	glPushMatrix();
	
	ofEnableAlphaBlending();
	ofFill();
	ofSetColor(255, 255, 255, 50);
	ofRect(0, 0, ofGetWidth()/mult, ofGetHeight());
	ofNoFill();
	ofSetColor(255, 255, 255);
	ofRect(0, 0, ofGetWidth()/mult, ofGetHeight());
	ofSetRectMode(1);
	
	glTranslated(translate.x, translate.y, 0);
	glScaled(scale, scale, scale);
	glRotated(-helper->getRotationAngle(0), 0.0,1.0,0.0); // Rotate it around the axis
			ofSetColor(0, 255, 0,255);
/*	for(int i=0;i<3000;i+=100){
		for(int u=0;u<3000;u+= 100){
			if(controller->legalPosition(ofxVec3f(i,u,0), controller->targetDir,0.0) || controller->legalPosition(ofxVec3f(i,u,0), controller->targetDir,1.0))
				ofRect(i, -u, 100, 100);
		}
	}*/
	drawGeneric();
	
	ofFill();
	glRotated(helper->getRotationAngle(0), 0.0,1.0,0.0); // Rotate it around the axis
	ofSetColor(255, 255, 255);
	ofLine(-1000, 0, 1000, 0);
	ofLine(0,-1000, 0, 1000);
	ofSetRectMode(0);	
	
	glPopMatrix();	
	
	glViewport(0, 0, ofGetWidth(), ofGetHeight());
	ofSetupScreen();
	ofSetColor(255, 255, 255);
	ofDrawBitmapString("Side view", x+10, y+15);
	
	glPopMatrix();	
	
}
void ofxIndustrialRobotVisualizer::drawtop(int x, int y, int w, int h){	
	topView.setPosAndSize(x,y,w, h);
	float aspect = (float)ofGetWidth()/ofGetHeight(); //1.333...
	float aspect2 = (float)w/h; //1.0000
	float mult = (float)aspect/aspect2; //Factor to multiply x coordinates with
	float scale = 0.09; // Same as to zoom
	ofxVec3f translate = ofxVec3f((ofGetWidth()/2.0)/mult, ofGetHeight()/2.0,0);
	
	if(topView.click){
		float cx = -(1.0- 2*((float)app->mouseX - x)/w);
		float cy = 1.0- 2*((float)app->mouseY - y)/h;
		float a1 = -atan2(cx,cy);
		float a2 = atan2(controller->targetPosition.x,controller->targetPosition.z)-HALF_PI;
		//		controller->targetPosition = ofxVec3f(((cx*ofGetWidth()/mult)/scale)/2.0, controller->targetPosition.y, (cy*ofGetHeight()/scale)/2.0);
		ofxVec3f target = ofxVec3f((float)((cx*ofGetWidth()/mult)/scale)/2.0,(float) controller->targetPosition.y, -(float)(cy*ofGetHeight()/scale)/2.0);
		controller->mousePressed(target);
		topView.click = false;
	}
	glPushMatrix();
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity(); 
	glOrtho(0.0, (float)ofGetWidth(), 0.0, (float)ofGetHeight(), 10.0, 2500);
	
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity();
	gluLookAt(0.0, 0.0, 1000,
			  0.0, 0.0, 0.0,
			  0.0, 1.0, 0.0);
	
	glScalef(1, -1, 1);           // invert Y axis so increasing Y goes down.
	
	glViewport(x, ofGetHeight()- y-h, w, h);
	ofFill();
	ofSetColor(255, 255, 0);
	
	glScaled(1.0*mult, 1.0, 1.0);	
	glTranslated(0, -ofGetHeight(), 0);
	
	ofEnableAlphaBlending();
	ofFill();
	ofSetColor(255, 255, 255, 50);
	ofRect(0, 0, ofGetWidth()/mult, ofGetHeight());
	ofNoFill();
	ofSetColor(255, 255, 255);
	ofRect(0, 0, ofGetWidth()/mult, ofGetHeight());
	ofSetRectMode(1);
	glTranslated(translate.x,translate.y, 0);
	glScaled(scale, scale, scale);
	
	glRotated(-90, 1.0, 0, 0.0);
	
	drawGeneric();
	
	ofSetRectMode(0);
	
	glViewport(0, 0, ofGetWidth(), ofGetHeight());
	ofSetupScreen();
	ofSetColor(255, 255, 255);
	ofDrawBitmapString("Top view", x+10, y+15);
	
	glPopMatrix();	
}
Ejemplo n.º 14
0
//--------------------------------------------------------------
void testApp::draw(){

	//--------------------------- circles
	//let's draw a circle:
	ofSetColor(255,130,0);
	float radius = 50 + 10 * sin(counter);
	ofFill();		// draw "filled shapes"
	ofCircle(100,400,radius);

	// now just an outline
	ofNoFill();
	ofSetHexColor(0xCCCCCC);
	ofCircle(100,400,80);

	// use the bitMap type
	// note, this can be slow on some graphics cards
	// because it is using glDrawPixels which varies in
	// speed from system to system.  try using ofTrueTypeFont
	// if this bitMap type slows you down.
	ofSetHexColor(0x000000);
	ofDrawBitmapString("circle", 75,500);


	//--------------------------- rectangles
	ofFill();
	for (int i = 0; i < 200; i++){
		ofSetColor((int)ofRandom(0,255),(int)ofRandom(0,255),(int)ofRandom(0,255));
		ofRect(ofRandom(250,350),ofRandom(350,450),ofRandom(10,20),ofRandom(10,20));
	}
	ofSetHexColor(0x000000);
	ofDrawBitmapString("rectangles", 275,500);

	//---------------------------  transparency
	ofSetHexColor(0x00FF33);
	ofRect(400,350,100,100);
	// alpha is usually turned off - for speed puposes.  let's turn it on!
	ofEnableAlphaBlending();
	ofSetColor(255,0,0,127);   // red, 50% transparent
	ofRect(450,430,100,33);
	ofSetColor(255,0,0,(int)(counter * 10.0f) % 255);   // red, variable transparent
	ofRect(450,370,100,33);
	ofDisableAlphaBlending();

	ofSetHexColor(0x000000);
	ofDrawBitmapString("transparency", 410,500);

	//---------------------------  lines
	// a bunch of red lines, make them smooth if the flag is set

	if (bSmooth){
		ofEnableSmoothing();
	}

	ofSetHexColor(0xFF0000);
	for (int i = 0; i < 20; i++){
		ofLine(600,300 + (i*5),800, 250 + (i*10));
	}

	if (bSmooth){
		ofDisableSmoothing();
	}

	ofSetHexColor(0x000000);
	ofDrawBitmapString("lines\npress 's' to toggle smoothness", 600,500);

}
Ejemplo n.º 15
0
void ofxPolygonMask::draw(ofEventArgs &args) {
	
	if(points.size()==0) return;

	if(points.size()<4) checkWinding();

	if(usingShader) {		
		

		shader.begin();
		shader.setUniformTexture("tex", *tex, 0);
		shader.setUniform1f("gamma", gamma);
		shader.setUniform1f("blendPower", blendPower);
		shader.setUniform1f("luminance", luminance);
	}
	ofFill();
	ofSetColor(0, 0, 0);
	
	// do a normal fill of the inside
	ofBeginShape();
	
	for(int i = 0; i < points.size(); i++) {
		ofVertex(points[i].x, points[i].y);
	}
	
	ofEndShape(true);
	
	calcBlendShape();
	ofEnableAlphaBlending();
	if(points.size()>0) {
		glBegin(GL_TRIANGLE_STRIP);
		for(int i = 0; i < points.size(); i++) {
			glColor4f(0, 0, 0, 1);
			glVertex2f(points[i].x, points[i].y);
			glColor4f(0, 0, 0, 0);
			glVertex2f(blendShape[i].x, blendShape[i].y);
		}
		glColor4f(0, 0, 0, 1);
		glVertex2f(points[0].x, points[0].y);
		glColor4f(0, 0, 0, 0);
		glVertex2f(blendShape[0].x, blendShape[0].y);
		
		glEnd();
	}
	
	if(usingShader) {
		shader.end();
	}
	
	if(editing) {
		ofNoFill();
		
		ofSetHexColor(0xFF0000);
		// do a normal fill of the inside
		ofBeginShape();
		for(int i = 0; i < points.size(); i++) ofVertex(points[i].x, points[i].y);
		ofEndShape(true);
		for(int i = 0; i < points.size(); i++) {
			if(i==focusedPoint) ofSetHexColor(0x00FF00);
			else ofSetHexColor(0xFF0000);
			ofCircle(points[i].x, points[i].y, DIST_POINT_GRAB);
		}
		
		ofSetHexColor(0xCC0000);
		ofBeginShape();
		for(int i = 0; i < blendShape.size(); i++) ofVertex(blendShape[i].x, blendShape[i].y);
		ofEndShape(true);
		ofFill();
	}
	
}
void ofxKinectTracking::drawDepth(int x, int y, int w, int h){
	ofSetColor(255, 255, 255);
	openCL.finish();
#ifndef NORMAL_CAMERA
	kinect->drawDepth(x,y,w,h);
#else
	clImage[0].draw(x,y,w,h);
#endif
	clImage[1].draw(x+w, y, w,h);
	
	ofSetColor(255, 0, 0);
	ofDrawBitmapString(ofToString(ofGetFrameRate(), 1), ofPoint(20,20));
	
	ofEnableAlphaBlending();
	glTranslated(0, 480*2, 0);
	
	float scale = 5000.0;
	
	{
		ofSetColor(255, 255, 255,100);
		double avg = 0;
		glBegin(GL_LINE_STRIP);
		for(int i=10;i<totalTime.size();i++){
			glVertex2d(i*3, -totalTime[i]*scale);
			avg += totalTime[i];
		}
		glEnd();
		avg /=totalTime.size()-10;
		
		ofSetColor(255, 100, 255,255);
		ofLine(0, -avg*scale, 640*2, -avg*scale);
		ofDrawBitmapString("Avg: "+ofToString(avg*10000, 2), ofPoint(5,-avg*scale-10));
		
		double percentage = ((avg)/(1/30.0))*100;
		ofSetColor(255, 255, 255);
		ofDrawBitmapString("Time percentage of one frame used on openCL: "+ofToString(percentage, 2)+"%", ofPoint(5,-460));
	}
	{
		ofSetColor(255, 0, 0,150);
		double avg = 0;
		glBegin(GL_LINE_STRIP);
		for(int i=10;i<killingTime.size();i++){
			//		cout<<totalTime[i]*10000.0<<endl;
			glVertex2d(i*3, -killingTime[i]*scale);
			avg += killingTime[i];
		}
		glEnd();
		avg /=killingTime.size()-10;
		
		ofSetColor(255, 100, 0);
		ofLine(0, -avg*scale, 640*2, -avg*scale);
		ofDrawBitmapString("K Avg: "+ofToString(avg*10000, 2), ofPoint(5,-avg*scale-10));
	}
	
	{
		ofSetColor(0, 255, 0,150);
		double avg = 0;
		glBegin(GL_LINE_STRIP);
		for(int i=10;i<spawningTime.size();i++){
			//		cout<<totalTime[i]*10000.0<<endl;
			glVertex2d(i*3, -spawningTime[i]*scale);
			avg += spawningTime[i];
		}
		glEnd();
		avg /=spawningTime.size()-10;
		
		ofSetColor(100, 255, 0);
		ofLine(0, -avg*scale, 640*2, -avg*scale);
		ofDrawBitmapString("S Avg: "+ofToString(avg*10000, 2), ofPoint(5,-avg*scale-10));
	}
	{
		ofSetColor(0, 0, 255,150);
		double avg = 0;
		glBegin(GL_LINE_STRIP);
		for(int i=10;i<updateTime.size();i++){
			//		cout<<totalTime[i]*10000.0<<endl;
			glVertex2d(i*3, -updateTime[i]*scale);
			avg += updateTime[i];
		}
		glEnd();
		avg /=updateTime.size()-10;
		
		ofSetColor(0, 100, 255);
		ofLine(0, -avg*scale, 640*2, -avg*scale);
		ofDrawBitmapString("U Avg: "+ofToString(avg*10000, 2), ofPoint(5,-avg*scale-10));
	}
	
	
	
	
	
}
Ejemplo n.º 17
0
//--------------------------------------------------------------
void testApp::draw() {
    
//    ofBackground(10);
    ofSetColor(255, 255, 255, 255);
    bgImage.draw( 0, 0);
    
    glEnable(GL_DEPTH_TEST);
    ofEnableAlphaBlending();
    
    // store the white highlights created from the lights in the fbo
    // later it will be blurred and then applied over the render
    lightFbo.begin();
    ofClear(255, 255, 255, 0);
//    ofClear(0, 0, 0, 0);
    
    cam.begin();
    
    ofSetColor(255, 255, 255);
    ofEnableLighting();

//    glDepthMask(false);
    
    ofSetLineWidth(4.f);
    
    
    lightShader.begin();
    lightShader.setUniform1f( "lightRadius", lightRadius );
    lightShader.setUniform1i( "numLights", NUM_LIGHTS );
    
    ofVec3f helixMidPt = h.getMidPoint();
    lightShader.setUniform3fv("lightPoss", (float*)lightPoss, NUM_LIGHTS );
    lightShader.setUniform1fv("lightRadiuss", (float*)lightRadiuss, NUM_LIGHTS );
    
    glDepthMask(false);
//    ofEnableBlendMode(OF_BLENDMODE_ADD);
    ofSetColor(255);
    h.drawCentered(true, false);
    h.drawCentered( false, true );
    glDepthMask(true);
//    ofDisableBlendMode();
    
    
    ofDisableLighting();
    lightShader.end();
    
//    glDepthMask(true);
    
    
    // calculate distance and draw a particle image into the glow fbo //
    glDepthMask(false);
    ofEnableBlendMode(OF_BLENDMODE_ADD);
    dust.getTextureReference().bind();
    ofSetColor(255, 255, 255, 255);
    
    float distance = 0;
    for(int i = 0; i < h.lines.size(); i++ ) {
        float closestDistance = 10000.f;
        float closestDistanceb = 10000.f;
        ofVec3f pos     = h.lines[i].a - helixMidPt;
        ofVec3f posb    = h.lines[i].b - helixMidPt;
        for(int j = 0; j < NUM_LIGHTS; j++ ) {
            ofVec3f lightPos = lights[j].getPosition();
            distance = (lightPos - pos).length();
            if(distance < closestDistance) closestDistance = distance;
            
            distance = (lightPos - posb).length();
            if(distance < closestDistanceb) closestDistanceb = distance;
        }
        
        if(closestDistance < lightRadius) {
            float pct = 1.f - (closestDistance / lightRadius);
            if(pct >= .2f) {
                pct = ofMap(pct, 0.2f, 1.f, 0.f, 1.f, true);
                renderGlowParticle( pos, pct );
            }
        }
        
        if(closestDistanceb < lightRadius) {
            float pct = 1.f - (closestDistanceb / lightRadius);
            if(pct >= .2f) {
                pct = ofMap(pct, 0.2f, 1.f, 0.f, 1.f, true);
                renderGlowParticle( posb, pct );
            }
        }
    }
    dust.getTextureReference().unbind();
    glDepthMask(true);
    ofDisableBlendMode();
    
    cam.end();
    
    lightFbo.end();
    
    glDisable( GL_DEPTH_TEST );
    
    ofSetColor(255);
    ofEnableAlphaBlending();
    blur.begin();
//    ofClear(255, 255, 255, 0);
    ofClear( 0, 0, 0, 255);
    lightFbo.draw(0, 0, lightFbo.getWidth(), lightFbo.getHeight() );
    lightFbo.draw(0, 0, lightFbo.getWidth(), lightFbo.getHeight() );
    blur.end();
    
    
    ofSetLineWidth(2.f);
    cam.begin();
    
    
    bool bDebugLights = ((ofxUIToggle*)gui->getWidget("Debug Lights"))->getValue();
    if(bDebugLights) {
        ofSetColor(255, 255, 255);
        ofNoFill();
        for(int i = 0; i < NUM_LIGHTS; i++ ) {
            ofPushMatrix(); {
                ofDrawArrow( ofPoint(0,0,0), ofPoint(1,0,0) );
                ofTranslate( lights[i].getPosition() );
                
                ofMatrix4x4 mat;
                mat.makeRotationMatrix(ofVec3f(0,0,1), cam.getLookAtDir() );
                ofPushMatrix();
                ofMultMatrix(mat.getPtr());
                ofCircle(0, 0, lightRadiuss[i] );
                ofPopMatrix();
                
                
            } ofPopMatrix();
        }
        ofFill();
    }
    
//    ofSetColor(84,204,254);
//    h.drawCentered( true, false);
//    h.drawCentered( false, true );
    
    
    
    
    ofSetColor(84,204,254);
    h.drawCentered( true, false);
    h.drawCentered( false, true );
    
    cam.end();
    
//    ofSetColor(255, 255, 255);
//    glDepthMask(false);
//    ofEnableBlendMode(OF_BLENDMODE_ADD);
    ofEnableAlphaBlending();
    ofEnableBlendMode( OF_BLENDMODE_ADD );
//    glBlendFunc(GL_SRC_COLOR, GL_ONE);
    ofSetColor(84,204,254);
    blur.getTextureReference().draw(0,768,1024,-768);
    ofSetColor(255, 255, 255, 255);
    blur.getTextureReference().draw(0,768,1024,-768);
////    blur.getTextureReference().draw(0,768,1024,-768);
    ofSetColor(255, 255, 255, 40);
//    lightFbo.draw(0,768,1024,-768 );
    ofDisableBlendMode();
    
//    glDepthMask(true);
    
    
    bool bRenderFbos = ((ofxUIToggle*)gui->getWidget("Render FBOs"))->getValue();
    if(bRenderFbos) {
        ofSetColor(0);
        ofRect(220, 20, ofGetWidth() * .25f, ofGetHeight() * .25f );
        ofSetColor(255,255,255,255);
        lightFbo.draw(220, 20 + ofGetHeight() * .25, ofGetWidth() * .25, -ofGetHeight() * .25);
    }
    

}
Ejemplo n.º 18
0
//--------------------------------------------------------------
void Particle::draw() {
    ofEnableAlphaBlending();
    ofFill();
    ofSetColor(color, alpha*255.0);
    ofCircle(pos, radius);
}
Ejemplo n.º 19
0
//--------------------------------------------------------------
void ofApp::draw(){
	ofEnableAlphaBlending();

	float time = ofGetElapsedTimef();
	float w = ofGetWidth();
	float h = ofGetHeight();

	fbo.begin();
	
	//Draw something on the screen

	//Set a gradient background from white to gray 
	//See "Sharp sphere example" in chapter "Creating in 3D with openFrameworks"
	ofBackgroundGradient( ofColor( 255 ), ofColor( 128 ) );

	ofSetColor( 255, 255, 255 );
	image.draw( 351, 221 );

	fbo.end();

	//Draw first image
	fbo2.begin();	
	ofBackground( 0, 0, 0 );
	float ang = time * 30;
	//ang = 0;

	ofPushMatrix();
	ofTranslate( w/2, h/2 );
	ofRotate( ang );
	ofFill();
	ofSetColor( 255, 255, 255 );
	ofTriangle( -200, -114, 200, -114, 0, 230 );
	ofPopMatrix();

	fbo2.end();

	//Enable shader
	shader.begin();
	
    //pass time value to shader
	shader.setUniform1f("time", time );
			
	//we also pass in the mouse position 
	//we have to transform the coords to what the shader is expecting which is 0,0 in the center and y axis flipped. 
	//shader.setUniform2f("mouse", mouseX - ofGetWidth()/2, ofGetHeight()/2-mouseY );
	shader.setUniformTexture( "texture1", fbo2.getTextureReference(), 1 ); //"1" means that it is texture 1

	shader.setUniformTexture( "texture2", spectrumImage.getTextureReference(), 2 ); //"2" means that it is texture 2

	//shader.setUniform1i( "N", N );
	shader.setUniform1fv( "specArray", spectrum, N );

	//Draw image through shader
	ofSetColor( 255, 255, 255 );
	fbo.draw( 0, 0 );

	//ofSetColor( 255, 255, 255, 128 );
	//fbo2.draw( 0, 0 );

	shader.end();

	//Draw spectrum
/*	ofFill();
	ofSetColor( 0, 255, 0 ); 
	for (int i=0; i<N; i++) {
		ofRect( w/2 + i * 7, h/2, 7, -spectrum[i] * 100 );
	}

	ofSetColor( 255, 255, 255 );
	spectrumImage.draw( w/2, 0, N*7, 50 );
	*/
}
Ejemplo n.º 20
0
//--------------------------------------------------------------
void testApp::draw(){
    glEnable(GL_DEPTH_TEST);
    
    // render the scene normally
    firstPass.begin();
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    ofClear(0);
        cam.begin();  
    
        ofPushMatrix();
        ofTranslate(-2500, -4000, -5000);
        ofSetColor(255);
        sunImage.draw(0, 0, 2048, 2048);
        ofPopMatrix();
    
            phong.begin();            
            phong.setUniform1i("useTex", 1);
            phong.setUniform3f("lightPos", -2, 3, -2);
                modelLoader.drawFaces();
            phong.end();
        cam.end();
    firstPass.end();
    
    // render the sun normally and the 'occluding objects' (tank) in black
    occluded.begin();
    ofClear(0);
        cam.begin();  
        
        ofPushMatrix();
        ofTranslate(-2500, -4000, -5000);
        ofSetColor(255);
        sunImage.draw(0, 0, 2048, 2048);
        ofPopMatrix();
        
            ofSetColor(0);
            modelLoader.drawFaces();
            ofSetColor(255);
        cam.end();
    occluded.end();
    
    lightRays.begin();
    ofClear(0);
        scattering.begin();
        scattering.setUniform1f("exposure", exposure);
        scattering.setUniform1f("decay", decay);
        scattering.setUniform1f("density", density);
        scattering.setUniform1f("weight", weight);
        scattering.setUniform2f("lightPositionOnScreen", lightPosition.x, lightPosition.y);
        scattering.setUniformTexture("firstPass", occluded, 0);
            glBegin(GL_QUADS);
                int x = 0;
                int y = 0;
                glTexCoord2f(x, y);
                glVertex2f(x, y);
            
                x = ofGetWidth();
                glTexCoord2f(x, y);
                glVertex2f(x, y);
            
                y = ofGetHeight();
                glTexCoord2f(x, y);
                glVertex2f(x, y);
                
                x = 0;
                glTexCoord2f(x, y);
                glVertex2f(x, y);
            
            glEnd();
        scattering.end();
    lightRays.end();
    
    thresholdFbo.begin();
    ofClear(0);    
        thresholdShader.begin();
        thresholdShader.setUniformTexture("tex0", firstPass, 0);
        thresholdShader.setUniform3f("thresholdRGB", threshR, threshG, threshB);
        thresholdShader.setUniform2f("dimensions", ofGetWidth(), ofGetHeight());
        thresholdShader.setUniform1i("flipXY", 1);
            firstPass.draw(0, 0);
        thresholdShader.end();    
    thresholdFbo.end();
    
    lensFlareFbo.begin();
    ofClear(0);
        flareShader.begin();
        flareShader.setUniformTexture("tex0", thresholdFbo, 0);
        flareShader.setUniform2f("dimensions", ofGetWidth(), ofGetHeight());
        flareShader.setUniform1i("nSamples", samples);
        flareShader.setUniform1f("flareDispersal", flareDispersal);
        flareShader.setUniform1f("flareHaloWidth", flareHaloWidth);
        flareShader.setUniform3fv("flareChromaticDistortion", flareChromaticDistortion.getPtr());
            thresholdFbo.draw(0, 0);
        flareShader.end();
    lensFlareFbo.end();
    
    blurredFbo.begin();
    ofClear(0);
        blurShader.begin(blurAmount);
            lensFlareFbo.draw(0, 0);
        blurShader.end();
    blurredFbo.end();
    
    lensFlareFbo.begin();
    ofClear(0);
        modulateTextureShader.begin();
        modulateTextureShader.setUniformTexture("tex0", blurredFbo, 0);
        modulateTextureShader.setUniformTexture("tex1", dirtImage, 1);
        modulateTextureShader.setUniform2f("tex0dim", blurredFbo.getWidth(), blurredFbo.getHeight());
        modulateTextureShader.setUniform2f("tex1dim", dirtImage.getWidth(), dirtImage.getHeight());
        modulateTextureShader.setUniform1f("amount", dirtAmount);
            blurredFbo.draw(0, 0);
        modulateTextureShader.end();
    lensFlareFbo.end();
    
    ofEnableAlphaBlending();
    glDisable(GL_DEPTH_TEST);
    lensFlareFbo.draw(0, 0);
    lightRays.draw(0, 0);
    firstPass.draw(0, 0);
    
#ifdef SAVE_FRAMES
    ofSaveScreen("frames/"+ofToString(ofGetFrameNum(), 0)+".bmp");
#endif
}
Ejemplo n.º 21
0
void ofApp::setup() {

	// SYSTEM
	ofSetLogLevel(OF_LOG_VERBOSE);
	ofHideCursor();
	ofSetFrameRate(60);
	
	// SCREEN
    ofEnableAlphaBlending();
    ofBackground(100);
    width = ofGetWindowWidth();
    height = ofGetWindowHeight();
    
    // STATE
    presenting = true;
    tooSunny = false;
    fboAge = 0;
    imageTimer = 0;
    imageMAX = 500;
    playState = 1;
    currentBrightness = 0;
    targetAlpha = 155;
	
    #ifdef INTERACTIVE
        // KINECT
        #ifdef 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);
        #else
            camera.setVerbose(true);
            camera.initGrabber(320, 240);
        #endif
    
        // CAPTURE SIZE
        int capture_width, capture_height;
        #ifdef KINECT
            capture_width = kinect.width;
            capture_height = kinect.height;
        #else
            capture_width = camera.width;
            capture_height = camera.height;
        #endif
        
        // OPENCV
        colorImg.allocate(capture_width, capture_height);
        grayImage.allocate(capture_width, capture_height);
        grayThreshNear.allocate(capture_width, capture_height);
        grayThreshFar.allocate(capture_width, capture_height);
        grayBg.allocate(capture_width, capture_height);
        grayDiff.allocate(capture_width, capture_height);
        closePoints.allocate(capture_width, capture_height, GL_RGBA32F_ARB);

        nearThreshold = 350;
        farThreshold = 112;
        bLearnBakground = true;
        threshold = 80;
        bThreshWithOpenCV = false;
        minBlob = 25; 
        maxBlob = (capture_width * capture_height)/2;
    
        // FBO & GLSL SHADER
        setupGL(width, height);
    #else
        playState = 2;
        imageMAX = 2500;
    #endif
    

	
    // XML ASSETS
    BASEPATH = "../../../MEDIA/";
    assets.loadFile("xml/assets.xml");
    if( assets.loadFile("xml/assets.xml") ) {
        ofLog(OF_LOG_NOTICE, "Loaded xml file !!! \n");
        loadFonts();
        loadArtists();
        loadAssets();
    }
    else {
        ofLog(OF_LOG_ERROR, "UNABLE to load xml file :( \n");
    }

    //  INDEX
    currentIndex = 0;
    updateCurrentIndex();

    // ASSETS
    brush.loadImage("mouse/brush.png");
	stamp.loadImage("logo/stamp_white2.png");
	demo.loadMovie(BASEPATH + "demo/studio_in_the_city_6_promo.mp4");
    
    // MEMORY
    checkMemory();

	cout << "Setup Is Done \n" << endl;
}
Ejemplo n.º 22
0
//--------------------------------------------------------------
void testApp::setup(){
	
    
    long size;
    char *buf;
    char *ptr;
    
    size = pathconf(".", _PC_PATH_MAX);
    if ((buf = (char *)malloc((size_t)size)) != NULL){
        ptr = getcwd(buf, (size_t)size);
    }
    cout << ptr << endl;
    
	ofSetVerticalSync(true);
	ofEnableAlphaBlending();
	
	parser.loadFromFiles();
	visualSystems.loadPresets();
	
	storyEngine.parser = &parser;
	storyEngine.visualSystems = &visualSystems;
	storyEngine.printDecisions = false;
	storyEngine.combinedClipsOnly = false;
	storyEngine.setup();
	
	vector<CloudsClip*> startingNodes = parser.getClipsWithKeyword("#start");
	srand(ofGetSeconds());
    cout << "starting node size is " << startingNodes.size() << endl;
    
	ofRandomuf();
    ofRandomuf();
    ofRandomuf();
    
    int startNode = ofRandomuf()*startingNodes.size();
    cout << "START NODE index is " << startNode << endl;
    
	CloudsAct* act = storyEngine.buildAct(run, startingNodes[ startNode ]);
	run.topicHistory = act->getAllTopics();
	run.clipHistory = act->getAllClips();
	cout << "** TRAVERSAL INCLUDES:" << endl;
	for(int i = 0; i < run.clipHistory.size(); i++){
		cout << "	** " << run.clipHistory[i]->getID() << endl;
	}
    
//	clusterMap.forceScreenResolution(1920, 1080);
	clusterMap.setup();
#ifdef OCULUS_RIFT
	if(CloudsVisualSystem::getOculusRift().isHD()){
		clusterMap.loadPresetGUISFromName("FollowTraverse_OculusHD");
	}
	else{
		clusterMap.loadPresetGUISFromName("FollowTraverse_OculusSD");
	}
#else
//	clusterMap.loadPresetGUISFromName("FollowTraverse_Screen");
    clusterMap.loadPresetGUISFromName("NavigationInterlude_Screen");
#endif

	clusterMap.setRun(run);
	clusterMap.setAct(act);
	clusterMap.buildEntireCluster(parser);
	clusterMap.allocateFlickerTexture();
	
//	clusterMap.autoTraversePoints = true;
	clusterMap.populateDummyQuestions();
    
	clusterMap.playSystem();
	
}
//--------------------------------------------------------------
void testApp::setup(){
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofSetLogLevel(OF_LOG_VERBOSE);
    ofSetVerticalSync(true);
    
    //  Default Settings
    //
    mode                = MODE_NORMAL;
    project             = NULL;
    statusEnergy        = 0;
    float   margin      = 64;
    string  sketchName  = "mySketch";
    
    ofBackground(230,230,230);
    logo.loadImage("images/ofw-logo.png");
    
    //  XML Settings
    //
    ofxXmlSettings XML;
    XML.loadFile("settings/projectGeneratorSettings.xml");
    appToRoot = XML.getValue("appToRoot", "../../../../");
    defaultLoc = XML.getValue("defaultNewProjectLocation", "apps/myApps");
    
    //-------------------------------------
    // calculate the bin path (../../../ on osx) and the sketch path (bin -> root - > defaultLoc)
    //-------------------------------------
    // if appToRoot is wrong, we have alot of issues.  all these paths are used in this project:
    //
#ifdef TARGET_OSX
    string binPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofFilePath::getCurrentWorkingDirectory(), "../../../"));
#else
    string binPath = ofFilePath::getCurrentExeDir();
#endif
    
    string ofRoot = ofFilePath::getAbsolutePath(ofFilePath::join(binPath, appToRoot));
    addonsPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot,"addons"));
    string sketchPath = ofFilePath::getAbsolutePath(ofFilePath::join(ofRoot, defaultLoc));
    
    convertWindowsToUnixPath(ofRoot);
    convertWindowsToUnixPath(addonsPath);
    convertWindowsToUnixPath(sketchPath);
    
    // there's some issues internally in OF with non unix paths for OF root
    //
    setOFRoot(ofRoot);
    
    //------------------------------------- GUI
    //
    
    //  load font and setup the buttons
    //
    font.loadFont("fonts/Inconsolata.otf", 14, true,false,false,0.3,90);
    titleFont.loadFont("fonts/Inconsolata.otf", 28, true,false,false,0.3,90);
    secondFont.loadFont("fonts/Inconsolata.otf", 11, true,false,false,0.3,90);
    
    //  Sketch button
    //
    textButton  *buttonName = new textButton();
    buttonName->font = &font;
    buttonName->secondFont = &secondFont;
    buttonName->prefix = "Name: ";
    buttonName->enableEditing();
	buttonName->topLeftAnchor.set(margin+12, 160+40); //set top button position - others are set relative to this.
    buttonName->setText(sketchName);
    buttonName->secondaryText = "<< CLICK TO CHANGE THE NAME";
    buttons.push_back(buttonName);
    
    //  Path Button
    //
    textButton  *buttonPath = new textButton();
    buttonPath->font = &font;
    buttonPath->secondFont = &secondFont;
    buttonPath->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonPath->deliminater = "/";
    buttonPath->prefix = "Path: ";
    buttonPath->setText(sketchPath);
    buttonPath->secondaryText = "<< CLICK TO CHANGE THE DIRECTORY";
    buttons.push_back(buttonPath);
    
    //  Platform Button
    //
    textButton  *buttonPlat = new textButton();
    buttonPlat->font = &font;
    buttonPlat->secondFont = &secondFont;
    buttonPlat->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonPlat->deliminater = ", ";
    buttonPlat->prefix = "Platforms: ";
    buttonPlat->secondaryText = "<< CLICK TO CHANGE THE PLATFORM";
    buttonPlat->setText("");
    buttons.push_back(buttonPlat);
    
    //  Addons Button
    //
    textButton  *buttonAddon = new textButton();
    buttonAddon->font = &font;
    buttonAddon->secondFont = &secondFont;
    buttonAddon->topLeftAnchor.set(buttons[ buttons.size() -1 ]->topLeftAnchor.x, buttons[ buttons.size() -1 ]->topLeftAnchor.y + buttons[ buttons.size() -1 ]->height + 20);
    buttonAddon->deliminater = ", ";
    buttonAddon->prefix = "Addons: ";
    buttonAddon->secondaryText = "<< CLICK TO SELECT ADDONS";
    buttonAddon->setText("");
    buttons.push_back(buttonAddon);
    
    for (int i = 0; i < buttons.size(); i++){
        buttons[i]->calculateRect();
    }
    
    //  Generate Button
    //
    generateButton.font = &font;
    generateButton.secondFont = &secondFont;
    generateButton.deliminater = ",";
    generateButton.prefix = "GENERATE PROJECT";
    generateButton.setText("");
    generateButton.bDrawLong = false;
    generateButton.topLeftAnchor.set(ofGetWidth() - buttons[0]->x - generateButton.width + 10 , ofGetHeight() - generateButton.height - 40);
    generateButton.calculateRect();
    
    //  Addon Button
    //
    backButton = generateButton;
    backButton.prefix = "BACK >>";
    backButton.setText("");
    backButton.bDrawLong = false;
    backButton.calculateRect();
    
    //  LOAD ADDONS
    //
    loadAddons();
    
    //  LOAD PLATFORMS
    //
    platformsList.set(64,12,350,500);
    platformsList.font = &font;
    platformsList.title = "Platforms";
    platformsList.addElement("windows (codeblocks)",ofGetTargetPlatform()==OF_TARGET_WINGCC);
	platformsList.addElement("windows (visualStudio)", ofGetTargetPlatform()==OF_TARGET_WINVS);
	platformsList.addElement("linux (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX);
	platformsList.addElement("linux64 (codeblocks)",ofGetTargetPlatform()==OF_TARGET_LINUX64);

    //#define MAKE_IOS
#ifdef MAKE_IOS
	platformsList.addElement("osx (xcode)",false);
	platformsList.addElement("ios (xcode)",true);
#else
    platformsList.addElement("osx (xcode)",ofGetTargetPlatform()==OF_TARGET_OSX);
	platformsList.addElement("ios (xcode)",ofGetTargetPlatform()==OF_TARGET_IPHONE);
#endif
    
    // update the platforms text in the platform button
    //
    buttons[2]->setText( platformsList.getSelectedAsString() );
}
Ejemplo n.º 24
0
//-------------------------------
void ofxControlPanel::draw() {
    if( hidden ) return;

    ofPushStyle();
    ofEnableAlphaBlending();

    float panelH = boundingBox.height;
    if( minimize ) {
        panelH = 20;
    }

    glPushMatrix();
    glTranslatef(boundingBox.x, boundingBox.y, 0);
    //draw the background
    ofFill();
    glColor4fv(bgColor.getColorF());
    ofRect(0, 0, boundingBox.width, panelH);

    //draw the outline
    ofNoFill();
    glColor4fv(outlineColor.getColorF());
    ofRect(0, 0, boundingBox.width, panelH);
    ofLine(0, 20, boundingBox.width, 20);
    glPopMatrix();

    ofRect(minimizeButton.x, minimizeButton.y, minimizeButton.width, minimizeButton.height);

    ofPushStyle();
    ofFill();

    if( saveDown )glColor4fv(fgColor.getSelectedColorF());
    else glColor4fv(fgColor.getColorF());

    ofRect(saveButton.x, saveButton.y, saveButton.width,saveButton.height);
    ofSetColor(255, 255, 255);
    if(bUseTTFFont) {
        guiTTFFont.drawString("save", saveButton.x + 3, saveButton.y + saveButton.height -4);
    }
    else {
        ofDrawBitmapString("save", saveButton.x + 3, saveButton.y + saveButton.height -3);
    }

    ofPopStyle();

    ofPushStyle();
    ofFill();

    if( restoreDown )glColor4fv(fgColor.getSelectedColorF());
    else glColor4fv(fgColor.getColorF());

    ofRect(restoreButton.x, restoreButton.y, restoreButton.width,restoreButton.height);
    ofSetColor(255, 255, 255);
    if(bUseTTFFont) {
        guiTTFFont.drawString("restore", restoreButton.x + 3, restoreButton.y + restoreButton.height -4);
    }
    else {
        ofDrawBitmapString("restore", restoreButton.x + 3, restoreButton.y + restoreButton.height -3);
    }
    ofPopStyle();


    ofPushMatrix();
    ofTranslate(2,0,0);
    glColor4fv(textColor.getColorF());
    guiBaseObject::renderText();
    ofPopMatrix();

    if( !minimize ) {

        //don't let gui elements go out of their panels
        glEnable(GL_SCISSOR_TEST);
        glScissor(boundingBox.x, ofGetHeight() - ( boundingBox.y + boundingBox.height - (-2 + topSpacing) ), boundingBox.width - borderWidth , boundingBox.height);

        for(int i = 0; i < (int) panelTabs.size(); i++) {
            if( i == selectedPanel) {
                ofPushStyle();
                ofFill();
                glColor4fv(fgColor.getSelectedColorF());
                ofRect(panelTabs[i].x, panelTabs[i].y, panelTabs[i].width, panelTabs[i].height);
                glColor4fv(outlineColor.getColorF());
                ofPopStyle();
            }
            glColor4fv(outlineColor.getColorF());
            ofNoFill();
            ofRect(panelTabs[i].x, panelTabs[i].y, panelTabs[i].width, panelTabs[i].height);
        }

        glPushMatrix();
        glTranslatef(hitArea.x, hitArea.y, 0);
        for(int i = 0; i < (int) panels.size(); i++) {
            if( i == selectedPanel )panels[i]->render();
        }
        glPopMatrix();

        glDisable(GL_SCISSOR_TEST);
    }

    ofPopStyle();
}
Ejemplo n.º 25
0
//--------------------------------------------------------------
void testApp::draw() {

	ofNoFill();
	ofSetColor(80,80,80);
	for (int i=0; i<2000; i+=snap) {
		ofLine(i,0,i,2000);
		ofLine(0,i,2000,i);
	}

	//draw groups
	ofEnableAlphaBlending();
	for (int i=0; i<groups.size(); i++)
	{	
		if (groups[i].active) {
			ofFill();
			ofSetColor(50,50,50,50);
			ofRect(groups[i].rect);
		}
	}
	ofDisableAlphaBlending();

	// clear stacking info

	stacks.clear();
	for (int i=0; i<objects.size(); i++) {
		objects[i].stacked = false;
	}

	// draw the objects

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

		// let's calculate stacking here...
		bool stacked = false;
		for (int j=0; j<i; j++)
		{
			if (i!=j) {
				if (objects[i].rect == objects[j].rect) {
					stacked = true;

					bool hit = false;

					for (int k=0; k<stacks.size(); k++) {
						if (stacks[k].rect == objects[i].rect) {
							if (!objects[i].stacked) {
								stacks[k].number++;
							}
							objects[i].stacked = true;
							hit = true;
							
						}
					}

					if (!hit) {
						stack s;
						s.rect = objects[i].rect;
						objects[i].stacked = true;
						stacks.push_back(s);
					}

				}
			}
		}
		if (stacked) {

			ofPoint p0 = ofPoint(objects[i].rect.x + 2, objects[i].rect.y + 2);
			ofPoint p1 = p0 + ofPoint(objects[i].rect.width, objects[i].rect.height);

			ofPoint A = p0;
			ofPoint B = ofPoint(p1.x, p0.y);
			ofPoint C = ofPoint(p1.x, p1.y-20);
			ofPoint D = ofPoint(p1.x-20, p1.y);
			ofPoint E = ofPoint(p0.x, p1.y);
			ofPoint F = ofPoint(p1.x-20, p1.y-20);

			ofFill();
			switch (objects[i].type) {
				case 1:
					ofSetColor(255,251,176);
					break;
				case 2:
					ofSetColor(176,227,255);
					break;
				case 3:
					ofSetColor(255,211,176);
					break;
				default:
					ofSetColor(192,192,192);
					break;
			}
			

			ofBeginShape();
			ofVertex(A);
			ofVertex(B);
			ofVertex(C);
			ofVertex(D);
			ofVertex(E);
			ofVertex(A);
			ofEndShape();

			ofNoFill();
			ofSetColor(32,32,32);		
			
			ofBeginShape();
			ofVertex(A);
			ofVertex(B);
			ofVertex(C);
			ofVertex(D);
			ofVertex(E);
			ofVertex(A);
			ofEndShape();
			ofBeginShape();
			ofVertex(C);
			ofVertex(D);
			ofVertex(F);
			ofVertex(C);
			ofEndShape();

		} else {
			ofFill();
			switch (objects[i].type) {
				case 1:
					ofSetColor(255,251,176);
					break;
				case 2:
					ofSetColor(176,227,255);
					break;
				case 3:
					ofSetColor(255,211,176);
					break;
				default:
					ofSetColor(192,192,192);
					break;
			}
			ofRect(objects[i].rect);
			ofNoFill();
			ofSetColor(32,32,32);
			ofRect(objects[i].rect);
		}

	}

	// draw stack indicators

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

		if (stacks[i].number>1) {

			char buf[255];

			sprintf(buf, "%d", stacks[i].number);

			int x = stacks[i].rect.x + stacks[i].rect.width - 30;
			int y = stacks[i].rect.y + stacks[i].rect.height - 4;

			ofSetColor(0,0,0);
			ofDrawBitmapString(buf, x, y);

		}

	

	}

}
Ejemplo n.º 26
0
//--------------------------------------------------------------
void testApp::draw(){

	ofFill();
	ofSetColor(0xe0be21);

	//------(a)--------------------------------------
	// 
	// 		draw a star
	//
	// 		use poly winding odd, the default rule
	//
	// 		info about the winding rules is here:
	//		http://glprogramming.com/red/images/Image128.gif
	// 
	ofSetPolyMode(OF_POLY_WINDING_ODD);	// this is the normal mode
	ofBeginShape();
		ofVertex(200,135);
		ofVertex(15,135);
		ofVertex(165,25);
		ofVertex(105,200);
		ofVertex(50,25);
	ofEndShape();
	
	
	//------(b)--------------------------------------
	// 
	// 		draw a star
	//
	// 		use poly winding nonzero
	//
	// 		info about the winding rules is here:
	//		http://glprogramming.com/red/images/Image128.gif
	// 
	ofSetColor(0xb5de10);
	ofSetPolyMode(OF_POLY_WINDING_NONZERO);
	ofBeginShape();
		ofVertex(400,135);
		ofVertex(215,135);
		ofVertex(365,25);
		ofVertex(305,200);
		ofVertex(250,25);
	ofEndShape();
	//-------------------------------------
	
	
	
	//------(c)--------------------------------------
	// 
	// 		draw a star dynamically
	//
	// 		use the mouse position as a pct
	//		to calc nPoints and internal point radius
	//
	float xPct = (float)(mouseX) / (float)(ofGetWidth());
	float yPct = (float)(mouseY) / (float)(ofGetHeight());
	int nTips = 5 + xPct * 60;
	int nStarPts = nTips * 2;
	float angleChangePerPt = TWO_PI / (float)nStarPts;
	float innerRadius = 0 + yPct*80;
	float outerRadius = 80;
	float origx = 525;
	float origy = 100;
	float angle = 0;
	
	ofSetColor(0xa16bca);
	ofBeginShape();
	for (int i = 0; i < nStarPts; i++){
		if (i % 2 == 0) {
			// inside point:
			float x = origx + innerRadius * cos(angle);
			float y = origy + innerRadius * sin(angle);
			ofVertex(x,y);
		} else {
			// outside point
			float x = origx + outerRadius * cos(angle);
			float y = origy + outerRadius * sin(angle);
			ofVertex(x,y);
		}
		angle += angleChangePerPt;
	}
	ofEndShape();
	//-------------------------------------
	
	//------(d)--------------------------------------
	// 
	// 		poylgon of random points
	//
	// 		lots of self intersection, 500 pts is a good stress test
	// 
	// 
	ofSetColor(0x0cb0b6);
	ofSetPolyMode(OF_POLY_WINDING_ODD);
	ofBeginShape();
	for (int i = 0; i < 10; i++){
		ofVertex(ofRandom(650,850), ofRandom(20,200));
	}
	ofEndShape();
	//-------------------------------------
	
	
	//------(e)--------------------------------------
	// 
	// 		use sin cos and time to make some spirally shape
	//
	glPushMatrix();
		glTranslatef(100,300,0);
		ofSetColor(0xff2220);
		ofFill();
		ofSetPolyMode(OF_POLY_WINDING_ODD);
		ofBeginShape();
		float angleStep 	= TWO_PI/(100.0f + sin(ofGetElapsedTimef()/5.0f) * 60); 
		float radiusAdder 	= 0.5f;
		float radius 		= 0;
		for (int i = 0; i < 200; i++){
			float anglef = (i) * angleStep;
			float x = radius * cos(anglef);
			float y = radius * sin(anglef); 
			ofVertex(x,y);
			radius 	+= radiusAdder; 
		}
		ofEndShape(OF_CLOSE);
	glPopMatrix();
	//-------------------------------------
	
	//------(f)--------------------------------------
	// 
	// 		ofCurveVertex
	// 
	// 		because it uses catmul rom splines, we need to repeat the first and last 
	// 		items so the curve actually goes through those points
	//

	ofSetColor(0x2bdbe6);
	ofBeginShape();
	
		for (int i = 0; i < nCurveVertexes; i++){
			
			
			// sorry about all the if/states here, but to do catmull rom curves
			// we need to duplicate the start and end points so the curve acutally 
			// goes through them.
			
			// for i == 0, we just call the vertex twice
			// for i == nCurveVertexes-1 (last point) we call vertex 0 twice
			// otherwise just normal ofCurveVertex call
			
			if (i == 0){
				ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0
				ofCurveVertex(curveVertices[0].x, curveVertices[0].y); // we need to duplicate 0 for the curve to start at point 0
			} else if (i == nCurveVertexes-1){
				ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
				ofCurveVertex(curveVertices[0].x, curveVertices[0].y);	// to draw a curve from pt 6 to pt 0
				ofCurveVertex(curveVertices[0].x, curveVertices[0].y);	// we duplicate the first point twice
			} else {
				ofCurveVertex(curveVertices[i].x, curveVertices[i].y);
			}
		}
		
	ofEndShape();
	
	
	// show a faint the non-curve version of the same polygon:
	ofEnableAlphaBlending();
		ofNoFill();
		ofSetColor(0,0,0,40);
		ofBeginShape();
			for (int i = 0; i < nCurveVertexes; i++){
				ofVertex(curveVertices[i].x, curveVertices[i].y);
			}
		ofEndShape(true);
		
		
		ofSetColor(0,0,0,80);
		for (int i = 0; i < nCurveVertexes; i++){
			if (curveVertices[i].bOver == true) ofFill();
			else ofNoFill();
			ofCircle(curveVertices[i].x, curveVertices[i].y,4);
		}
	ofDisableAlphaBlending();
	//-------------------------------------
	
	
	//------(g)--------------------------------------
	// 
	// 		ofBezierVertex
	// 
	// 		with ofBezierVertex we can draw a curve from the current vertex
	//		through the the next three vertexes we pass in.
	//		(two control points and the final bezier point)
	//		
	
	float x0 = 500;
	float y0 = 300;
	float x1 = 550+50*cos(ofGetElapsedTimef()*1.0f);
	float y1 = 300+100*sin(ofGetElapsedTimef()/3.5f);
	float x2 = 600+30*cos(ofGetElapsedTimef()*2.0f);
	float y2 = 300+100*sin(ofGetElapsedTimef());
	float x3 = 650;
	float y3 = 300;
	
	
	
	ofFill();
	ofSetColor(0xFF9933);
	ofBeginShape();
	ofVertex(x0,y0);
	ofBezierVertex(x1,y1,x2,y2,x3,y3);
	ofEndShape();
	
	
	ofEnableAlphaBlending();
		ofFill();
		ofSetColor(0,0,0,40);
		ofCircle(x0,y0,4);
		ofCircle(x1,y1,4);
		ofCircle(x2,y2,4);
		ofCircle(x3,y3,4);
	ofDisableAlphaBlending();
	
	
	
	//------(h)--------------------------------------
	// 
	// 		holes / ofNextContour
	// 
	// 		with ofNextContour we can create multi-contour shapes
	// 		this allows us to draw holes, for example... 
	//
	ofFill();
	ofSetColor(0xd3ffd3);
	ofRect(80,480,140,70);
	ofSetColor(0xff00ff);
	
	ofBeginShape();
		
		ofVertex(100,500);
		ofVertex(180,550);
		ofVertex(100,600);
		
		ofNextContour(true);
		
		ofVertex(120,520);
		ofVertex(160,550);
		ofVertex(120,580);
		
	ofEndShape(true);
	//-------------------------------------
	
	
	//------(i)--------------------------------------
	// 
	// 		CSG / ofNextContour
	// 
	// 		with different winding rules, you can even use ofNextContour to 
	// 		perform constructive solid geometry 
	// 		
	// 		be careful, the clockwiseness or counter clockwisenss of your multiple
	// 		contours matters with these winding rules.
	//
	// 		for csg ideas, see : http://glprogramming.com/red/chapter11.html
	// 
	// 		info about the winding rules is here:
	//		http://glprogramming.com/red/images/Image128.gif
	// 
	ofNoFill();
	
	
	glPushMatrix();
	
	ofSetPolyMode(OF_POLY_WINDING_ODD);
	
	ofBeginShape();
		
		ofVertex(300,500);
		ofVertex(380,550);
		ofVertex(300,600);
		
		ofNextContour(true);
		
		for (int i = 0; i < 20; i++){
			float anglef = ((float)i / 19.0f) * TWO_PI;
			float x = 340 + 30 * cos(anglef);
			float y = 550 + 30 * sin(anglef); 
			ofVertex(x,y);
			radius 	+= radiusAdder; 
		}
		

	ofEndShape(true);
	
	glTranslatef(100,0,0);
	
	ofSetPolyMode(OF_POLY_WINDING_NONZERO);	
	ofBeginShape();
		
		ofVertex(300,500);
		ofVertex(380,550);
		ofVertex(300,600);
		
		ofNextContour(true);
		
		for (int i = 0; i < 20; i++){
			float anglef = ((float)i / 19.0f) * TWO_PI;
			float x = 340 + 30 * cos(anglef);
			float y = 550 + 30 * sin(anglef); 
			ofVertex(x,y);
			radius 	+= radiusAdder; 
		}
		
	ofEndShape(true);
	
	glTranslatef(100,0,0);
	ofSetPolyMode(OF_POLY_WINDING_ABS_GEQ_TWO);
	ofBeginShape();
		ofVertex(300,500);
		ofVertex(380,550);
		ofVertex(300,600);
		ofNextContour(true);
		
		for (int i = 0; i < 20; i++){
			float anglef = ((float)i / 19.0f) * TWO_PI;
			float x = 340 + 30 * cos(anglef);
			float y = 550 + 30 * sin(anglef); 
			ofVertex(x,y);
			radius 	+= radiusAdder; 
		}
		
		
	ofEndShape(true);
	
	glPopMatrix();
	//-------------------------------------
	
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(a) star\nwinding rule odd", 20,210);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(b) star\nwinding rule nonzero", 220,210);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(c) dynamically\ncreated shape", 420,210);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(d) random points\npoly", 670,210);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(e) fun with sin/cos", 20,410);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(f) ofCurveVertex\nuses catmull rom\nto make curved shapes", 220,410);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(g) ofBezierVertex\nuses bezier to draw curves", 460,410);
	
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(h) ofNextContour\nallows for holes", 20,610);
	
	ofSetColor(0x000000);
	ofDrawBitmapString("(i) ofNextContour\ncan even be used for CSG operations\nsuch as union and intersection", 260,620);
	
	
}
Ejemplo n.º 27
0
void ofApp::drawLetters(){
    ofEnableAlphaBlending();
    //first 5 seconds draw letters title
    if (counterLettersTitle<introLength*FRAME_RATE) {
        //draw title facade
        if(counterLettersTitle<FRAME_RATE){
            blendInfoFacade+=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        }
        //blend out
        else if(counterLettersTitle>FRAME_RATE*(introLength-1)){
            blendInfoFacade-=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        } else{
            ofSetColor(255);
        }
        
        lettersTitleFacade.draw(37, 259);
        
        //draw title LED2
        if(counterLettersTitle<FRAME_RATE){
            blendInfoLED2+=8;
            ofSetColor(255, 255, 255, blendInfoLED2);
        }else{
            ofSetColor(255);
        }
        ofPushMatrix();
        ofTranslate(508, 77);
        
        lettersTitleLED2.draw(0,0);
        //draw letters LED already
        int noOfLetters=(int)allLetters.size();
        
        if(noOfLetters>0){
            allLetters[currLetterImgNo1].drawLED2(currLetterImgNo1);
        }
        if(noOfLetters>1){
            allLetters[currLetterImgNo2].drawLED2(currLetterImgNo2);
        }
        if(noOfLetters>2){
            allLetters[currLetterImgNo3].drawLED2(currLetterImgNo3);
        }
        if(noOfLetters>3){
            allLetters[currLetterImgNo4].drawLED2(currLetterImgNo4);
        }
        if(noOfLetters>4){
            allLetters[currLetterImgNo5].drawLED2(currLetterImgNo5);
        }

        
        ofPopMatrix();

    } /*else if(counterLettersTitle==introLength*FRAME_RATE){
        blendInfo=0;
    } */else{
        //facade
        //blend in
        if(counterPostcardsAndLetters<FRAME_RATE){
            blendInfoFacade+=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        }
        //blend out
        else if(counterPostcardsAndLetters>FRAME_RATE*(lengthLetters-1)){
            blendInfoFacade-=8;
            ofSetColor(255, 255, 255, blendInfoFacade);
        } else{
            ofSetColor(255);
        }
        //draw letters Sao Paulo
        int noOfLetters=(int)allLetters.size();
        
        if(noOfLetters>0){
            allLetters[currLetterImgNo1].drawFacade(currLetterImgNo1);
        }
        if(noOfLetters>1){
            allLetters[currLetterImgNo2].drawFacade(currLetterImgNo2);
        }
        if(noOfLetters>2){
            allLetters[currLetterImgNo3].drawFacade(currLetterImgNo3);
        }
        if(noOfLetters>3){
            allLetters[currLetterImgNo4].drawFacade(currLetterImgNo4);
        }
        if(noOfLetters>4){
            allLetters[currLetterImgNo5].drawFacade(currLetterImgNo5);
        }
        
        //draw title on LED2

        //blend out
        if(counterPostcardsAndLetters>FRAME_RATE*(lengthLetters-1)){
            blendInfoLED2-=8;
            ofSetColor(255, 255, 255, blendInfoLED2);
        } else{
            ofSetColor(255);
        }

        ofPushMatrix();
        ofTranslate(508, 77);
        //title LED2
        lettersTitleLED2.draw(0,0);
        //draw letters LED
        if(noOfLetters>0){
            allLetters[currLetterImgNo1].drawLED2(currLetterImgNo1);
        }
        if(noOfLetters>1){
            allLetters[currLetterImgNo2].drawLED2(currLetterImgNo2);
        }
        if(noOfLetters>2){
            allLetters[currLetterImgNo3].drawLED2(currLetterImgNo3);
        }
        if(noOfLetters>3){
            allLetters[currLetterImgNo4].drawLED2(currLetterImgNo4);
        }
        if(noOfLetters>4){
            allLetters[currLetterImgNo5].drawLED2(currLetterImgNo5);
        }

        ofPopMatrix();


    }
    
    ofDisableAlphaBlending();
}
Ejemplo n.º 28
0
//--------------------------------------------------------------
void testApp::draw(){
	
	// Main image
	ofSetColor(0xffffff);
	grayImage.draw(0, 0);
	ofSetColor(0x666666);	
	ofDrawBitmapString(ofToString(artk.getNumDetectedMarkers()) + " marker(s) found", 10, 20);

	// Threshold image
	ofSetColor(0xffffff);
	grayThres.draw(640, 0);
	ofSetColor(0x666666);	
	ofDrawBitmapString("Threshold: " + ofToString(threshold), 650, 20);
	ofDrawBitmapString("Use the Up/Down keys to adjust the threshold", 650, 40);

	// ARTK draw
	// An easy was to see what is going on
	// Draws the marker location and id number
	artk.draw(640, 0);
	
	// ARTK 2D stuff
	// See if marker ID '64' was detected
	// and draw blue corners on that marker only
	int myIndex = artk.getMarkerIndex(64);
	
	if(myIndex >= 0) {	
		// Get the corners
		vector<ofPoint> corners;
		artk.getDetectedMarkerBorderCorners(myIndex, corners);
		// Can also get the center like this:
		// ofPoint center = artk.getDetectedMarkerCenter(myIndex);
		ofSetHexColor(0x0000ff);
		for(int i=0;i<corners.size();i++) {
			ofCircle(corners[i].x, corners[i].y, 10);
		}
	}
	
	// Homography
	// Here we feed in the corners of an image and get back a homography matrix
	ofMatrix4x4 Homography = artk.getHomography(myIndex, displayImageCorners);
	// We apply the matrix and then can draw the image distorted on to the marker
	ofPushMatrix();
	glMultMatrixf(Homography.getPtr());
	ofSetHexColor(0xffffff);
	colorImage.draw(0, 0);
	ofPopMatrix();
	
	
	// ARTK 3D stuff
	// This is another way of drawing objects aligned with the marker
	// First apply the projection matrix once
	
	ofPushMatrix();

		artk.applyProjectionMatrix();
		// Find out how many markers have been detected
		int numDetected = artk.getNumDetectedMarkers();
		ofEnableAlphaBlending();
		// Draw for each marker discovered
		for(int i=0; i<numDetected; i++) {
			
			// Set the matrix to the perspective of this marker
			// The origin is in the middle of the marker	
			artk.applyModelMatrix(i);		
			
			// Draw a stack of rectangles by offseting on the z axis
			ofNoFill();
			ofEnableSmoothing();
			ofSetColor(255, 255, 0, 50);	

			for(int i=0; i<10; i++) {		
				ofRect(-25, -25, 50, 50);
				ofTranslate(0, 0, i*1);
			}
			
		}
	ofPopMatrix();

}
void movementLineDOFScene::draw(){
	
	
	point3d * points = pointSet.points;
	
	ofEnableAlphaBlending();
	
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0);
	
	// super helpful: http://pmviewer.sourceforge.net/method.php
	glEnable(GL_POINT_SMOOTH);
	glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
	
		
	
	
	glPointSize(1);
	
	glPushMatrix();
	
	glTranslatef(ofGetWidth()/2, ofGetHeight()/2,-2000);
	glRotatef(control.rotateY,-1,0,0);
	glRotatef(control.rotateX,0,1,0);
	
	
	//--------
	//
	
	
	
	
	dofLineShader.begin();
	

	glDisable(GL_DEPTH);
	glDisable(GL_DEPTH_TEST);
	
	
	
	float rgbBrightness = panel.getValueF("rgbBrightness");
	float pointBrightness = panel.getValueF("point_brightness");
	float aberration		= panel.getValueF("aberration");
	float aperture		= panel.getValueF("aperture");
	dofLineShader.setUniform("focusDistance", panel.getValueF("focus_offset"));
	dofLineShader.setUniform("aperture", aperture);
	dofLineShader.setUniform("pointBrightness", pointBrightness);
	dofLineShader.setUniform("rgbBrightness", rgbBrightness);
	dofLineShader.setUniform("maxPointSize", panel.getValueF("maxPointSize"));
	
	
	float v[4];
	
	
	for(int i = 0; i < 144; i+= 2) {
		bool bInRun = false;
		for(int j = 0; j < 176; j++) {
			int n = (j  + i * 176);
			if (points[n].bVisibleThisFrame == true){
				if (bInRun == false){
					bInRun = true;	
					glBegin(GL_TRIANGLE_STRIP);
				}
				//ofSetColor(points[n].color.x * 255.0, points[n].color.y * 255.0, points[n].color.z * 255.0, 200.0);
				int n0 = n;
				glNormal3f(1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
				glNormal3f(-1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
			
			
			} else {
				if (bInRun == true){
					glEnd();	
					bInRun = false;
				}
			}
		}
		if (bInRun == true){
			glEnd();	
			bInRun = false;
		}
	}
	
	
	glTranslatef(-1500, 0, 0);
	
	for(int i = 0; i < 144; i+= 2) {
		bool bInRun = false;
		for(int j = 0; j < 176; j++) {
			int n = (j  + i * 176);
			if (points[n].bVisibleThisFrame == true){
				if (bInRun == false){
					bInRun = true;	
					glBegin(GL_TRIANGLE_STRIP);
				}
				//ofSetColor(points[n].color.x * 255.0, points[n].color.y * 255.0, points[n].color.z * 255.0, 200.0);
				int n0 = n;
				glNormal3f(1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
				glNormal3f(-1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
				
				
			} else {
				if (bInRun == true){
					glEnd();	
					bInRun = false;
				}
			}
		}
		if (bInRun == true){
			glEnd();	
			bInRun = false;
		}
	}
	
	
	glTranslatef(3000, 0, 0);
	
	for(int i = 0; i < 144; i+= 2) {
		bool bInRun = false;
		for(int j = 0; j < 176; j++) {
			int n = (j  + i * 176);
			if (points[n].bVisibleThisFrame == true){
				if (bInRun == false){
					bInRun = true;	
					glBegin(GL_TRIANGLE_STRIP);
				}
				//ofSetColor(points[n].color.x * 255.0, points[n].color.y * 255.0, points[n].color.z * 255.0, 200.0);
				int n0 = n;
				glNormal3f(1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
				glNormal3f(-1,0,0);
				glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
				glVertex3f(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
				
				
				
			} else {
				if (bInRun == true){
					glEnd();	
					bInRun = false;
				}
			}
		}
		if (bInRun == true){
			glEnd();	
			bInRun = false;
		}
	}
	
		
	
	
	//
//	int step = 1; //(int)ofMap(sin(ofGetElapsedTimef()*20), -1,1, 1,8);
//	for(int i = 0; i < 144; i+= step) {
//		bool bInRun = false;
//		
//		
//		ofxVec3f upNormal;
//		ofxVec3f sideNormal;
//		
//		
//		glBegin(GL_TRIANGLE_STRIP);
//		
//		
//		
//		//glBegin(GL_LINE_STRIP);
//		for(int j = 0; j < 176-1; j++) {
//			int n0 = (j  + i * 176);
//			int n1 = ((j+1)  + i * 176);
//			
//			
//			
//			
//			
//			
//			//for(int i = 0; i < n-1; i++) {
//				// make left/bottom vertex
//				
//			
//				ofxVec3f diff = points[n1].pos - points[n0].pos;
//				diff.normalize();
//				
//				//dofLineShader.setUniform("nextVertex", points[n1].pos.x, points[n1].pos.y, points[n1].pos.z);
//			
//			
//				//glVertexAttrib1f(side, -1);
//				//dofLineShader.setAttribute("nextVertex", 1.0f, 0.0f, 0.0f);
//			
//			v[0] = points[n0].color.x;
//			v[1] = points[n0].color.y;
//			v[2] = points[n0].color.z;
//			v[3] = 1.0;
//			
//			//ofSetColor(points[n].color.x*255.0,points[n].color.y*255.0,points[n].color.z*255.0, 160);
//			//glColor4fv(v);
//			
//			
//			
//
//			glNormal3f(1,0,0);
//			glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
//			glVertex3f(points[n0].pos.x, points[n0].pos.y, points[n0].pos.z);
//			
//			
//				//dofLineShader.setAttribute("sideAA", 1.0f);
//			glNormal3f(-1,0,0);
//			glColor4f(points[n0].color.x,points[n0].color.y,points[n0].color.z,1);
//			//glColor4fv(v);
//				//glTexCoord3f(points[n1].pos.x, points[n1].pos.y, points[n1].pos.z);
//								//dofLineShader.setUniform("sideAA", 3.0f);
//				//make right/top vertex
//				//glVertexAttrib1f(side, +1);
//				//glVertexAttrib3f(nextVertex, points[i+1].x, points[i+1].y, points[i+1].z);
//				glVertex3f(points[n0].pos.x, points[n0].pos.y, points[n0].pos.z);
//			
//			//}
//			
//			
//			//
////			//  a
//////			b c d
//////			  e
////			
////			ofxVec3f ptsa[5];	
////			ofxVec3f ptsb[5];	
////			
////			ofxVec3f pta; pta.set(points[n0].pos.x - pointSet.midPointSmoothed.x, points[n0].pos.y - pointSet.midPointSmoothed.y, points[n0].pos.z - pointSet.midPointSmoothed.z);
////			ofxVec3f ptb; ptb.set(points[n1].pos.x - pointSet.midPointSmoothed.x, points[n1].pos.y - pointSet.midPointSmoothed.y, points[n1].pos.z - pointSet.midPointSmoothed.z);
////			
////			//printf("%f %f %f %f %f %f \n", pta.x, pta.x, pta.z, ptb.x, ptb.y, ptb.z);
////			
////			ofxVec3f diff = ptb-pta;
////			diff.normalize();
////			ofxVec3f up;
////			up.set(0,1,0);
////			ofxVec3f side;
////			side.set(0,0,1);
////			
////			
////			ofxVec3f oldUpNormal;
////			ofxVec3f oldSideNormal; 
////			if (j != 0){
////				oldUpNormal = upNormal;
////				oldSideNormal = sideNormal;
////			}
////			
////			ofxVec3f upNormal = diff.getCrossed(up);
////			ofxVec3f sideNormal = diff.getCrossed(side);
////			if (j == 0){
////				oldUpNormal = upNormal;
////				oldSideNormal = sideNormal;
////			}
////			
////			
////			ptsa[0] = pta + upNormal *0.0;
////			ptsa[1] = pta + sideNormal*0.0;
////			ptsa[2] = pta;
////			ptsa[3] = pta - sideNormal *0.0;
////			ptsa[4] = pta - upNormal *0.0;
////			
////			
////			ptsb[0] = ptb + upNormal *0.0;
////			ptsb[1] = ptb + sideNormal*0.0;
////			ptsb[2] = ptb;
////			ptsb[3] = ptb - sideNormal *0.0;
////			ptsb[4] = ptb - upNormal *0.0;
////			
////			//draw two quads.  use color to represent which direction to distort this point! 
////			
////			//
//////			glBegin(GL_LINES);
//////			glVertex3f(pta.x, pta.y, pta.z);
//////			glVertex3f(ptb.x, ptb.y, ptb.z);
//////			
//////			glEnd();
////			
////			glBegin(GL_QUADS);
////			
////			glNormal3f(oldSideNormal.x, oldSideNormal.y, oldSideNormal.z);
////			glVertex3f(ptsa[1].x, ptsa[1].y, ptsa[1].z);
////			
////			glNormal3f(-oldSideNormal.x, -oldSideNormal.y, -oldSideNormal.z);
////			glVertex3f(ptsa[3].x, ptsa[3].y, ptsa[3].z);
////			
////			glNormal3f(-sideNormal.x, -sideNormal.y, -sideNormal.z);
////			glVertex3f(ptsb[3].x, ptsb[3].y, ptsb[3].z);
////			
////			glNormal3f(sideNormal.x, sideNormal.y, sideNormal.z);
////			glVertex3f(ptsb[1].x, ptsb[1].y, ptsb[1].z);
////			
////			
////			glEnd();
//			
//			
//			//glBegin(GL_QUADS);
////			
////			glNormal3f(oldUpNormal.x, oldUpNormal.y, oldUpNormal.z);
////			glVertex3f(ptsa[0].x, ptsa[0].y, ptsa[0].z);
////			
////			glNormal3f(-oldUpNormal.x, -oldUpNormal.y, -oldUpNormal.z);
////			glVertex3f(ptsa[4].x, ptsa[4].y, ptsa[4].z);
////			
////			
////			glNormal3f(-upNormal.x, -upNormal.y, -upNormal.z);
////			glVertex3f(ptsb[4].x, ptsb[4].y, ptsb[4].z);
////			
////			glNormal3f(upNormal.x, upNormal.y, upNormal.z);
////			glVertex3f(ptsb[0].x, ptsb[0].y, ptsb[0].z);
////
////			glEnd();
////			
//			
//			
//			//
////			
////			//float pctz = ( points[n].pos.z - pointSet.bottom.z) / (pointSet.top.z - pointSet.bottom.z);
////			//pctz = powf(pctz, 3.0);
////			//int clr = ofMap(pctz, 0,1,50, 255);
////			
////			if (points[n].bVisibleThisFrame == true){
////				ofSetColor(200,200,200,100);
////				glVertex3f(points[n].pos.x - pointSet.midPointSmoothed.x, points[n].pos.y - pointSet.midPointSmoothed.y, points[n].pos.z - pointSet.midPointSmoothed.z);
////				
////			} else {
////				ofSetColor(200,200,200,100);
////				glVertex3f(points[n].pos.x - pointSet.midPointSmoothed.x, points[n].pos.y - pointSet.midPointSmoothed.y,  points[n].pos.z - pointSet.midPointSmoothed.z);
////				
////				
////			}
//			
//		}
//		//glEnd();	
//		glEnd();
//		
//	}
	
	dofLineShader.end();
	
	//--------
	
	
	ofEnableAlphaBlending();
	ofSetColor(255,255,255,50);
	if (control.bDrawBox) ofxLineBox(pointSet.midpt.x - pointSet.midPointSmoothed.x, pointSet.midpt.y - pointSet.midPointSmoothed.y, pointSet.midpt.z- pointSet.midPointSmoothed.z, pointSet.top.x-pointSet.bottom.x, pointSet.top.y-pointSet.bottom.y, pointSet.top.z -pointSet.bottom.z);
	
	glPopMatrix();
	
	glDisable(GL_DEPTH);
	glDisable(GL_DEPTH_TEST);
	
	
	panel.draw();
	
	//flow.draw(176*3, 144*3);
	
}
Ejemplo n.º 30
0
void ofx2DFormMapping::draw(bool show_source) {

	ofSetColor(42);
	ofFill();
	ofDrawRectangle(this->getPosition().x, this->getPosition().y, this->getWidth(), this->getHeight()-2);

	ofxPanel::draw();

	if(show_source) {
		//ofDrawRectangle(mapping_rect_src);
		if(source_bg) {
			ofSetColor(255,60);
			source_bg->draw(
						mapping_rect_src.x,
						mapping_rect_src.y,
						mapping_rect_src.width,
						mapping_rect_src.height);
		}
		else {
			ofSetColor(0,0,0,100);
			ofFill();
			ofDrawRectangle(mapping_rect_src);
		}
	}

	ofEnableAlphaBlending();

	ofSetLineWidth(2);

	//draw dst

	if(!direct_edit) {
		mapping_front.begin();
		ofClear(0,0,0,0);
		ofTranslate(mapping_margin, mapping_margin);

		ofPushMatrix();
		ofTranslate(-mapping_rect_dst.getPosition());

		//ZOOM TRANSLATION

		translation_dst = zoom_point-zoom_point_scaled+zoom_point_offset;
		if(translation_dst.x > 0) translation_dst.x = 0;
		if(translation_dst.y > 0) translation_dst.y = 0;
		if(translation_dst.x < -addZoom(mapping_rect_dst.getWidth())+mapping_rect_dst.getWidth())
			translation_dst.x = -addZoom(mapping_rect_dst.getWidth())+mapping_rect_dst.getWidth();
		if(translation_dst.y < -addZoom(mapping_rect_dst.getHeight())+mapping_rect_dst.getHeight())
			translation_dst.y = -addZoom(mapping_rect_dst.getHeight())+mapping_rect_dst.getHeight();
		ofTranslate(translation_dst);

		ofSetColor(255,160);
		mapping_bg->draw(
					mapping_rect_dst.x,
					mapping_rect_dst.y,
					addZoom(mapping_rect_dst.width),
					addZoom(mapping_rect_dst.height));

	}

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

//        //draw dst rectangles

//        ofNoFill();
//        ofSetColor(80,130,150);

//        ofBeginShape();
//        for(unsigned int j = 0; j < shapes[i].dst.size(); j++) {
//            ofVertex(shapes[i].dst[j]);
//        }
//        ofEndShape(true);

		//draw shape lines and fillings

		for(int j = 0; j < 2; j++) {
			if(j == 0) {
				ofFill();
				ofSetColor(shapes[i].color,40);
			}
			else {
				ofNoFill();
				if(direct_edit) {
					ofSetColor(255);
				}
				else {
					ofSetColor(shapes[i].color,255);
				}

			}
			if(!(j == 0 && direct_edit)) {
				ofBeginShape();
				for(unsigned int j = 0; j < shapes[i].polyline.size(); j++) {
					ofVertex(addZoom(shapes[i].polyline[j].x-mapping_rect_dst.x)+mapping_rect_dst.x,
							 addZoom(shapes[i].polyline[j].y-mapping_rect_dst.y)+mapping_rect_dst.y);
				}
				ofEndShape(true);
			}
		}

		//draw dragging points
		ofSetColor(255,255,255,200);
		if(parent_projector->getMappingObject(i)->editable) {
			for(unsigned int j = 0; j < shapes[i].polyline.size(); j++) {
				if (shapes[i].polyline[j].bOver) ofFill();
				else ofNoFill();
				ofDrawCircle(addZoom(shapes[i].polyline[j]-mapping_rect_dst.getPosition())+mapping_rect_dst.getPosition(),6);
			}
		}

	}

	if(!direct_edit) {
		ofPopMatrix();
		mapping_front.end();
		mapping_front.draw(mapping_rect_dst.getPosition()-ofPoint(mapping_margin, mapping_margin), mapping_front.getWidth(), mapping_front.getHeight());
	}

	//draw src

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

		ofNoFill();
		ofSetColor(shapes[i].color,255);
		ofBeginShape();

		for(unsigned int j = 0; j < shapes[i].src.size(); j++) {
			ofVertex(shapes[i].src[j].x, shapes[i].src[j].y);
		}
		ofEndShape(true);

		//draw dragging points
		ofSetColor(255,255,255,200);
		if(parent_projector->getMappingObject(i)->editable) {
			for(unsigned int j = 0; j < shapes[i].src.size(); j++) {

				if (shapes[i].src[j].bOver) ofFill();
				else ofNoFill();
				if(j%2==0)
					ofDrawCircle(shapes[i].src[j].x, shapes[i].src[j].y,6);

			}
		}

	}

}