示例#1
0
文件: menu.cpp 项目: serman/muncyt
//--------------------------------------------------------------
void menu::draw() {
	ofBackground(ofColor::black);



	// clear fbos
	if(bDrawFbos) {
		ofSetColor(255,255,255);
		
		fbo1.begin();	ofBackground(0,0,0); ofEnableAlphaBlending();	fbo1.end();
		fbo2.begin();	ofBackground(0,0,0); ofEnableAlphaBlending();	fbo2.end();
		fbo3.begin();	ofBackground(0,0,0); ofEnableAlphaBlending();	fbo3.end();
		fbo4.begin();	ofBackground(0,0,0); ofEnableAlphaBlending();	fbo4.end();	
		
		draw4Forces_fbos();
		
		fbo1.begin();	ofDisableAlphaBlending();	fbo1.end();
		fbo2.begin();	ofDisableAlphaBlending();	fbo2.end();
		fbo3.begin();	ofDisableAlphaBlending();	fbo3.end();
		fbo4.begin();	ofDisableAlphaBlending();	fbo4.end();
		
		fbo1.draw(centroScreen.x, centroScreen.y);
		fbo2.draw(centroScreen.x-fbo2.getWidth(), centroScreen.y);
		fbo3.draw(centroScreen.x-fbo3.getWidth(), centroScreen.y-fbo3.getHeight());
		fbo4.draw(centroScreen.x, centroScreen.y-fbo4.getHeight());
		
	}	
	else {
		if(bDraw4Forces) {
            ofEnableAlphaBlending();
			draw4Forces();
            ofDisableAlphaBlending();
		}
		else {
             ofEnableAlphaBlending();
			draw2Colors();
              ofDisableAlphaBlending();
		}
	}


    // Botones para TUIO
    touchElements.draw();
	
	// TUIOS
	//    tuioClient.drawCursors();	
//    ofPushMatrix(); //colocamos el canvas en su posicion centrada
//	ofTranslate((ofGetWidth()-W_WIDTH)/2, 0);
    hands.draw();
//	ofPopMatrix();
	
	ofPushStyle();
	borde.draw();
	ofPopStyle();
	
	ofPushStyle();
	string info = "";
	info += "Press [c] for circles\n";
	info += "Press [b] for blocks\n";
	info += "(4) draw 4Forces: "+ofToString(bDraw4Forces)+"\n";
	info += "(r) Modo Fuerza Color: "+ofToString(fRed)+"\n";
	info += "(f) Modo FBOs: "+ofToString(bDrawFbos)+"\n";
	info += "(d) Fuerza Densidad: "+ofToString(swFuerzaDensidad)+"\n";
	info += "(m) mousePressed: " + ofToString(isMousePressed)+"\n";
	info += "Total Bodies: "+ofToString(box2d.getBodyCount())+"\n";
	info += "Total Joints: "+ofToString(box2d.getJointCount())+"\n\n";
	info += "FPS: "+ofToString(ofGetFrameRate(), 1)+"\n";
    info += "Button Dest" + ofToString(mdisplay.scene);
//	ofSetHexColor(0x444342);
	ofSetHexColor(0xAAAAAA);
    if(     bshowdebug)
        ofDrawBitmapString(info, 30, 30);
	ofPopStyle();
    
    mdisplay.draw();
}
示例#2
0
//--------------------------------------------------------------
void ofApp::drawSource(int _x, int _y, int _width, int _height) {
	ofPushStyle();
	ofEnableBlendMode(OF_BLENDMODE_DISABLED);
	cameraFbo.draw(_x, _y, _width, _height);
	ofPopStyle();
}
示例#3
0
//--------------------------------------------------------------
void ofApp::draw(){
    
    //    ofEnableLighting();
    
    cam.begin();
    
    
    
    //    mainLight.enable();
    
    
    //    for (int i=0; i<buildingsPolyline_33975_22294.size(); i++) {
    //        buildingsPolyline_33975_22294[i].draw();
    //    }
    
    //    ofPushStyle();
    //    ofSetColor(255, 160);
    //
    //    for (int i=0; i<buildings_33975_22294.size(); i++) {
    //        vector<ofVec3f> & _v = buildings_33975_22294[i].getVertices();
    //        for (int j=0; j<_v.size(); j++) {
    //            ofDrawLine( _v[j] - ofVec3f(0, 0, 0), _v[j] + ofVec3f(0, 0, 100) );
    //        }
    //    }
    //    ofPopStyle();
    
    
    for (int i=0; i<roadsPolyline_33975_22294.size(); i++) {
        roadsPolyline_33975_22294[i].draw();
    }
    
    
    for (int i=0; i<roadsPolyline_33975_22294.size(); i++) {
        ofDrawCircle(roadsPolyline_33975_22294[i].getPointAtPercent( roadMoving_33975_22294 ) , 2);
    }
    
    
    
    ofPushStyle();
    ofSetColor(255, 180);
    for (int i=0; i<buildingsPolyline_33975_22294.size(); i++) {
        
        buildingsPolyline_33975_22294[i].draw();
        
//                ofBeginShape();
//                vector<ofVec3f>& vertices = buildingsPolyline_33975_22294[i].getVertices();
//                for(int j = 0; j < vertices.size(); j++) {
//                    ofVertex(vertices[j]);
//                }
//                ofEndShape();
//        
//                ofBeginShape();
//                vector<ofVec3f>& verticesUp = buildingsPolyline_33975_22294[i].getVertices();
//                for(int j = 0; j < verticesUp.size(); j++) {
//                    ofVec3f _v = verticesUp[j] + ofVec3f(0, 0, 100);
//                    ofVertex(_v);
//                }
//                ofEndShape();
        
    }
    ofPopStyle();
    
    
    
    //    mainLight.disable();
    
    cam.end();
    
    //    ofDisableLighting();
    
    

    ofPushMatrix();
    
    ofTranslate( mainOffSetXPos, mainOffSetYPos );
    
    baseArch.guideFrames();
    baseArch.drawEdgeCover( ofColor(0) );
    baseArch.guideLines();
    baseArch.guidePoints();
    
    ofPopMatrix();

    
    ofDrawBitmapString("control : w, s, a, d, r, q, e, c, mouse", 10, 20);
    
    
}
//--------------------------------------------------------------
void ofApp::setup(){
	kinect.open();
	kinect.initDepthSource();
	kinect.initColorSource();
	kinect.initInfraredSource();
	kinect.initBodyIndexSource();
	kinect.initBodySource();

	gui.init();

	//setup a gui panel for the widgets at top-left
	auto widgets = gui.addWidgets();
	widgets->addTitle("ofxKinectForWindows2");
	widgets->addFps();
	widgets->addMemoryUsage();

	//setup a gui panel for the 3D view
	auto worldView = gui.addWorld("World");
	worldView->onDrawWorld += [this](ofCamera &) {
		this->kinect.drawWorld();
	};

	//setup a gui panel for every kinect source
	auto sources = kinect.getSources();
	for(auto source : sources) {
		auto sourceWithTexture = dynamic_pointer_cast<ofBaseHasTexture>(source);
		if (sourceWithTexture) {
			auto panel = gui.add(sourceWithTexture->getTexture(), source->getTypeName());

			//if it's the colour panel, let's do something special by writing some info on top
			auto colorSource = dynamic_pointer_cast<ofxKFW2::Source::Color>(source);
			if (colorSource) {
				panel->onDraw += [colorSource] (ofxCvGui::DrawArguments &) {
					stringstream message;
					message << "Exposure : " << colorSource->getExposure() << "us" << endl;
					message << "FrameInterval : " << colorSource->getFrameInterval() << "us" << endl;
					message << "Gain : " << colorSource->getGain() << endl;
					message << "Gamma : " << colorSource->getGamma() << endl;
					ofxCvGui::Utils::drawText(message.str(), 20, 60);
				};
			}

			//if it's the depth panel, set some scaling
			auto depthSource = dynamic_pointer_cast<ofxKFW2::Source::Depth>(source);
			if (depthSource) {
				auto style = make_shared<ofxCvGui::Panels::Texture::Style>();
				style->rangeMaximum = 0.25f;
				panel->setStyle(style);
			}

			//if it's the body index panel, let's draw the joints on top
			auto bodyIndexSource = dynamic_pointer_cast<ofxKFW2::Source::BodyIndex>(source);
			if(bodyIndexSource) {
				panel->onDrawImage += [this](ofxCvGui::DrawImageArguments & args) {
					auto bodySource = this->kinect.getBodySource();
					const auto & bodies = bodySource->getBodies();

					ofPushStyle();
					{
						ofColor color(200, 100, 100);
						int index = 0;
						for (const auto & body : bodies) {
							color.setHueAngle((index * 50) % 360);
							ofSetColor(color);
							for (const auto & joint : body.joints) {
								ofDrawCircle(joint.second.getPositionInDepthMap(), 5);
							}
							index++;
						}
					}
					ofPopStyle();
				};
			}
		}

		//add an 'isFrameNew' widget to the panel
		widgets->addIndicatorBool(source->getTypeName() + " frame new", [source]() {
			return source->isFrameNew();
		});
	}

	//if we press the 'c' key on the World panel, then toggle the camera's cursor. This works best when you fullscreen that panel
	worldView->onKeyboard += [this, worldView] (ofxCvGui::KeyboardArguments & args) {
		if (args.action == ofxCvGui::KeyboardArguments::Action::Pressed && args.key =='c') {
			worldView->getCamera().toggleCursorDrawEnabled();
		}
	};
}
示例#5
0
//--------------------------------------------------------------
void ofApp::drawFluidObstacle(int _x, int _y, int _width, int _height) {
	ofPushStyle();
	ofEnableBlendMode(OF_BLENDMODE_DISABLED);
	fluidSimulation.getObstacle().draw(_x, _y, _width, _height);
	ofPopStyle();
}
示例#6
0
void gpuPictoString::update(){

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

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

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

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

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

            if(index<=particleMax){

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

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

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


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

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

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

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

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

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

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

            ofSetColor(255);
            ofFill();

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

            ofPopStyle();

        }updateRender.end();

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

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

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

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

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

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

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

                glEnd();
            }
        }

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

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

}
//-----------------------------------------------.
void guiTypeTextDropDown::render(){

	ofPushStyle();
	guiBaseObject::renderText();

		//draw the background
		ofFill();
		glColor4fv(bgColor.getNormalColorF());
		ofRect(hitArea.x, hitArea.y, hitArea.width, hitArea.height);

		if(bShowDropDown)
		{

			for(int i = 0; i < (int) vecDropList.size(); i++)
			{
				float bx = hitArea.x;
				float by = hitArea.y + i * (boxHeight);

				if(value.getValueI() == i){
					glColor4fv(fgColor.getSelectedColorF());
				}else{
					glColor4fv(fgColor.getNormalColorF());
				}

				ofFill();

				ofRect(bx, by,  boundingBox.width, boxHeight);

				ofNoFill();
				glColor4fv(outlineColor.getColorF());
				ofRect(bx, by,  boundingBox.width, boxHeight);

				if(i==0) {
					ofFill();
					glColor4fv(outlineColor.getColorF());
					ofRect(bx + boundingBox.width - boxHeight*0.5, by, boxHeight*0.5, boxHeight*0.5);
				}

				glColor4fv(textColor.getColorF());

				displayText.renderString(vecDropList[i], bx + 2, by + boxHeight -4);

			}

		} else {
			float bx = hitArea.x;
			float by = hitArea.y;

			ofFill();
			glColor4fv(bgColor.getColorF());
			ofRect(bx, by,  boundingBox.width, boxHeight);

			ofNoFill();
			glColor4fv(outlineColor.getColorF());
			ofRect(bx, by,  boundingBox.width, boxHeight);

			ofFill();
			glColor4fv(outlineColor.getColorF());
			//ofTriangle(bx + boundingBox.width - 7, by + boxHeight, bx + boundingBox.width - 14, by,bx + boundingBox.width, by);
			ofRect(bx + boundingBox.width - boxHeight*0.5, by, boxHeight*0.5, boxHeight*0.5);

			glColor4fv(textColor.getColorF());
			//displayText.renderString(vecDropList[value.getValueI()], bx + 2, by + boxHeight -4);

		}

	ofPopStyle();
}
void testApp::drawScene(int iCameraDraw){	
	
	nodeSwarm.draw();
	nodeGrid.draw();
	
	//////////////////////////////////
	// DRAW EASYCAM FRUSTUM PREVIEW
	//////////////////////////////////
	//
	// This code draws our camera in
	//	the scene (reddy/pink lines)
	//
	// The pyramid-like shape defined
	//	by the cameras view is called
	//	a 'frustum'.
	//
	// Often we refer to the volume
	//	which can be seen by the
	//	camera as 'the view frustum'.
	//
	
	
	//let's not draw the camera
	//if we're looking through it
	if (iCameraDraw != 0)
	{
		ofPushStyle();
				
		//in 'camera space' this frustum
		//is defined by a box with bounds
		//-1->1 in each axis
		//
		//to convert from camera to world
		//space, we multiply by the inverse
		//matrix of the camera
		//
		//by applying this transformation
		//our box in camera space is
		//transformed into a frustum in
		//world space.
		
		ofMatrix4x4 inverseCameraMatrix;
		
		//the camera's matricies are dependant on
		//the aspect ratio of the viewport
		//so we must send the viewport if it's not
		//the same as fullscreen
		//
		//watch the aspect ratio of preview camera
		inverseCameraMatrix.makeInvertOf(camEasyCam.getModelViewProjectionMatrix( (iMainCamera == 0 ? viewMain : viewGrid[0]) ));
		
		// By default, we can say
		//	'we are drawing in world space'
		//
		// The camera matrix performs
		//	world->camera
		//
		// The inverse camera matrix performs
		//	camera->world
		//
		// Our box is in camera space, if we
		//	want to draw that into world space
		//	we have to apply the camera->world
		//	transformation.
		//
		ofPushMatrix();
		glMultMatrixf(inverseCameraMatrix.getPtr());
		
		
		ofSetColor(255, 100, 100);
		
		//////////////////////
		// DRAW WIREFRAME BOX
		//
		// xy plane at z=-1 in camera sapce
		// (small rectangle at camera position)
		//
		glBegin(GL_LINE_LOOP);
			glVertex3f(-1, -1, -1);
			glVertex3f(-1, 1, -1);
			glVertex3f(1, 1, -1);
			glVertex3f(1, -1, -1);
		glEnd();
		
		
		// xy plane at z=1 in camera space
		// (generally invisible because so far away)
		//
		glBegin(GL_LINE_LOOP);
			glVertex3f(-1, -1, 1);
			glVertex3f(-1, 1, 1);
			glVertex3f(1, 1, 1);
			glVertex3f(1, -1, 1);
		glEnd();
		
		// connecting lines between above 2 planes
		// (these are the long lines)
		//
		glBegin(GL_LINES);
			glVertex3f(-1, 1, -1);
			glVertex3f(-1, 1, 1);
			
			glVertex3f(1, 1, -1);
			glVertex3f(1, 1, 1);
		
			glVertex3f(-1, -1, -1);
			glVertex3f(-1, -1, 1);
			
			glVertex3f(1, -1, -1);
			glVertex3f(1, -1, 1);
		glEnd();
		//
		//////////////////////

		ofPopStyle();
		ofPopMatrix();
	}
	
	//
	//////////////////////////////////

	
	
	//////////////////////////////////
	// DRAW RAY
	//////////////////////////////////
	//
	//draw if we've got camEasyCam selected
	//and we're not looking through it
	if (iMainCamera == 0 && iCameraDraw != 0)
	{
		ofPushStyle();
		ofSetColor(100, 100, 255);
		ofLine(ray[0], ray[1]);
		ofPopStyle();
	}
	//
	//////////////////////////////////
}
void MaskFrame::drawLive(DisplayMode mode, StretchMode stretchMode){
    ofPushMatrix();
    ofTranslate(this->livePosition.x, this->livePosition.y);
    
    if(this->canDrawLive()){
        homographyMode = stretchMode == HOMOGRAPHY && maskPoints.size() == 4;
        ofSetColor(ofColor::white);
        
        if(homographyMode) {
            prepareHomography();
            homography.begin(input, output);
            pattern->drawLayer(0, false);
            homography.end();
        } else {
            pattern->beginMask();
            ofPushStyle();
            {
                ofFill();
                ofBackground(ofColor::black);
                ofBeginShape();
                for(int i = 0; i < maskPoints.size(); i++){
                    if(stretchMode == STRETCH_TO_MASKFRAME) {
                        x = ofMap(maskPoints[i]->getLiveX(), 0, getLiveWidth(), 0, pattern->getWidth());
                        y = ofMap(maskPoints[i]->getLiveY(), 0, getLiveHeight(), 0, pattern->getHeight());
                    } else {
                        x = maskPoints[i]->getLiveX();
                        y = maskPoints[i]->getLiveY();
                    }
                    ofVertex(x, y);
                }
                ofEndShape();
            }
            ofPopStyle();
            pattern->endMask();
            
            if(stretchMode == STRETCH_TO_MASKFRAME) {
                pattern->draw(0, 0, getLiveWidth(), getLiveHeight());
            } else {
                pattern->draw();
            }
        }
    }
    
    if(mode != Live){
        
        bool hasHighlightedDragHandle = this->hasHighlightedDragHandle();
        bool hasHighlightedMaskPoint = this->hasHighlightedMaskPoint();

        ofPushStyle();
        {
            if((highlighted || hasHighlightedDragHandle || getTransformState() == Scaling) && !hasHighlightedMaskPoint){
                ofSetColor(highlightedColor);
            }else{
                ofSetColor(notHighlightedColor);
            }
            ofRect(0, 0, this->liveWidth, this->liveHeight);

            if((highlighted || hasHighlightedDragHandle) && !hasHighlightedMaskPoint){
                for(int i = 0; i < dragHandles.size(); i++){
                    dragHandles[i]->drawLive();
                }
            }
        }
        ofPopStyle();
    }
        
    if(mode == Design){
        if(maskPoints.size() > 2){
            ofSetColor(maskLineColor);
            for(int i = 0; i < maskPoints.size(); i++){
                int nextIndex = getNextIndex(i, maskPoints.size());
                ofLine(maskPoints[i]->getLiveX(), maskPoints[i]->getLiveY(), maskPoints[nextIndex]->getLiveX(), maskPoints[nextIndex]->getLiveY());
            }
        }
    }
    
    if(mode != Live){
        
        if(this->hasAGhostPoint){
            ghostPoint.drawLive();
        }
        
        for(int i = 0; i < maskPoints.size(); i++){
            maskPoints[i]->drawLive();
        }
    }
    
    ofPopMatrix();
}
示例#10
0
void ofxTLSwitches::draw(){
    
    ofPushStyle();
	ofFill();
	
	//draw a little wobble if its on
	//if(isOnAtMillis(timeline->getCurrentTimeMillis())){
	//play solo change
	if(isOn()){
		ofSetColor(timeline->getColors().disabledColor, 20+(1-powf(sin(ofGetElapsedTimef()*5)*.5+.5,2))*20);
		ofRect(bounds);
	}

    for(int i = 0; i < keyframes.size(); i++){
        ofxTLSwitch* switchKey = (ofxTLSwitch*)keyframes[i];
        float startScreenX = MAX(millisToScreenX(switchKey->timeRange.min), 0);
        float endScreenX = MIN(millisToScreenX(switchKey->timeRange.max), bounds.getMaxX());
		if(startScreenX == endScreenX){
			continue;
		}
		switchKey->display = ofRectangle(startScreenX, bounds.y, endScreenX-startScreenX, bounds.height);

        //draw handles

        ofSetLineWidth(2);
        bool keyIsSelected = isKeyframeSelected(switchKey);
        if(keyIsSelected || switchKey->startSelected){
	        ofSetColor(timeline->getColors().textColor);
        }
        else{
	        ofSetColor(timeline->getColors().keyColor);    
        }

        ofLine(switchKey->display.x, bounds.y, 
               switchKey->display.x, bounds.y+bounds.height);

        if(keyIsSelected || switchKey->endSelected){
	        ofSetColor(timeline->getColors().textColor);                
        }
        else{
	        ofSetColor(timeline->getColors().keyColor);    
        }        
        ofLine(switchKey->display.x+switchKey->display.width, bounds.y, 
               switchKey->display.x+switchKey->display.width, bounds.y+bounds.height);

        //draw region
        if(keyIsSelected){
        	ofSetColor(timeline->getColors().textColor, 100);    
        }
        else{
        	ofSetColor(timeline->getColors().keyColor, 100);
        }
        //set overlay colors, this will override the colors above
        if(hoverKeyframe == switchKey){
            if(startHover){
                ofPushStyle();
                if(switchKey->startSelected){
                    ofSetColor(timeline->getColors().highlightColor);
                }
                else{
                    ofSetColor(timeline->getColors().keyColor);
                }
                ofRect(switchKey->display.x-2, bounds.y, 4, bounds.height);
                ofPopStyle();
            }
            else if(endHover){
				ofPushStyle();
                if(switchKey->endSelected){
                    ofSetColor(timeline->getColors().highlightColor);
                }
                else{
                    ofSetColor(timeline->getColors().keyColor);
                }
                ofRect(switchKey->display.x+switchKey->display.width-2, bounds.y, 4.0, bounds.height);
                ofPopStyle();
            }
            else {
                if(keyIsSelected){
	                ofSetColor(timeline->getColors().highlightColor);                    
                }else {
	                ofSetColor(timeline->getColors().keyColor);    
                }
            }
        }
        ofRect(switchKey->display);
    }
    ofPopStyle();
}
//--------------------------------------------------------------
void testApp::draw(){
	
	ofDrawBitmapString("test", 10, 10);
	
	//////////////////////////
	// BACKGROUND HIGHLIGHT
	//////////////////////////
	//
	glDisable(GL_DEPTH_TEST);
	ofPushStyle();
	ofSetColor(100, 100, 100);
	ofRect(viewGrid[iMainCamera]);
	ofPopStyle();
	glEnable(GL_DEPTH_TEST);
	//
	//////////////////////////
	
	
	
	//////////////////////////
	// DRAW ALL VIEWPORTS
	//////////////////////////
	//
	
	//draw main viewport
	cameras[iMainCamera]->begin(viewMain);
	drawScene(iMainCamera);
	
	//calculate mouse ray whilst this camera is active
	updateMouseRay();
	
	cameras[iMainCamera]->end();
	
	//draw side viewports
	for (int i=0; i<N_CAMERAS; i++)
	{
		cameras[i]->begin(viewGrid[i]);
		drawScene(i);
		cameras[i]->end();
	}
	
	//
	//////////////////////////
	
	
	
	//////////////////////////
	// DRAW STUFF ON TOP
	//////////////////////////
	//
	ofPushStyle();
	glDepthFunc(GL_ALWAYS); // draw on top of everything
	
	//draw some labels
	ofSetColor(255, 255, 255);
	ofDrawBitmapString("Press keys 1-4 to select a camera for main view", viewMain.x + 20, 30);
	ofDrawBitmapString("Camera selected: " + ofToString(iMainCamera+1), viewMain.x + 20, 50);
	ofDrawBitmapString("Press 'f' to toggle fullscreen", viewMain.x + 20, 70);
	ofDrawBitmapString("Press 'p' to toggle parents on OrthoCamera's", viewMain.x + 20, 90);
	
	ofDrawBitmapString("EasyCam",	viewGrid[0].x + 20, viewGrid[0].y + 30);
	ofDrawBitmapString("Front",		viewGrid[1].x + 20, viewGrid[1].y + 30);
	ofDrawBitmapString("Top",		viewGrid[2].x + 20, viewGrid[2].y + 30);
	ofDrawBitmapString("Left",		viewGrid[3].x + 20, viewGrid[3].y + 30);

	//draw outlines on views
	ofSetLineWidth(5);
	ofNoFill();
	ofSetColor(255, 255, 255);
	//
	for (int i=0; i<N_CAMERAS; i++)
		ofRect(viewGrid[i]);
	//
	ofRect(viewMain);
	
	glDepthFunc(GL_LESS);
	ofPopStyle();
	//
	//////////////////////////
}
//----------------------------------------------------
void ofxSimpleSlider::draw() {

	ofPushStyle();
	ofEnableAlphaBlending();
	ofDisableSmoothing();
	ofPushMatrix();
	ofTranslate(x, y, 0);

	// Use different alphas if we're actively maniupulating me. 
	float sliderAlpha = (bHasFocus) ? 128 : 64;
	float spineAlpha = (bHasFocus) ? 192 : 128;
	float thumbAlpha = (bHasFocus) ? 255 : 160;

	// draw box outline
	ofNoFill();
	ofSetLineWidth(1.0);
	ofSetColor(164, 164, 164, sliderAlpha);
	ofRect(0, 0, width, height);

	// draw spine
	ofSetLineWidth(1.0);
	ofSetColor(205, 205, 205, spineAlpha);
	if (bVertical) {
		ofLine(width / 2, 0, width / 2, height);
	}
	else {
		ofLine(0, height / 2, width, height / 2);
	}

	// draw thumb
	ofSetLineWidth(5.0);
	ofSetColor(250,250, 250, thumbAlpha);
	if (bVertical) {
		float thumbY = ofMap(percent, 0, 1, height, 0, true);
		ofLine(0, thumbY, width, thumbY);
	}
	else {
		float thumbX = ofMap(percent, 0, 1, 0, width, true);
		ofLine(thumbX, 0, thumbX, height);
	}

	// draw numeric value 
	if (bHasFocus) {
		ofSetColor(255);
	}
	else {
		ofSetColor(128);
	}
	if (bVertical) {
		ofDrawBitmapString(ofToString(getValue(), numberDisplayPrecision), width + 5, height);
	}
	else {
		ofDrawBitmapString(ofToString(getValue(), numberDisplayPrecision), width + 5, height / 2 + 4);
		//DRAW ABOVE USE TYPE
		float labelStringWidth = labelString.size();
		//ofDrawBitmapString( labelString, 0-labelStringWidth*8-5, height/2 + 4); 
		ofDrawBitmapString(labelString, 0, height + 10);
	}

	ofPopMatrix();
	ofPopStyle();
}
示例#13
0
文件: menu.cpp 项目: serman/muncyt
void menu::drawBola4(ofVec2f pos, float radius, float rot) {
	ofVec2f vx = ofVec2f(1,0);
	ofVec2f posCentro =  pos-centroScreen;
	float angulo = vx.angle(posCentro);
	while(angulo<0) {angulo+=360.0;}
	
	ofPushMatrix();
	ofPushStyle();
	ofFill();
	ofTranslate(pos.x,pos.y,0);
	if(angulo>=rangosAngDeg[0] && angulo<rangosAngDeg[1]) {
//		ofLogNotice("drawBola4-->UNO");
		float rr = 2*radius;
		ofSetColor(ofColor::royalBlue, 200);
		bola.draw(-rr,-rr,2*rr,2*rr);
		ofTranslate(-posCentro.x,-posCentro.y,0);
		ofSetColor(ofColor::royalBlue, 80);
		ofSetLineWidth(0.2);
//		ofLine(0,0,  posCentro.length()*cos(angulo*DEG_TO_RAD), posCentro.length()*sin(angulo*DEG_TO_RAD));
		ofLine(0,0,  posCentro.length()*cos(angulo*DEG_TO_RAD), posCentro.length()*sin(angulo*DEG_TO_RAD));
		ofPolyline arco;
		arco.arc(ofPoint(0,0), posCentro.length(), posCentro.length(),0, 90);
		arco.draw();
	}
	
	else if(angulo>=rangosAngDeg[1] && angulo<rangosAngDeg[2]) {
//		ofLogNotice("drawBola4-->DOS");
		float rr = 6*radius;
		ofSetColor(ofColor::green, 200);
		bola.draw(-rr,-rr,2*rr,2*rr);
	}
	
	else if(angulo>=rangosAngDeg[2] && angulo<rangosAngDeg[3]) {
//		ofLogNotice("drawBola4-->TRES");
		//			ofSetColor(ofColor::deepPink, 200);
		//			bola.draw(-rr,-rr,2*rr,2*rr);
		ofSetColor(150 + ofRandom(105));
		ofCircle(0,0,radius/8);
	}
	
	else if(angulo>=rangosAngDeg[3] && angulo<(rangosAngDeg[0]+360)) {
//		ofLogNotice("drawBola4-->CUATRO");
		ofEnableBlendMode(OF_BLENDMODE_ADD);

		if(fRed) {
			float rr = 2*radius;
			ofSetColor(ofColor::red, 150);
	//		ofSetColor(ofColor::darkBlue  , 150);
			bola.draw(-rr,-rr,2*rr,2*rr);
			
			ofPushMatrix();
			ofTranslate(-pos.x, -pos.y, 0);
//			ofTranslate(ofGetWidth()/2, ofGetHeight()/2, 0);
			ofTranslate(ofGetWidth()/2, W_HEIGHT/2, 0);
			float rot = 2*(315-angulo);
			ofRotate(rot);
			ofTranslate(posCentro.x, posCentro.y,0);
			ofSetColor(ofColor::darkRed  , 150);
			rr = 2*radius;
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
		}
		else {
			float rr = 0.7*radius;
			ofRotate(rot);
			ofSetColor(ofColor::red, 150);
			//		ofSetColor(ofColor::darkBlue  , 150);
			ofPushMatrix();
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
			ofSetColor(ofColor::blue, 150);
			ofPushMatrix();
			ofRotateZ(120);
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
			ofSetColor(ofColor::green, 150);
			ofPushMatrix();
			ofRotateZ(240);
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
		}
		ofDisableBlendMode();
	}
	
	ofPopStyle();
	ofPopMatrix();	
}
示例#14
0
文件: menu.cpp 项目: serman/muncyt
void menu::drawBola4_fbos(ofVec2f pos, float radius, float rot) {
	ofPushStyle();
	
	ofVec2f vx = ofVec2f(1,0);
	ofVec2f posCentro =  pos-centroScreen;
	float angulo = vx.angle(posCentro);
	while(angulo<0) {angulo+=360.0;}
	
	//	ofPushMatrix();
	//	ofPushStyle();
	//	ofFill();
	//	ofTranslate(pos.x,pos.y,0);
	if(angulo>=0 && angulo<90) {
		float rr = 2*radius;
		fbo1.begin();
		
		ofPushMatrix();
		ofPushStyle();
		ofFill();
		ofTranslate(posCentro.x,posCentro.y,0);
		
		ofSetColor(ofColor::royalBlue, 200);
		bola.draw(-rr,-rr,2*rr,2*rr);
		ofTranslate(-posCentro.x,-posCentro.y,0);
		ofSetColor(ofColor::royalBlue, 80);
		ofSetLineWidth(0.2);
		ofLine(0,0,  posCentro.length()*cos(angulo*DEG_TO_RAD), posCentro.length()*sin(angulo*DEG_TO_RAD));
		ofPolyline arco;
		arco.arc(ofPoint(0,0), posCentro.length(), posCentro.length(),0, 90);
		arco.draw();
		
		ofPopStyle();
		ofPopMatrix();
		
		fbo1.end();
	}
	
	else if(angulo>=90 && angulo<180) {
		float rr = 6*radius;
		fbo2.begin();
		
		ofPushMatrix();
		ofPushStyle();
		ofFill();
		ofTranslate(fbo2.getWidth()+posCentro.x,posCentro.y,0);
		
		ofSetColor(ofColor::green, 200);
		bola.draw(-rr,-rr,2*rr,2*rr);
		
		ofPopStyle();
		ofPopMatrix();
		
		fbo2.end();
	}
	else if(angulo>=180 && angulo<270) {
		fbo3.begin();
		ofPushMatrix();
		ofPushStyle();
		ofFill();
		ofTranslate(fbo3.getWidth()+posCentro.x,fbo3.getHeight()+posCentro.y,0);
		
		//			ofSetColor(ofColor::deepPink, 200);
		//			bola.draw(-rr,-rr,2*rr,2*rr);
		ofSetColor(155 + ofRandom(100));
		ofCircle(0,0,radius/8);
		
		ofPopStyle();
		ofPopMatrix();
		
		fbo3.end();
	}
	else if(angulo>=270 && angulo<360) {
		fbo4.begin();
		ofPushMatrix();
		ofPushStyle();
		ofFill();
		ofTranslate(posCentro.x,fbo4.getHeight()+posCentro.y,0);
		
		ofEnableBlendMode(OF_BLENDMODE_ADD);
		
		if(fRed) {
			// bolas rojas, con simetria
			
			float rr = 2*radius;
			ofSetColor(ofColor::red, 150);
			//		ofSetColor(ofColor::darkBlue  , 150);
			bola.draw(-rr,-rr,2*rr,2*rr);
			
			ofPushMatrix();
			ofTranslate(-pos.x, -pos.y, 0);
			ofTranslate(ofGetWidth()/2, ofGetHeight()/2, 0);
			float rotSim = 2*(315-angulo);
			ofRotate(rotSim);
			ofTranslate(posCentro.x, posCentro.y,0);
			ofSetColor(ofColor::darkRed  , 150);
			rr = 2*radius;
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
		}
		else {
			// 3 bolas color
			
			float rr = 0.7*radius;
			ofRotate(rot/20.0);
			ofSetColor(ofColor::red, 150);
			//		ofSetColor(ofColor::darkBlue  , 150);
			ofPushMatrix();
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
			ofSetColor(ofColor::blue, 150);
			ofPushMatrix();
			ofRotateZ(120);
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
			ofSetColor(ofColor::green, 150);
			ofPushMatrix();
			ofRotateZ(240);
			ofTranslate(radius,0,0);
			bola.draw(-rr,-rr,2*rr,2*rr);
			ofPopMatrix();
			
		}
		ofDisableBlendMode();
		
		ofPopStyle();
		ofPopMatrix();
		fbo4.end();
	}

	ofPopStyle();
	
}
示例#15
0
void ofxBlur::end() {

	base.end();

	for(int i = 0; i < ping.size(); i++) {
		ofFbo& curPing = ping[i];
		ofFbo& curPong = pong[i];
		curPing.begin(); ofClear(0,0,0,0); curPing.end();
		curPong.begin(); ofClear(0,0,0,0); curPong.end();
	}

	ofPushStyle();
	ofSetColor(255);
			
	ofVec2f xDirection = ofVec2f(scale, 0).getRotatedRad(rotation);
	ofVec2f yDirection = ofVec2f(0, scale).getRotatedRad(rotation);
	for(int i = 0; i < ping.size(); i++) {
		ofFbo& curPing = ping[i];
		ofFbo& curPong = pong[i];
		
		// resample previous result into ping
		curPing.begin();
		int w = curPing.getWidth();
		int h = curPing.getHeight();
		if(i > 0) {
			ping[i - 1].draw(0, 0, w, h);
		} else {
			base.draw(0, 0, w, h);
		}
		curPing.end();
		
		// horizontal blur ping into pong
		curPong.begin();
		blurShader.begin();
		blurShader.setUniformTexture("source", curPing.getTextureReference(), 0);
		blurShader.setUniform2f("direction", xDirection.x, xDirection.y);
		curPing.draw(0, 0);
		blurShader.end();
		curPong.end();
		
		// vertical blur pong into ping
		curPing.begin();
		blurShader.begin();
		blurShader.setUniformTexture("source", curPong.getTextureReference(), 0);
		blurShader.setUniform2f("direction", yDirection.x, yDirection.y);
		curPong.draw(0, 0);
		blurShader.end();
		curPing.end();
	}
	
	// render ping back into base
	if(ping.size() > 1) {
		int w = base.getWidth();
		int h = base.getHeight();
        
        ofPlanePrimitive plane;
        plane.set(w, h);
        plane.mapTexCoordsFromTexture(ping[0].getTextureReference());

		base.begin();
		combineShader.begin();
		for(int i = 0; i < ping.size(); i++) {
			string name = "s" + ofToString(i);
            combineShader.setUniformTexture(name.c_str(),
                                            ping[i].getTextureReference(),
                                            1 + i);
        }
		combineShader.setUniform1f("brightness", brightness);
        ofPushMatrix();
        ofTranslate(w / 2, h / 2);
        plane.draw();
        ofPopMatrix();
		combineShader.end();
		base.end();
	} else {
		base.begin();
		ping[0].draw(0, 0);
		base.end();
	}

	ofPopStyle();
}
示例#16
0
文件: ofApp.cpp 项目: tokujin/pool
//--------------------------------------------------------------
void ofApp::draw(){
	
    
    gui.draw();
    
	videoGrayscaleCvImage.draw(120,20, 312,240);
    //	videoBgImage.draw(312+40, 20, 312, 240);

    //	this is where the point image comes(20,240+40);
	panel.draw();

    //draw 24x24
    
    ofSetColor(255, 255, 255);
    for (int i = 0; i*10 < video.getWidth()-72; i++){
		for (int j = 0; j*10 < video.getHeight(); j++){
			int pct = ofMap(leds_flip[24*j+i], 0,255, 0,5);
			ofSetColor(255,255,255);
			ofCircle(120 + i*10 + 13/2, 240 + 40 + j*10 + 10/2, pct);
		}
    
    //draw 8x72
    for (int i=0; i<72; i++) {
        for (int j=0; j<8; j++) {
            int pct = ofMap(led_matrix[j][i], 0, 255, 0, 5);
            ofCircle(120-1 + 13/2 + i*10, 280-1 + 240 + 20 + 10/2 + j*10, pct);
        }
    }

    //additional line
    ofPushStyle();
        ofNoFill();
        ofSetColor(255, 0, 0);
        ofSetLineWidth(1.5);
        ofSetRectMode(OF_RECTMODE_CORNER);
    
        //3x3 grid
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                ofRect(120-1 + 240/3*i,280-1 + 240/3*j, 240/3, 240/3);
            }
        }
        ofSetColor(0, 255, 0);
    
        //9 strip
        for (int i=0; i<9; i++) {
            ofRect(120-1 + 240/3*i,280-1 + 240 + 20, 240/3, 240/3);
        }
    
        //8 lines for casode
        ofSetColor(255, 0, 0);
        for (int i=0; i<8; i++) {
            ofLine(120-1 +13/2, 280-1 + 240 + 20 + 10/2 + 10*i, 120-1 +13/2 + 10*(72-1), 280-1 + 240 + 20 + 10/2 + 10*i);
        }
    
    ofPopStyle();
    }
    
    
    if(!isInitialized)
        ofDrawBitmapString("PRESS 'S' TO SEND KICKOFF BYTE", 400, 400);
    else {
        //just for debug
        ofDrawBitmapString("num messages sent total: "+ ofToString(numMsgSent), 400, 450);
    }

}
示例#17
0
//--------------------------------------------------------------
void testApp::draw(){
    ofRectangle previewWindow(20,20,640,480);
    ofRectangle playbackWindow(20+640,20,640,480);

    // draw the background boxes
    ofPushStyle();
    ofSetColor(0);
    ofFill();
    ofRect(previewWindow);
    ofRect(playbackWindow);
    ofPopStyle();
    
    // draw the preview if available
	if(vidRecorder->hasPreview()){
        ofPushStyle();
        ofFill();
        ofSetColor(255);
        // fit it into the preview window, but use the correct aspect ratio
        ofRectangle videoGrabberRect(0,0,vidGrabber.getWidth(),vidGrabber.getHeight());
        videoGrabberRect.scaleTo(previewWindow);
        vidGrabber.draw(videoGrabberRect);
        ofPopStyle();
    } else{
		ofPushStyle();
		// x out to show there is no video preview
        ofSetColor(255);
		ofSetLineWidth(3);
		ofLine(20, 20, 640+20, 480+20);
		ofLine(20+640, 20, 20, 480+20);
		ofPopStyle();
	}
    
    // draw the playback video
    if(recordedVideoPlayback.isLoaded()){
        ofPushStyle();
        ofFill();
        ofSetColor(255);
        // fit it into the preview window, but use the correct aspect ratio
        ofRectangle recordedRect(ofRectangle(0,0,recordedVideoPlayback.getWidth(),recordedVideoPlayback.getHeight()));
        recordedRect.scaleTo(playbackWindow);
        recordedVideoPlayback.draw(recordedRect);
        ofPopStyle();
    }

    ofPushStyle();
    ofNoFill();
    ofSetLineWidth(3);
    if(vidRecorder->isRecording()){
        //make a nice flashy red record color
        int flashRed = powf(1 - (sin(ofGetElapsedTimef()*10)*.5+.5),2)*255;
		ofSetColor(255, 255-flashRed, 255-flashRed);
    }
    else{
    	ofSetColor(255,80);
    }
    ofRect(previewWindow);
    ofPopStyle();
    
    
    //draw instructions
    ofPushStyle();
    ofSetColor(255);
    ofDrawBitmapString("' ' space bar to toggle recording", 680, 540);
    ofDrawBitmapString("'v' switches video device", 680, 560);
    ofDrawBitmapString("'a' swiches audio device", 680, 580);
    
    //draw video device selection
    ofDrawBitmapString("VIDEO DEVICE", 20, 540);
    for(int i = 0; i < videoDevices.size(); i++){
        if(i == vidRecorder->getVideoDeviceID()){
			ofSetColor(255, 100, 100);
        }
        else{
            ofSetColor(255);
        }
        ofDrawBitmapString(videoDevices[i], 20, 560+i*20);
    }
    
    //draw audio device;
    int startY = 580+20*videoDevices.size();
    ofDrawBitmapString("AUDIO DEVICE", 20, startY);
    startY += 20;
    for(int i = 0; i < audioDevices.size(); i++){
        if(i == vidRecorder->getAudioDeviceID()){
			ofSetColor(255, 100, 100);
        }
        else{
            ofSetColor(255);
        }
        ofDrawBitmapString(audioDevices[i], 20, startY+i*20);
    }
    ofPopStyle();
}
void ofxTimeMeasurements::draw(float x, float y) {

	if (!enabled) return;
	
	drawLines.clear();
	float percentTotal = 0.0f;
	float timePerFrame = 1000.0f / desiredFrameRate;

	mutex.lock();

	vector<TimeMeasurement*> toResetUpdatedLastFrameFlag;

	//update time stuff, build draw lists
	for( unordered_map<string,TimeMeasurement*>::iterator ii = times.begin(); ii != times.end(); ++ii ){
		TimeMeasurement* t = ii->second;
		string key = ii->first;
		if(!t->measuring){
			if (t->life > 0.01){
				t->life *= idleTimeColorDecay; //decrease life
			}else{ //life decays very slow when very low
				t->life *= deadThreadExtendedLifeDecSpeed; //decrease life very slowly
			}
		}
		if (!t->updatedLastFrame && timeAveragePercent < 1.0f){ // if we didnt update that time, make it tend to zero slowly
			t->avgDuration = (1.0f - timeAveragePercent) * t->avgDuration;
		}
		toResetUpdatedLastFrameFlag.push_back(t);
	}

	unordered_map<Poco::Thread*, ThreadInfo>::iterator ii;
	vector<Poco::Thread*> expiredThreads;

	//lets make sure the Main Thread is always on top
	vector< pair<Poco::Thread*, ThreadInfo> > sortedThreadList;

	for( ii = threadInfo.begin(); ii != threadInfo.end(); ++ii ){ //walk all thread trees
		if (ii->first == NULL){ //main thread is NULL!
			sortedThreadList.insert(sortedThreadList.begin(), *ii);
		}else{
			sortedThreadList.push_back(*ii);
		}
	}
	std::sort(sortedThreadList.begin(), sortedThreadList.end(), compareThreadPairs);

	#if defined(USE_OFX_HISTORYPLOT)
	vector<ofxHistoryPlot*> plotsToDraw;
	#endif

	for( int k = 0; k < sortedThreadList.size(); k++ ){ //walk all thread trees

		Poco::Thread* thread = sortedThreadList[k].first;
		core::tree<string> &tr = sortedThreadList[k].second.tree;

		PrintedLine header;
		header.formattedKey = "+" + *tr;
		header.color = threadInfo[thread].color;
		header.key = *tr; //key for selection, is thread name
		drawLines.push_back(header); //add header to drawLines

		int numAlive = 0;
		int numAdded = 0;

		core::tree<string>::iterator wholeTreeWalker = tr.in();
		bool finishedWalking = false;

		while( !finishedWalking ){

			string key = *wholeTreeWalker;
			TimeMeasurement * t = times[*wholeTreeWalker];

			#if defined(USE_OFX_HISTORYPLOT)
			bool plotActive = false;
			if(plots[key]){
				if(t->settings.plotting){
					if(t->updatedLastFrame){
						if (t->accumulating){
							plots[key]->update(t->microsecondsAccum / 1000.0f);
						}else{
							plots[key]->update(t->avgDuration / 1000.0f);
						}
					}
					plotsToDraw.push_back(plots[key]);
					plotActive = true;
				}
			}
			#endif

			bool visible = t->settings.visible;
			bool alive = t->life > 0.0001;
			if(alive){
				numAlive++;
			}

			if (visible){
				PrintedLine l;
				l.key = key;
				l.tm = t;

				int depth = wholeTreeWalker.level();
				for(int i = 0; i < depth; ++i) l.formattedKey += " ";

				if (wholeTreeWalker.size() == 0){
					l.formattedKey += "-";
				}else{
					l.formattedKey += "+";
				}
				l.formattedKey += key;
				#if defined(USE_OFX_HISTORYPLOT)
				if(plotActive) l.formattedKey += " [p]";
				#endif

				l.time = getTimeStringForTM(t);

				l.color = threadInfo[thread].color * ((1.0 - idleTimeColorFadePercent) + idleTimeColorFadePercent * t->life);
				if (!t->settings.enabled){
					l.color = disabledTextColor;
				}
				if (t->key == selection && menuActive){
					if(ofGetFrameNum()%5 < 4){
						l.color.invert();
					}
				}
				drawLines.push_back(l);
				numAdded++;
			}

			//only update() and draw() count to the final %
			if(key == TIME_MEASUREMENTS_DRAW_KEY || key == TIME_MEASUREMENTS_UPDATE_KEY){
				percentTotal += (t->avgDuration * 0.1f) / timePerFrame;
			}
			t->accumulating = false;
			t->microsecondsAccum = 0;

			//control the iterator to walk the tree "recursivelly" without doing so.
			if(wholeTreeWalker.size()){
				wholeTreeWalker = wholeTreeWalker.in();
			}else{
				if ( wholeTreeWalker.next() == wholeTreeWalker.end() ){
					wholeTreeWalker = wholeTreeWalker.out();
					while( wholeTreeWalker.next() == wholeTreeWalker.end() && wholeTreeWalker != tr){
						wholeTreeWalker = wholeTreeWalker.out();
					}
					if(wholeTreeWalker == tr){
						finishedWalking = true;
					}else{
						wholeTreeWalker++;
					}
				}else{
					++wholeTreeWalker;
				}
			}
		}

		if (numAlive == 0 && removeExpiredThreads){
			//drop that whole section if all entries in it are not alive
			for(int i = 0; i < numAdded + 1; i++){
				if(drawLines.size() > 0){
					int delID = drawLines.size() - 1;
					//clear selection if needed
					if (selection == drawLines[delID].key){
						selection = TIME_MEASUREMENTS_UPDATE_KEY;
					}
					drawLines.erase(drawLines.begin() + delID);
				}
			}
			expiredThreads.push_back(thread);
		}
	}

	//delete expired threads
	for(int i = 0; i < expiredThreads.size(); i++){
		unordered_map<Poco::Thread*, ThreadInfo>::iterator treeIt = threadInfo.find(expiredThreads[i]);
		if (treeIt != threadInfo.end()) threadInfo.erase(treeIt);
	}

	mutex.unlock();

	updateLongestLabel();

	//update max width, find headers
	int tempMaxW = -1;
	vector<int> headerLocations;
	for( int i = 0; i < drawLines.size(); i++ ){
		if (drawLines[i].tm){ //its a measurement
			//add padding to draw in columns
			for(int j = drawLines[i].formattedKey.length(); j < longestLabel; j++){
				drawLines[i].formattedKey += " ";
			}
			if (!drawLines[i].tm->error){
				drawLines[i].fullLine = drawLines[i].formattedKey + " " + drawLines[i].time;
			}else{
				drawLines[i].fullLine = drawLines[i].formattedKey + "    Error!" ;
			}
			int len = drawLines[i].fullLine.length();
			if(len > tempMaxW) tempMaxW = len;
		}else{ //its a header
			drawLines[i].fullLine = drawLines[i].formattedKey;
			headerLocations.push_back(i);
		}
	}
	maxW = tempMaxW;

	ofSetupScreen(); //mmmm----
	ofPushStyle();
	ofPushMatrix();
	ofScale(uiScale,uiScale);
	ofSetDrawBitmapMode(OF_BITMAPMODE_SIMPLE);

	ofFill();
	ofEnableAlphaBlending();

	#if defined(USE_OFX_HISTORYPLOT)
	//int numCols = plotsToDraw.size()
	for(int i = 0; i < plotsToDraw.size(); i++){
		int y = ofGetHeight() / uiScale - plotHeight * (i + 1);
		plotsToDraw[i]->draw(0, y, ofGetWidth() / uiScale, plotHeight);
		ofSetColor(99);
		if(i != plotsToDraw.size() -1){
			ofLine(0, y, ofGetWidth() / uiScale, y );
		}
	}
	#endif

	float totalW = getWidth();
	float totalH = getHeight();

	ofSetColor(bgColor, 245);
	int barH = 1;
	ofRect(x, y + 1, totalW, totalH);

	//thread header bg highlight
	for(int i = 0; i < headerLocations.size(); i++){
		int loc = headerLocations[i];
		//whole section
		ofSetColor(drawLines[loc].color, 40);
		int h = charH * ((i < headerLocations.size() - 1) ? headerLocations[i+1] - headerLocations[i] : drawLines.size() - loc );
		ofRect(x, y + 2 + loc * charH, totalW, h);
		//thread header
		ofSetColor(drawLines[loc].color, 40);
		ofRect(x, y + 2 + loc * charH, totalW, charH + 1);
	}

	ofSetColor(hilightColor);
	ofRect(x, y + 1, totalW, barH);
	ofRect(x, y + totalH - charH - 4 , totalW, barH);
	ofRect(x, y + totalH, totalW - barH, barH);

	for(int i = 0; i < drawLines.size(); i++){
		ofSetColor(drawLines[i].color);
		drawString(drawLines[i].fullLine, x , y + (i + 1) * charH);
	}

	//print bottom line, fps and stuff
	bool missingFrames = ( ofGetFrameRate() < desiredFrameRate - 1.0 ); // tolerance of 1 fps TODO!
	static char msg[128];

	sprintf(msg, "%2.1f fps % 5.1f%%", ofGetFrameRate(), percentTotal );
	if(missingFrames){
		ofSetColor(170,33,33);
	}else{
		ofSetColor(hilightColor);
	}
	int len = strlen(msg);
	string pad = " ";
	int diff = (maxW - len) - 1;
	for(int i = 0; i < diff; i++) pad += " ";
	int lastLine = ( drawLines.size() + 1 ) * charH + 2;
	drawString( pad + msg, x, y + lastLine );
	ofSetColor(hilightColor);
	drawString( " '" + ofToString(char(activateKey)) + "'" + string(timeAveragePercent < 1.0 ? " avgd!" : ""),
					   x, y + lastLine );

	for(int i = 0; i < toResetUpdatedLastFrameFlag.size(); i++){
		toResetUpdatedLastFrameFlag[i]->updatedLastFrame = false;
	}
	ofPopMatrix();
	ofPopStyle();
}
示例#19
0
//-------------------------------
void ofxControlPanel::draw(){
    if( hidden ) return;

	lastFrameDrawn	= ofGetFrameNum();

    ofPushStyle();
    ofEnableAlphaBlending();

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

		if(!bInvisible || !elementSelected){

			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, topBar.height, boundingBox.width, topBar.height);
			glPopMatrix();

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

			if ( bDoSaveRestore ){
				ofPushStyle();
					ofFill();

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

					ofRect(saveButton.x, saveButton.y, saveButton.width,saveButton.height);
					ofSetColor(255, 255, 255);
				
					displayText.renderString("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);
				
					displayText.renderString("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);

				if(!bInvisible || !elementSelected){
					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]->setShowOnlySelectedElement(bInvisible);
							panels[i]->render();
						}
					}
                glPopMatrix();

            glDisable(GL_SCISSOR_TEST);
        }

    ofPopStyle();
	
	if(bShowStatusBar){
		ofPushStyle();
		
			float textH = displayText.getTextSingleLineHeight() + 4;
			
			float yPos = ofGetHeight()-textH;
		
			glColor4fv(bgColor.getColorF());
			ofRect(0, yPos, ofGetWidth(), textH);
			
			glColor4fv(textColor.getColorF());
			displayText.renderString("Fps: " + ofToString(ofGetFrameRate(), 0) + "  Status: " + statusMessage, 4, yPos + textH - 4);
			
		ofPopStyle();
	}
}
void ParticleRenderer::draw(){
//	meshBuilder.draw();
	//render dots
	ofPushStyle();
	glPushMatrix();
	glPushAttrib(GL_ENABLE_BIT);
	
	kinect->getNode().transformGL();
	
	ofScale(1, -1, 1);
	ofScale(0.001, 0.001, 0.001);

	ofEnableAlphaBlending();
	//		if(useShaderToggle){
	if(false){
		pointCloudDOF.begin();
		//			if(depthRangeMultiply) focalRange *= 10;
		//			pointCloudDOF.setUniform1f("minSize", masterTimeline.getValue("Min Point Size"));
		//			pointCloudDOF.setUniform1f("maxSize", masterTimeline.getValue("Max Point Size"));
		//			pointCloudDOF.setUniform1f("focalRange", focalRange);
		//			pointCloudDOF.setUniform1f("focalDistance", focalDistance);
		pointCloudDOF.setUniform1i("useTexture", 0);
		//			pointCloudDOF.setUniform1i("useTexture", useColors && colorPalette.isAllocated() ? 1 : 0);
	}
	else{
		//glPointSize(masterTimeline.getValue("Min Point Size"));
		glPointSize(3);
	}
	
	//		if(useColors && colorPalette.isAllocated()){
	//			colorPalette.bind();
	//		}
	//    if(drawPointcloud){
	//        ofPushMatrix();
	//        ofScale(1,-1,1);
	//        ofEnableAlphaBlending();
	//        renderer.drawPointCloud(false);
	//        ofPopMatrix();
	//	}
	
	//ofEnableBlendMode(OF_BLENDMODE_ADD);
//	ofEnableBlendMode(OF_BLENDMODE_SCREEN);
	ofEnableAlphaBlending();
	glEnable(GL_POINT_SMOOTH); // makes circular points
	glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);	// allows per-point size
	//		glPointSize(4);
	
	//		cout << "Drawing " << mesh.getNumVertices() << " Particles " << endl;
	mesh.drawVertices();
	
	//		if(useColors && colorPalette.isAllocated()){
	//			colorPalette.unbind();
	//		}
	//
	if(false){
		pointCloudDOF.end();
	}
	
	kinect->getNode().restoreTransformGL();
	
	glPopAttrib();
	glPopMatrix();
	ofPopStyle();
}
示例#21
0
void ofxWWSearchTerm::draw(){

	ofPushStyle();
	ofSetLineWidth(4);
	ofEnableAlphaBlending();
	
	//TEMP USE THIS FOR SEARCH
	ofColor selectedColor = ofColor::fromHex(Colours::get(AT_SIGN));
	ofColor baseColor = ofColor::fromHex(Colours::get(LAYER_2_FONT));
	
	baseColor.a = selectedColor.a = opacity*255;
	float holdLerp = 1.0;

	
	float p = 0.0; 
	if(is_highlighting) {
		
		float now = ofGetElapsedTimeMillis();
		float diff =  tween_duration-(highlighted_on - now);
		p = MIN(1,diff / tween_duration);
	}
	else if(is_fading) {
		float now = ofGetElapsedTimeMillis();
		float diff =  tween_duration-(faded_on - now);
		p = 1.0 - MIN(1,diff / tween_duration);
	}
	
	p = selection.getValue();
	
	
	float t = timeSpeedVariation * ofGetElapsedTimef()+timeOffset;
	
	//TODO center this
	
	// give the search term a floaty movement
	float scaleFactor = ofMap(sin(t/4.f), -1, 1, 0.9, 1.1);
	
	

	ofColor c = baseColor.lerp(selectedColor, p);
	
	// make the colour brighter if the scale is bigger
	c.a *= ofMap(scaleFactor, 0.9, 1.2, 0.6, 1);
	float pulseDuration = 1.5;
	if(ofGetElapsedTimef()-selectedTime<pulseDuration) {
		
		float tt = ofGetElapsedTimef()-selectedTime;
		float fastStart = 0.1;
		if(tt<fastStart*pulseDuration) {
			tt = ofMap(tt, 0, fastStart*pulseDuration, 0, 0.5*pulseDuration);
		} else {
			tt = ofMap(tt, fastStart*pulseDuration, pulseDuration, 0.5*pulseDuration, pulseDuration);
		}
		float x = ofMap(tt, 0, pulseDuration, 0, 1, true);
		float pulseScale = (1-cos(x*2*PI))/2;
		scaleFactor += pulseScale * 0.5;
	}
	ofSetColor( c );
	glPushMatrix();
	{
		glTranslatef(pos.x, pos.y, 0);
		glScalef(scaleFactor, scaleFactor, 1);
		glTranslatef(-searchTermWidth/2, 0, 0);
		
		manager->parent->sharedSearchFont.drawString(term, 0, 0);
	}
	glPopMatrix();
	
	ofPopStyle();
}
示例#22
0
void ofxMPD24::drawInterface(int x, int y){
    
    int numCols = 4;
    int numRows = 4;
    int padWidth = 50;
    int padHeight = 50;
    
    ofPushStyle();


        //Draw Pads Area 1-----------------------
        ofPushMatrix();
        ofTranslate(x,y);
        int countpos = 1;
        for(int k = 4; k>0;k--){ //start in bottom left
            for(int j = 0; j<4;j++){
                ofPushMatrix();
                ofTranslate((j*55)+50, (k*55));
                
                ofSetRectMode(OF_RECTMODE_CORNER);
                ofSetColor(0, 0, 0);
                ofNoFill();
                ofRect(0,0,padWidth, padHeight);
                
                
                float xScale, yScale, pressureScale;
                pressureScale = ofMap(afterTouchVals[(countpos)], 0, 127, 0, padWidth);
                
                ofSetRectMode(OF_RECTMODE_CENTER);
                ofSetColor(100, 100, 255);
                ofFill();
                ofRect(padWidth/2,(padWidth/2),pressureScale, pressureScale);
                
                //name of pad
                ofSetColor(0);
                ofDrawBitmapString(ofToString(countpos), 20,20);
                ofPopMatrix();
                
                countpos++;
            }
        }
      ofPopMatrix();
    
    // Draw pads area 2
    ofPushMatrix();
    ofTranslate(x+55*4+50+5, y);
        int countpos2 = 17;
        for(int k = 4; k>0;k--){ //start in bottom left
            for(int j = 0; j<4;j++){
                ofPushMatrix();
                ofTranslate((j*55)+50, (k*55));
                
                ofSetRectMode(OF_RECTMODE_CORNER);
                ofSetColor(0, 0, 0);
                ofNoFill();
                ofRect(0,0,padWidth, padHeight);
                

                float xScale, yScale, pressureScale;
                pressureScale = ofMap(afterTouchVals[(countpos2)], 0, 127, 0, padWidth);
                
                ofSetRectMode(OF_RECTMODE_CENTER);
                ofSetColor(100, 100, 255);
                ofFill();
                ofRect(padWidth/2,(padWidth/2),pressureScale, pressureScale);
                
                ofSetRectMode(OF_RECTMODE_CORNER);
                //name of pad
                ofSetColor(0);
                ofDrawBitmapString(ofToString(countpos2), 20,20);
                ofPopMatrix();
                
                countpos2++;
            }
        }
    ofPopMatrix();

        //Draw Sliders Buttons----------------------
        ofPushMatrix();
            ofTranslate(x+50, y);
            ofDrawBitmapString("Sliders", 0,40);
            for (int i=0; i<6; i++){
                ofPushMatrix();
                ofTranslate(i*20,0);
                    ofSetRectMode(OF_RECTMODE_CENTER);
                
                    int locScale = ofMap(controlVals[mpdSliderLocNum[i]], 127, 0, 0, padHeight);
                    
                    ofNoFill();
                    ofSetColor(0, 0, 0);
                    ofRect(0,0,10, padHeight);
                ofFill();
                    ofSetColor(0, 0, 0);
                    ofRect(0, locScale-padHeight/2, 10, 3);
                ofPopMatrix();
            }
        ofPopMatrix();
    
        //Draw Knobs----------------------
        ofPushMatrix();
            ofTranslate(x+50, y+320);
            ofDrawBitmapString("Knob", 0,40);
            for (int i=0; i<8; i++){
                ofPushMatrix();
                ofTranslate(i*20,0);
                ofSetRectMode(OF_RECTMODE_CENTER);
                
                int locScale = ofMap(controlVals[knobNum[i]], 127, 0, 0, padHeight);
                
                ofNoFill();
                ofSetColor(0, 0, 0);
                ofRect(0,0,10, padHeight);
                
                ofFill();
                ofSetColor(0, 0, 0);
                ofRect(0, locScale-padHeight/2, 10, 3);
                ofPopMatrix();
            }
        ofPopMatrix();
    
        //Draw Buttons----------------------
    //These dont update because they just send 127 continuously and never get a 0 message like a velocity change
        ofPushMatrix();
        ofTranslate(x+240, y+320);
        ofDrawBitmapString("Buttons", 0,40);
        for (int i=0; i<5; i++){
            ofPushMatrix();
            ofTranslate(i*20,0);
            ofSetRectMode(OF_RECTMODE_CENTER);
            
            int locScale = ofMap(controlVals[buttonNum[i]], 127, 0, 0, padHeight);
            
            ofNoFill();
            ofSetColor(0, 0, 0);
            ofRect(0,0,10, padHeight);
            
            ofFill();
            ofSetColor(0, 0, 0);
            ofRect(0, locScale-padHeight/2, 10, 3);
            ofPopMatrix();
        }
    
    for (int i=0; i<oscPaths.size(); i++){
        ofDrawBitmapString(oscPaths[i], 20, 100+i*20);
    }
        ofPopMatrix();
        
  
    
    ofPopStyle();
}
示例#23
0
//--------------------------------------------------------------
void ofApp::update(){
	
	deltaTime = ofGetElapsedTimef() - lastTime;
	lastTime = ofGetElapsedTimef();
	
	simpleCam.update();
	
	if (simpleCam.isFrameNew()) {
		ofPushStyle();
		ofEnableBlendMode(OF_BLENDMODE_DISABLED);
		cameraFbo.begin();
		
		if (doFlipCamera)
			simpleCam.draw(cameraFbo.getWidth(), 0, -cameraFbo.getWidth(), cameraFbo.getHeight());  // Flip Horizontal
		else
			simpleCam.draw(0, 0, cameraFbo.getWidth(), cameraFbo.getHeight());
		cameraFbo.end();
		ofPopStyle();
		
		opticalFlow.setSource(cameraFbo.getTexture());
		
		// opticalFlow.update(deltaTime);
		// use internal deltatime instead
		opticalFlow.update();
		
		velocityMask.setDensity(cameraFbo.getTexture());
		velocityMask.setVelocity(opticalFlow.getOpticalFlow());
		velocityMask.update();
	}
	
	
	fluidSimulation.addVelocity(opticalFlow.getOpticalFlowDecay());
	fluidSimulation.addDensity(velocityMask.getColorMask());
	fluidSimulation.addTemperature(velocityMask.getLuminanceMask());
	
	mouseForces.update(deltaTime);
	
	for (int i=0; i<mouseForces.getNumForces(); i++) {
		if (mouseForces.didChange(i)) {
			switch (mouseForces.getType(i)) {
				case FT_DENSITY:
					fluidSimulation.addDensity(mouseForces.getTextureReference(i), mouseForces.getStrength(i));
					break;
				case FT_VELOCITY:
					fluidSimulation.addVelocity(mouseForces.getTextureReference(i), mouseForces.getStrength(i));
					particleFlow.addFlowVelocity(mouseForces.getTextureReference(i), mouseForces.getStrength(i));
					break;
				case FT_TEMPERATURE:
					fluidSimulation.addTemperature(mouseForces.getTextureReference(i), mouseForces.getStrength(i));
					break;
				case FT_PRESSURE:
					fluidSimulation.addPressure(mouseForces.getTextureReference(i), mouseForces.getStrength(i));
					break;
				case FT_OBSTACLE:
					fluidSimulation.addTempObstacle(mouseForces.getTextureReference(i));
				default:
					break;
			}
		}
	}
	
	fluidSimulation.update();
	
	if (particleFlow.isActive()) {
		particleFlow.setSpeed(fluidSimulation.getSpeed());
		particleFlow.setCellSize(fluidSimulation.getCellSize());
		particleFlow.addFlowVelocity(opticalFlow.getOpticalFlow());
		particleFlow.addFluidVelocity(fluidSimulation.getVelocity());
//		particleFlow.addDensity(fluidSimulation.getDensity());
		particleFlow.setObstacle(fluidSimulation.getObstacle());
	}
	particleFlow.update();
	
}
示例#24
0
//--------------------------------------------------------------
void testApp::draw(){

    if (bPrintToPdf){
        ofBackground(255);
        ofBeginSaveScreenAsPDF("screenshot-"+ofGetTimestampString()+".pdf", false);
    } else {
        ofBackground(11,94,148);
        ofBackgroundGradient(ofColor(11,94,148), ofColor(0,45,128,100));
        float margin = 10;
        ofRectangle grid = ofRectangle(margin,margin,ofGetWidth()-margin*2.0,ofGetHeight()-margin*2.0);
        
        ofPushStyle();
        
        ofSetColor(200,20);
        ofSetLineWidth(2);
        ofNoFill();
        ofRect(grid);
        ofSetLineWidth(0.3);
        drawGrid(grid, 10);
        
        ofPopStyle();
    }
    
    //  Potentialy New Gear
    //
    if( bValid && !bPrintToPdf) {
        ofSetColor(255,0,0);
        picked->update();
        picked->draw();
    }
    
    //  Draw Disk
    //
    if (bPrintToPdf){
        ofSetColor(0,100);
    } else {
        ofSetColor(255,100);
    }
    ofFill();
    ofBeginShape();
    for (int i = 0; i < disk.size(); i++) {
        ofVertex(disk[i]);
    }
    ofEndShape();
    
    if (onA)
        ofFill();
    else
        ofNoFill();
    ofCircle(A, 10);
    
    if (onB)
        ofFill();
    else
        ofNoFill();
    ofCircle(B, 10);
    
    ofNoFill();
    ofDrawBitmapString("A", A.x-3,A.y+4);
    ofDrawBitmapString("B", B.x-3,B.y+4);
    ofRect(window);
    
    //  Draw Gears
    //
    for (int i = 0; i < gears.size(); i++) {
    
        gears[i]->bPrint = bPrintToPdf;
        gears[i]->bSelected = (hoverGear == i);
        
        ofSetColor(255);
        gears[i]->update();
        gears[i]->draw();

    }
    
    if (bPrintToPdf){
        ofEndSaveScreenAsPDF();
        bPrintToPdf = false;
    }
}
示例#25
0
//--------------------------------------------------------------
void ofApp::drawMask(int _x, int _y, int _width, int _height) {
	ofPushStyle();
	ofEnableBlendMode(OF_BLENDMODE_DISABLED);
	velocityMask.draw(_x, _y, _width, _height);
	ofPopStyle();
}
//--------------------------------------------------------------
void Bird::draw(){
    ofPushStyle();
    ofSetColor(0);
    ofEllipse(pos.x, pos.y, 5, 5);
    ofPopStyle();
}
示例#27
0
void Baton::draw(int w, int h){
    
    
    ofPushStyle();
    //  ofPushMatrix();
    
    // ofSetColor(0,0,0);
    //    ofEnableLighting();
    //    light.enable();
    //    light.customDraw();
    //    material.begin();
    ofFill();
    
    
    // ofBox(light.getPosition(),30);
    ofPath polyline,polyline2;
    
    polyline.setColor(ofColor(255,255,255,alpha));
    polyline2.setColor(ofColor(255,255,255,alpha));
    
    //polyline.setMode(ofPath::POLYLINES);
    ///polyline.setStrokeWidth(thickness);
    polyline.setPolyWindingMode(OF_POLY_WINDING_NONZERO);
    polyline2.setPolyWindingMode(OF_POLY_WINDING_NONZERO);
    switch (mode){
        case 0:
            
            for(int i =0;i<poly.size();i++){
                
                polyline.curveTo(ofVec3f(poly[i].x+curthickness*sin(orientation[i]),poly[i].y+curthickness*cos(orientation[i]),poly[i].z));
                polyline2.curveTo(ofVec3f(poly2[i].x+curthickness*sin(orientation[i]),poly2[i].y+curthickness*cos(orientation[i]),poly[i].z));
            }
            
            for(int i =poly.size()-1;i>=0;i--){
                polyline.curveTo(ofVec3f(poly[i].x-curthickness*sin(orientation[i]),poly[i].y-curthickness*cos(orientation[i]),poly[i].z));
                polyline2.curveTo(ofVec3f(poly2[i].x-curthickness*sin(orientation[i]),poly2[i].y-curthickness*cos(orientation[i]),poly[i].z));    
            }
            
            
            for(int i=0;i<stainl.size();i++){
                stain.draw(stainl[i].x-stainw/2,stainl[i].y-stainh/2,stainl[i].z);
            }
            
            
            if(poly.size()>1){
                polyline.draw();
                polyline2.draw();
            }
            break;    
            
            
            
        case 1:
            
            ofSetLineWidth(thickness);
            for(int i=0;i<poly.size();i++){
                polyline.clear();
                ofVec2f curvec = poly2[i]-poly[i];
                curvec.normalize();
                curvec*=curthickness;
                
                
                polyline.curveTo(poly[i]-curvec.getRotated(90)-curvec);
                polyline.curveTo(poly[i]+curvec.getRotated(90)-curvec);
                polyline.curveTo(poly[i]+2*curvec.getRotated(90));
                
                
                polyline.curveTo(poly2[i]+2*curvec.getRotated(90));
                polyline.curveTo(poly2[i]+curvec.getRotated(90)+curvec);
                
                polyline.curveTo(poly2[i]-curvec.getRotated(90)+curvec);
                polyline.curveTo(poly2[i]-2*curvec.getRotated(90));
                
                polyline.curveTo(poly[i]-2*curvec.getRotated(90));
                polyline.curveTo(poly[i]-curvec.getRotated(90)-curvec);
                polyline.curveTo(poly[i]+2*curvec.getRotated(90));
                polyline.draw();
                
            }
            break;
        default:
            break;
    }
    //    light.disable();
    //    ofDisableLighting();
    //    material.end();
    // //   ofPopMatrix();
    ofPopStyle();
    
}
示例#28
0
//--------------------------------------------------------------
void testApp::draw()
{
//	glActiveTexture(GL_TEXTURE0);
    if (bSetup)
    {

        arhelper.draw();
        if (bText)
        {

            glPushMatrix();
            ofSetColor(255 , 255, 255 );
            string msg = "";;
            myFont.drawString(msg, (ofGetWidth()/2)-myFont.stringWidth(msg)/2,ofGetHeight()/2);
            glPopMatrix();
        }
        ofSetupScreen();
        glDisable(GL_DEPTH_TEST);
        if (fadable.getAlpha()>0)
        {
            ofPushStyle();
            ofEnableAlphaBlending();
            ofSetColor(0,0,0,maskA*fadable.getAlpha());
            ofRect(0,0,ofGetWidth(),ofGetHeight());



            if (bLoaded)
            {
#ifdef INSTRUCTION
                int cx = ofGetWidth()/2;
                int cy = ofGetHeight()/2;
                ofSetColor(255,255,255);

                shaderBGSub.setShaderActive(true);
                shaderBGSub.setUniform("tex1", 1);
                shaderBGSub.setUniform("tex2", 2);
                shaderBGSub.setUniform("tol", tol);
                player.draw(cx-vw/2,cy-vh/2);


                myTexture2.unbind();
                myTexture.unbind();

                shaderBGSub.setShaderActive(false);
                glDisable(GL_DEPTH_TEST);
#endif //#ifdef INSTRUCTION
            }

            ofDisableAlphaBlending();
            ofPopStyle();
        }
		ofSetColor(0xffffff);
        gui.draw();

    }
    else
    {
        ofEnableAlphaBlending();
        ofSetColor(255,255,255,255*sinf(ofGetElapsedTimef())+125);
        loading.draw(0,0);
        ofDisableAlphaBlending();
        ofDrawBitmapString("Loading ... ",ofGetWidth()/2,ofGetHeight()/2);
    }
}
void SceneManager::drawDebug(Depth & depth)
{
	if (player.isLoaded() && isPlayingSequence)
    {
		
		if (isDancerSilhouetteDebugVisible)
		{
			// Draw the video frame
			ofSetColor(255, 255, 255);
			ofPushMatrix();
			ofTranslate(0, ofGetHeight() - srcH * vidScale);
			ofScale(vidScale, vidScale);
			player.draw(0, 0);
			ofPopMatrix();

			// draw blurred
			ofPushMatrix();
			ofTranslate(srcW * vidScale, ofGetHeight() - srcH * vidScale);
			ofScale(vidScale, vidScale);
			dancerFbo[currentVidFbo].draw(0, 0);
			ofPopMatrix();

			// draw CV Grey image
			ofPushMatrix();
			ofTranslate(srcW * 2 * vidScale, ofGetHeight() - srcH * vidScale);
			ofScale(vidScale, vidScale);
			dancerSilhouette.drawCvGreyImg();
			ofPopMatrix();

			// draw contour
			ofPushStyle();
			ofSetColor(255, 0, 0);
			ofPushMatrix();
			ofTranslate(srcW * 3 * vidScale, ofGetHeight() - srcH * vidScale);
			ofScale(vidScale, vidScale);
			dancerSilhouette.drawContour();
			ofPopMatrix();
			ofPopStyle();
		}
    }

	if (isUserSilhouetteDebugVisible)
	{
		// draw blurred
		ofPushMatrix();
		ofTranslate(srcW * vidScale, ofGetHeight() - srcH * vidScale * 2);
		ofScale(vidScale, vidScale);
		userFbo[currentVidFbo].draw(0, 0);
		ofPopMatrix();

		// draw CV Grey image
		ofPushMatrix();
		ofTranslate(srcW * 2 * vidScale, ofGetHeight() - srcH * vidScale * 2);
		ofScale(vidScale, vidScale);
		userSilhouette.drawCvGreyImg();
		ofPopMatrix();

		// draw contour
		ofPushStyle();
		ofSetColor(255, 0, 0);
		ofPushMatrix();
		ofTranslate(srcW * 3 * vidScale, ofGetHeight() - srcH * vidScale * 2);
		ofScale(vidScale, vidScale);
		userSilhouette.drawContour();
		ofPopMatrix();
		ofPopStyle();
	}

	if (isDrawDepth)
		drawDepth(depth, 0, 480 * 0.5);

	if (isDrawClippedDepth)
	{
		ofPushMatrix();
		ofTranslate(0, ofGetHeight() - srcH * vidScale * 2);
		ofScale(vidScale, vidScale);
		drawClippedDepth(0, 0);
		ofPopMatrix();
	}

	if (isDrawLargeClippedDepth)
	{
		ofPushMatrix();
		ofTranslate(640 * 0.5, 0);
		ofScale(largeClippingScale, largeClippingScale);
		depthFbo.draw(0, 0);
		ofPopMatrix();
	}
   
    if (screenRecorder.getIsRecording())
	{
		fastFboReader.readToPixels(depthFbo, pix);
		screenRecorder.addFrame(pix);
	}

	ofPushStyle();
	ofSetColor(0);
	ofPushMatrix();
	ofTranslate(ofGetWidth() - 100, 20);
	screenRecorder.draw();
	ofPopMatrix();
	ofPopStyle();
}
示例#30
0
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			bool usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			if (colorSource) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (colorSource) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotate(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}