コード例 #1
0
//--------------------------------------------------------------
void Page::meshDraw()
{
    if (meshAlpha > 0.0) {
        float scaledAlpha = meshAlpha * 255;
        
        // mesh
        ofSetColor(128, scaledAlpha);
        mesh.drawWireframe();
        
        // normals
        for (int i=0; i < mesh.getNumIndices(); i++) {
            ofVec3f coord = mesh.getVertex(mesh.getIndex(i));
            ofVec3f norm = mesh.getNormal(mesh.getIndex(i));
            
            ofSetColor(255, 0, 255, scaledAlpha);
            ofLine(coord, coord + (norm * 5));
            ofSetColor(255, 255, 0, scaledAlpha);
            ofPushMatrix();
            ofTranslate(coord);
            ofRotate(90, 0, 1, 0);
            ofCircle(0, 0, 0, 0.1);
            ofPopMatrix();
        }
        
        // bounding box
        ofSetColor(0, 255, 255, scaledAlpha);
        ofLine(boundsMin.x, boundsMin.y, boundsMin.z, boundsMin.x, boundsMin.y, boundsMax.z);
        ofLine(boundsMin.x, boundsMin.y, boundsMax.z, boundsMax.x, boundsMin.y, boundsMax.z);
        ofLine(boundsMax.x, boundsMin.y, boundsMax.z, boundsMax.x, boundsMax.y, boundsMax.z);
        ofLine(boundsMax.x, boundsMax.y, boundsMax.z, boundsMax.x, boundsMax.y, boundsMin.z);
        ofLine(boundsMax.x, boundsMax.y, boundsMin.z, boundsMin.x, boundsMax.y, boundsMin.z);
        ofLine(boundsMin.x, boundsMax.y, boundsMin.z, boundsMin.x, boundsMin.y, boundsMin.z);
        ofLine(boundsMin.x, boundsMin.y, boundsMin.z, boundsMax.x, boundsMin.y, boundsMin.z);
        ofLine(boundsMax.x, boundsMin.y, boundsMin.z, boundsMax.x, boundsMin.y, boundsMax.z);
        ofLine(boundsMax.x, boundsMax.y, boundsMin.z, boundsMax.x, boundsMin.y, boundsMin.z);
        ofLine(boundsMin.x, boundsMax.y, boundsMax.z, boundsMin.x, boundsMin.y, boundsMax.z);
        ofLine(boundsMin.x, boundsMax.y, boundsMin.z, boundsMin.x, boundsMax.y, boundsMax.z);
        ofLine(boundsMin.x, boundsMax.y, boundsMax.z, boundsMax.x, boundsMax.y, boundsMax.z);
        
        // min and max coords
        ofSetColor(255, scaledAlpha);
        stringDraw("(" + ofToString(boundsMin.x, 3) + ", " + ofToString(boundsMin.y, 3) + ", " + ofToString(boundsMin.z, 3) + ")", boundsMin.x, boundsMin.y, boundsMin.z);
        stringDraw("(" + ofToString(boundsMax.x, 3) + ", " + ofToString(boundsMin.y, 3) + ", " + ofToString(boundsMin.z, 3) + ")", boundsMax.x, boundsMin.y, boundsMin.z);
        stringDraw("(" + ofToString(boundsMin.x, 3) + ", " + ofToString(boundsMax.y, 3) + ", " + ofToString(boundsMin.z, 3) + ")", boundsMin.x, boundsMax.y, boundsMin.z);
        stringDraw("(" + ofToString(boundsMin.x, 3) + ", " + ofToString(boundsMin.y, 3) + ", " + ofToString(boundsMax.z, 3) + ")", boundsMin.x, boundsMin.y, boundsMax.z);
        stringDraw("(" + ofToString(boundsMax.x, 3) + ", " + ofToString(boundsMax.y, 3) + ", " + ofToString(boundsMin.z, 3) + ")", boundsMax.x, boundsMax.y, boundsMin.z);
        stringDraw("(" + ofToString(boundsMax.x, 3) + ", " + ofToString(boundsMin.y, 3) + ", " + ofToString(boundsMax.z, 3) + ")", boundsMax.x, boundsMin.y, boundsMax.z);
        stringDraw("(" + ofToString(boundsMin.x, 3) + ", " + ofToString(boundsMax.y, 3) + ", " + ofToString(boundsMax.z, 3) + ")", boundsMin.x, boundsMax.y, boundsMax.z);
        stringDraw("(" + ofToString(boundsMax.x, 3) + ", " + ofToString(boundsMax.y, 3) + ", " + ofToString(boundsMax.z, 3) + ")", boundsMax.x, boundsMax.y, boundsMax.z);
        
        // axis
        ofSetColor(255, 0, 0, scaledAlpha);
        ofLine(0, 0, 0, 10, 0, 0);
        stringDraw("x", 11, 0, 0);
        ofSetColor(0, 255, 0, scaledAlpha);
        ofLine(0, 0, 0, 0, 10, 0);
        stringDraw("y", 0, 11, 0);
        ofSetColor(0, 0, 255, scaledAlpha);
        ofLine(0, 0, 0, 0, 0, 10);
        stringDraw("z", 0, 0, 11);
    }
}
コード例 #2
0
void Planet::draw(){
    ofSetColor(red,green,blue);
    ofRotate(rotation* rotateSpeed);
    ofSphere(distance,0,0,30);

}
コード例 #3
0
//--------------------------------------------------------------
void LeapVisualizer::drawArmFromXML(ofxXmlSettings & XML){
	
	float armWidth = XML.getValue("AW", 0.0);
	float basisLen = 50.0;
	
	ofPoint	handPt    = ofPoint(XML.getValue("PM:X",0.0), XML.getValue("PM:Y",0.0), XML.getValue("PM:Z",0.0));	// palm
	ofPoint	wristPt   = ofPoint(XML.getValue("W:X",0.0),  XML.getValue("W:Y",0.0),  XML.getValue("W:Z",0.0));	// wrist
	ofPoint	elbowPt   = ofPoint(XML.getValue("E:X",0.0),  XML.getValue("E:Y",0.0),  XML.getValue("E:Z",0.0));	// elbow
	ofPoint	handNorm  = ofPoint(XML.getValue("PN:X",0.0), XML.getValue("PN:Y",0.0), XML.getValue("PN:Z",0.0));	// palm normal
	
	//Hand basis matrix
	XML.pushTag("HM", 0);
    ofPoint handBasisX = ofPoint(XML.getValue("XX",0.0), XML.getValue("XY",0.0), XML.getValue("XZ",0.0));
    ofPoint handBasisY = ofPoint(XML.getValue("YX",0.0), XML.getValue("YY",0.0), XML.getValue("YZ",0.0));
    ofPoint handBasisZ = ofPoint(XML.getValue("ZX",0.0), XML.getValue("ZY",0.0), XML.getValue("ZZ",0.0));
	XML.popTag();
	
	// Arm basis matrix
	XML.pushTag("AM", 0);
    ofPoint armBasisX = ofPoint(XML.getValue("XX",0.0), XML.getValue("XY",0.0), XML.getValue("XZ",0.0));
    ofPoint armBasisY = ofPoint(XML.getValue("YX",0.0), XML.getValue("YY",0.0), XML.getValue("YZ",0.0));
    ofPoint armBasisZ = ofPoint(XML.getValue("ZX",0.0), XML.getValue("ZY",0.0), XML.getValue("ZZ",0.0));
	XML.popTag();
	
    
	// Draw the wrist and elbow points.
	if (bDrawSimple){
		ofSetColor(ofColor::orange);
		ofDrawSphere(handPt,  8.0);
		ofDrawSphere(wristPt, 8.0);
		ofDrawSphere(elbowPt, 8.0);
		
		ofLine(handPt, wristPt);
		ofLine(wristPt, elbowPt);
		ofLine(handPt, handPt+ basisLen*handNorm);
		ofDrawSphere(handPt+ basisLen*handNorm, 2.0);
		
		glLineWidth(2.0);
        // draw the rotation vectors of the hand.
        ofSetColor(ofColor::red  );	ofLine(handPt, handPt + basisLen*handBasisX);
        ofSetColor(ofColor::green);	ofLine(handPt, handPt + basisLen*handBasisY);
        ofSetColor(ofColor::blue );	ofLine(handPt, handPt + basisLen*handBasisZ);
		
        // draw the rotation vectors of the arm.
        ofSetColor(ofColor::red  );	ofLine(wristPt, wristPt + basisLen*armBasisX);
        ofSetColor(ofColor::green);	ofLine(wristPt, wristPt + basisLen*armBasisY);
        ofSetColor(ofColor::blue );	ofLine(wristPt, wristPt + basisLen*armBasisZ);
		glLineWidth(1.0);
		
		string handType = XML.getValue("TYPE", "RIGHT");
		ofSetColor(ofColor::orange);
		ofDrawBitmapString(handType, (handPt + (basisLen*1.2)*handBasisY));
		
        
        
	} else {
		
		// Draw a cylinder between two points, properly oriented in space.
		float dx = wristPt.x - elbowPt.x;
		float dy = wristPt.y - elbowPt.y;
		float dz = wristPt.z - elbowPt.z;
		float dh = sqrt(dx*dx + dy*dy + dz*dz);
		
		ofPushMatrix();
		{
			ofTranslate( (elbowPt.x+wristPt.x)/2, (elbowPt.y+wristPt.y)/2, (elbowPt.z+wristPt.z)/2 );
			
			float theta =   90 - RAD_TO_DEG * asin(dz/dh);
			float phi   =        RAD_TO_DEG * atan2(dy,dx);
			ofRotate(phi,   0,0,1);
			ofRotate(theta, 0,1,0);
			ofRotate(90,	1,0,0);
			
			// Get the arm Matrix, which provides its orthogonal basis vectors.
			float ax = armBasisY.x;
			float ay = armBasisY.y;
			float az = armBasisY.z;
			
			// Compute the longitudinal rotation of the arm
			ofNode armBasisYNode;
			armBasisYNode.setPosition(armBasisY);
			armBasisYNode.rotateAround(0-   phi, ofVec3f(0,0,1), ofVec3f(0,0,0));
			armBasisYNode.rotateAround(0- theta, ofVec3f(0,1,0), ofVec3f(0,0,0));
			armBasisYNode.rotateAround(0-    90, ofVec3f(1,0,0), ofVec3f(0,0,0));
			ofPoint newArmBasisY = armBasisYNode.getPosition();
			float armRotation = RAD_TO_DEG * atan2f(newArmBasisY.z, newArmBasisY.x);
			
			ofPushMatrix();
			{
				ofRotate(armRotation, 0,-1,0);
				float armThicknessRatio = 0.6;
				glScalef(armThicknessRatio, 1.0, 1.0);
				ofSetColor(ofColor::magenta);
				
				// Oblate arm cylinder
				ofDrawCylinder (armWidth/2.0, dh);
				
				// Wrist endcap
				ofPushMatrix();
				ofTranslate(ofPoint(0, dh/2,0));
				glScalef(1.0, armThicknessRatio, 1.0);
				ofDrawSphere(armWidth/2.0);
				ofPopMatrix();
				
				// Elbow endcap
				ofPushMatrix();
				ofTranslate(ofPoint(0, -dh/2,0));
				glScalef(1.0, armThicknessRatio, 1.0);
				ofDrawSphere(armWidth/2.0);
				ofPopMatrix();
				
			} // Close popMatrix
			ofPopMatrix();
		} // Close popMatrix
		ofPopMatrix();
	} // Close if !drawSimple
    
}
コード例 #4
0
ファイル: ofApp.cpp プロジェクト: AsmaM/openFrameworks
//--------------------------------------------------------------
void ofApp::draw(){
    ofSetColor(255);
    
    ofEnableBlendMode(OF_BLENDMODE_ALPHA);
    
	ofEnableDepthTest();
    
    glShadeModel(GL_SMOOTH); //some model / light stuff
    light.enable();
    ofEnableSeparateSpecularLight();

    ofPushMatrix();
    ofTranslate(model.getPosition().x+100, model.getPosition().y, 0);
    ofRotate(-mouseX, 0, 1, 0);
    ofTranslate(-model.getPosition().x, -model.getPosition().y, 0);
    model.drawFaces();
    ofPopMatrix();

   if(ofGetGLProgrammableRenderer()){
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS);
    }
    glEnable(GL_NORMALIZE);

    ofPushMatrix();
    ofTranslate(model.getPosition().x-300, model.getPosition().y, 0);
    ofRotate(-mouseX, 0, 1, 0);
    ofTranslate(-model.getPosition().x, -model.getPosition().y, 0);
    
    ofxAssimpMeshHelper & meshHelper = model.getMeshHelper(0);
    
    ofMultMatrix(model.getModelMatrix());
    ofMultMatrix(meshHelper.matrix);
    
    ofMaterial & material = meshHelper.material;
    if(meshHelper.hasTexture()){
        meshHelper.getTexturePtr()->bind();
    }
    material.begin();
    mesh.drawWireframe();
    material.end();
    if(meshHelper.hasTexture()){
        meshHelper.getTexturePtr()->unbind();
    }
    ofPopMatrix();

    if(ofGetGLProgrammableRenderer()){
    	glPopAttrib();
    }
    
    ofDisableDepthTest();
    light.disable();
    ofDisableLighting();
    ofDisableSeparateSpecularLight();
    
    ofSetColor(255, 255, 255 );
    ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);
    ofDrawBitmapString("keys 1-5 load models, spacebar to trigger animation", 10, 30);
    ofDrawBitmapString("drag to control animation with mouseY", 10, 45);
    ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 60);
}
コード例 #5
0
void LightScene::Render()
{
	//FOG 
	m_fogShader.begin();
	m_fogImg.getTextureReference().bind();
	m_fogVbo.bind();

	//draw fog shader
	m_fogShader.setUniformTexture("lightsOnPix", m_lightsOnTexture, 1);
	m_fogShader.setUniform1f("numLights", m_lights.size());
	glDrawArrays(GL_QUADS, 0, 4);

	m_fogImg.getTextureReference().unbind();
	m_fogShader.end();
	m_fogVbo.unbind();


	//draw lights
	ofSetColor(255);
	ofSetRectMode(OF_RECTMODE_CORNER);
	for(vector<Light>::iterator l = m_lights.begin(); l != m_lights.end(); ++l){
		if(l->isOn == true){
			m_lightImg.draw(l->x, 0, 0);
		}
	}


	HexagonParticle* hp;
	//draw a hexagon for each person in people
	for(vector<Particle*>::iterator p = pPeople->begin(); p != pPeople->end(); ++p)
	{
		hp = (HexagonParticle*) (*p);
		ofPushMatrix();
			ofTranslate(hp->pos);
			ofSetRectMode(OF_RECTMODE_CENTER);
			ofRotate(hp->hexRotation);
			ofScale(hp->hexSize, hp->hexSize);

			ofSetColor(hp->hexColor);
			m_hexImgInner.draw(0,0);

			ofSetColor(255);
			m_hexImgBorder.draw(0,0);
		ofPopMatrix();
		
		ofNoFill();
		ofSetLineWidth(5);
		float distSqrd = std::numeric_limits<float>::max();

		for(vector<Particle*>::iterator hands = pHandPositions->begin(); hands != pHandPositions->end(); ++hands){
			distSqrd = ofDistSquared( (*hands)->pos.x, (*hands)->pos.y, (*p)->pos.x, (*p)->pos.y);
			
			if (distSqrd < 90000){				
				closestHand.push_back((*hands));							
			}
		}

		if(closestHand.size() != 0){
			for(vector<Particle*>::iterator connectedhands = closestHand.begin(); connectedhands != closestHand.end(); ++connectedhands){

				ofLine( (*connectedhands)->pos.x, (*connectedhands)->pos.y, (*p)->pos.x, (*p)->pos.y);
				
				hp->hexAlpha += 5;
				if(hp->hexAlpha > 200){
					hp->hexAlpha = 200;
				}
				
				hp->hexSize += hp->hexGrowthRate;
				if (hp->hexSize  > 4){  
					hp->hexSize = 4; 
				}
			}
			closestHand.clear();

		}
		else
		{

			hp->hexAlpha -= 5;
			if(hp->hexAlpha < 0){
				hp->hexAlpha = 0;
			}	

			hp->hexSize -= hp->hexGrowthRate;
				if (hp->hexSize  < 1){  
					hp->hexSize = 1; 
				}
		}
		hp->hexColor.a = hp->hexAlpha;	
	}

}
コード例 #6
0
ファイル: ofApp.cpp プロジェクト: 4ker/openFrameworks
//--------------------------------------------------------------
void ofApp::draw(){
	ofBackgroundGradient(ofColor(245), ofColor(200));
	//ofSetLineWidth(1);
	
	//The following is just to print the instructions to the screen.
	ofSetColor(80);
	ofDrawBitmapString("Click here to add horizontal oscillators.", LEFT_MARGIN +100, TOP_MARGIN-5 );
	
	ofDrawBitmapString("Click and drag\nover an\noscillator to\nmodify it's\nspeed and\namplitude", 15,25);
	ofDrawBitmapString("Click in this area and drag upwards/downwards to scale up/down.\nPress spacebar to delete all the oscillators.", LEFT_MARGIN + 200, ofGetHeight()-40);
	
	//All this bunch is to print the vertical text
	ofPushMatrix();
	ofTranslate(LEFT_MARGIN -5,  ofGetHeight() - 100, 0);
	ofRotate(-90, 0, 0, 1);
	ofDrawBitmapString("Click here to add vertical oscillators.",  0, 0 );
	ofPopMatrix();
	
	
	
	
	ofEnableSmoothing();
	
	//This are just the reference lines draw in the screen.
	ofSetColor(0, 0, 0, 150);
	ofDrawLine(LEFT_MARGIN, 0, LEFT_MARGIN, ofGetHeight());
	ofDrawLine(0, TOP_MARGIN, ofGetWidth(), TOP_MARGIN);
	
	ofSetColor(0, 0, 0, 80);
	ofDrawLine(LEFT_MARGIN, center.y, ofGetWidth(), center.y);
	ofDrawLine(center.x, TOP_MARGIN, center.x, ofGetHeight());
	
	//ofSetLineWidth(2);
	
	
	float horWave = 0;
	float vertWave = 0;
	
	//here we go through all the horizontal oscillators
	for (unsigned int i=0; i<horizontalOscilators.size(); i++) {
		ofSetColor(255, 127+i, 0,150);
		horizontalOscilators[i].draw(); //we draw each oscillator
		horWave += horizontalOscilators[i].waveSin;
		//THIS IS IMPORTANT. Here we are adding together all the current sine values of each oscillator.
		// This is what is creates all the crazy motion that we get.
	}
	//the same as above but for vertical oscillators
	for (unsigned int i=0; i<verticalOscilators.size(); i++) {
		ofSetColor(0, 127+i, 255, 150);
		verticalOscilators[i].draw();
		vertWave += verticalOscilators[i].waveSin;
	}
	//here we move all the elements of the array one position forward so to make space for a new value.
	for (int i=1; i<TAIL_LENGTH; i++) {
		waveHistory[i-1] = waveHistory[i];
	} 
	for (int i=1; i<WAVEFORM_HISTORY; i++) {
		horWaveHistory[i-1] = horWaveHistory[i];
		vertWaveHistory[i-1]= vertWaveHistory[i];
	}
	// here we save into our history
	horWaveHistory[WAVEFORM_HISTORY-1] = horWave;
	vertWaveHistory[WAVEFORM_HISTORY-1] = vertWave;
	waveHistory[TAIL_LENGTH-1] = ofVec3f(horWave, vertWave,0);
	
	
	
	ofMesh wave; // declaring a new ofMesh object with which we're drawing the motion path created by summing the vertical and horizontal oscillators
	wave.setMode(OF_PRIMITIVE_LINE_STRIP);
	for (int i=0; i<TAIL_LENGTH; i++) {
		wave.addColor(ofFloatColor(0.1f,0.1f,0.1f, 0.5f + 0.5f * i/float(TAIL_LENGTH) ));
		wave.addVertex(waveHistory[i]);
	}
	
	//all the following is to create and populate the horizontal and vertical waveforms.
	ofMesh hWave;
	hWave.setMode(OF_PRIMITIVE_LINE_STRIP);
	ofMesh vWave;
	vWave.setMode(OF_PRIMITIVE_LINE_STRIP);
	for (int i=0; i<WAVEFORM_HISTORY; i++) {
		hWave.addColor(ofFloatColor(255, 240,10, 255));
		hWave.addVertex(ofVec3f(i*hWaveMult, horWaveHistory[i]*0.1f*scale, 0));
		vWave.addColor(ofFloatColor(255, 240,10, 255));
		vWave.addVertex(ofVec3f(vertWaveHistory[i]*0.1f*scale, i*vWaveMult, 0));
	}
	
	//draw the vertical and horizontal wave.
	ofPushMatrix();
	ofTranslate(LEFT_MARGIN, TOP_MARGIN, 0);
	hWave.draw();
	vWave.draw();
	ofPopMatrix();
	
	//draw the composite wave.
	ofPushMatrix();
	ofTranslate(center.x, center.y, 0);
	ofScale(scale, scale, 0);
	wave.draw();
	ofSetColor(0,10, 255),
	ofDrawCircle(horWave, vertWave, 10);
	ofPopMatrix();
	
}
コード例 #7
0
//--------------------------------------------------------------
void testApp::draw()
{
    //Quick way to get a nice cycling number between 0 and 1.
    //sin ( ofGetElapsedTimef() ) cycles between -1 and 1 .
    float amount = ( sin ( ofGetElapsedTimef() ) + 1.0f ) / 2.0f ;
    
    //Translate
    ofDrawBitmapStringHighlight("Translate", 25 , 20 ) ;
    ofPushMatrix();
        //Move it away from the edge a bit
        ofTranslate( 25 , 125 ) ;
       
        ofSetColor( ofColor::red ) ;
        ofCircle( 0 , 0 , 15 ) ;
    
        ofTranslate( 100 * amount , 100 * amount ) ;
        ofSetColor( 0 , 255 , 0 ) ;
        ofCircle( 0 , 0 , 15 ) ;
    
        ofTranslate( 100 * amount , 100 * amount ) ;
        ofSetHexColor( 0x0000FF ) ;
        ofCircle( 0 , 0 , 15 ) ;
    
    ofPopMatrix() ;
    
    //Rotation
    ofDrawBitmapStringHighlight("Rotate", 350 , 20 ) ;
    ofPushMatrix() ;
        ofTranslate( 350 , 125 ) ;
    
        ofSetColor( 255 ) ;
        ofCircle( 0 , 0, 15 ) ;
    
        int numItems = 12 ;
        float anglePer = 360.0f / (float) numItems ;
        
        for ( int i = 0 ; i < numItems ; i++ )
        {
            ofSetColor( ofColor::fromHsb( i * 35.0f , 255.0f , 255.0f ) ) ;
            ofPushMatrix() ;
                ofRotate( anglePer * (float)i * amount ) ;
            
                ofRect( -10 , 0 , 20 , 60 ) ; 
            ofPopMatrix() ;
        }
    ofPopMatrix() ;
    
    //Scale
    ofPushMatrix() ;
        ofDrawBitmapStringHighlight("Scale", 550 , 20 ) ;
        ofTranslate( 550 , 125 ) ;
        int triSize = 75 ;
        ofSetColor( ofColor::red ) ;
        ofTriangle( -triSize , triSize , 0 , -triSize , triSize , triSize ) ;
    
        //Make everything half as big
        ofScale( 0.5 * amount , 0.5 * amount ) ;
        ofSetColor( ofColor::green ) ;
        ofTriangle( -triSize , triSize , 0 , -triSize , triSize , triSize ) ;
    
        //Shrink it down again
        ofScale( 0.5 * amount , 0.5 * amount ) ;
        ofSetColor( ofColor::magenta ) ;
        ofTriangle( -triSize , triSize , 0 , -triSize , triSize , triSize ) ;
    
    ofPopMatrix() ;
}
コード例 #8
0
ファイル: testApp.cpp プロジェクト: kimon-satan/danceTracker
//--------------------------------------------------------------
void testApp::draw(){
    
    ofSetColor(0);
    ofBackground(120);
    
    ofDrawBitmapString("FPS: " +  ofToString(ofGetFrameRate(), 2), 20,20);
    
    
    if(displayMode == DT_DM_3D){
        
        cm.begin();
        
        
        glEnable(GL_DEPTH_TEST);
        
        ofScale(-100,100,100);
        
        ofNoFill();
        
        ofPushMatrix();
        ofScale(0.05, 0.05, 0.05);
        ofDrawGrid();
        ofPopMatrix();
        
        
        ofPushMatrix();
        ofTranslate(0, m_kinectManager.getFloorY(), 0);
        drawFloor();
        ofPopMatrix();
        
        
        ofNoFill();
        ofSetColor(255,255,0);
        
        ofPushMatrix();
        ofVec3f a = m_kinectManager.getQAxis();
        ofRotate(m_kinectManager.getQAngle(), a.x, a.y, a.z);
        ofScale(2,0.5,0.5);
        ofBox(0.15);
        ofPopMatrix();
        
        
        if(isViewSegPoints){
            if(m_kinectManager.getDancer())m_kinectManager.drawUserPointCloud();
        }else{
            m_kinectManager.drawScenePointCloud();
        }
        
        if(isViewCom && m_kinectManager.getDancer()){
            ofNoFill();
            ofSetColor(0, 255, 255);
            ofVec3f com = m_kinectManager.getDancer()->com;
            ofSphere(com.x, com.y, com.z, m_kinectManager.getDancerHeight()/2);
        }
        
        
        if(isViewCScene)m_bankManager->getCurrentScene()->draw(cm.getPosition());
        
        
        cm.end();
        
        glDisable(GL_DEPTH_TEST);
        
    }
    
    
    if(displayMode == DT_DM_2D){
        
        ofSetColor(255);
        
        ofPushMatrix();
        ofTranslate(ofGetWidth() - 750, 50);
        m_kinectManager.getLiveImg()->draw(0,0,320,240);
        ofTranslate(0, 260);
        ofDrawBitmapString("live depthMap", 0,0);
        ofTranslate(0, 40);
        m_kinectManager.getSegMask()->draw(0,0,320,240);
        ofTranslate(0, 260);
        ofDrawBitmapString("segmented depthMap", 0,0);
        ofTranslate(0, 40);
        
        
        ofPopMatrix();
        
        ofPushMatrix();
        ofTranslate(ofGetWidth() - 360, 50);
        ofFill();
        ofSetColor(50);
        ofRect(0,0,320,240);
        m_kinectManager.getCfFinder()->draw(0,0,320,240);
        ofTranslate(0, 260);
        ofSetColor(255);
        ofDrawBitmapString("contour analysis", 0,0);
        ofPopMatrix();
        
    }
    
}
コード例 #9
0
ファイル: ofApp.cpp プロジェクト: h-nishihata/VJ_2014
//--------------------------------------------------------------
void ofApp::drawFboTest_00(){
    
    float movementSpeed = .3;
    float cloudSize = ofGetWidth();
    float minBoxSize = 50;
    float spacing = 50;
    int boxCount = 30;
    
    
    ofEnableAlphaBlending();
    ofClear(255, 255, 255, 0);
    ofBackgroundGradient(ofColor(0,0,255), ofColor(85, 78, 68), OF_GRADIENT_LINEAR);
    
    
    for (int i=0; i<kNumCameras; i++) {
        if (lookatIndex[i] >= 0) {
            cam[i].lookAt(testNodes[lookatIndex[i]]);
        }
    }
    
    cam[0].begin();
    
//  grids
    for(int i = -3; i < 3; i++) {
        ofPushMatrix();
        
        ofTranslate(i*300, 0, 0);
        ofSetColor(0,255,200);
        ofDrawGridPlane(1000);
        
        ofPopMatrix();
        
        
        ofPushMatrix();
        
        ofTranslate(0, i*300, 0);
        ofRotate(90, 0, 0, -1);
        ofSetColor(0,255,200);
        ofDrawGridPlane(1000);
        
        ofRotate(90, 0, 0, -1);
        
        ofPopMatrix();
    }
    
//  boxes
    for(int i = 0; i < boxCount; i++) {
        ofPushMatrix();
        float t = (ofGetElapsedTimef() + i * spacing) * movementSpeed;
        ofVec3f pos(
                    ofSignedNoise(t, 0, 0),
                    ofSignedNoise(0, t, 0),
                    ofSignedNoise(0, 0, t));
        
        float boxSize = minBoxSize + magnitude[i]*10;
        
        pos *= cloudSize;
        ofTranslate(pos);
        ofRotateX(pos.x*.8);
        ofRotateY(pos.y*.8);
        ofRotateZ(pos.z*.8);
        
        ofFill();
        ofSetColor(255);
        ofDrawBox(boxSize);
        ofPopMatrix();
    }

    cam[0].end();
    
    
// waves
    //FFT解析した結果をもとに、グラフを生成
    float w = (float)ofGetWidth()/ (float)fft_size / 2.0f;
    for (int i = 0; i < fft_size; i++) {
        
        //塗りのアルファ値でFFT解析結果を表現
//        ofColor col;
//        col.setHsb(i * 255.0f / (float)fft_size, 255, 255, 255);
//        ofSetColor(col);
        float h = magnitude[i] * ofGetHeight();
        ofRect(ofGetWidth()/2 - w * i, ofGetHeight()/2, w, h);
        ofRect(ofGetWidth()/2 + w * i, ofGetHeight()/2, w, -h);
    }
}
コード例 #10
0
ファイル: Groove.cpp プロジェクト: occak/monad_client
void Groove::draw(){
    
    
    ofSetColor(50);
    ofFill();
    ofSetSphereResolution(20);
    ofDrawSphere(0, 0, disc->origin);
    
    for(int i = 0; i < disc->getDiscIndex(); i++){
        
        
        //rotate
        disc->setRotation(i, disc->getRotationSpeed(i));
        if(turn) ofRotate(disc->getRotation(i), 0, 0, 1);
        else ofRotate(disc->getRotation(i), 0, 0, 1);
        
        
        mesh[i].draw();
        
        //draw circles
        ofSetLineWidth(3);
        ofNoFill();
        ofColor fillColor = 50;
        if( i != me->getDiscIndex() && disc->isMute(i) == 1) fillColor = ofColor::lightGrey;
        if( otherPlayers.size() > 0){
            for (int j = 0; j < otherPlayers.size(); j++) {
                if( i == otherPlayers[j]->getDiscIndex() && disc->isMute(otherPlayers[j]->getDiscIndex()) == 0) fillColor = otherPlayers[j]->getColor();
                else if( i == otherPlayers[j]->getDiscIndex() && disc->isMute(otherPlayers[j]->getDiscIndex()) == 1){
                    ofColor pale = otherPlayers[j]->getColor();
                    pale.setSaturation(pale.getSaturation() - 110);
                    fillColor = pale;
                }
            }
        }
        if( i == me->getDiscIndex() && disc->isMute(me->getDiscIndex()) == 0) fillColor = me->getColor();
        if( i == me->getDiscIndex() && disc->isMute(me->getDiscIndex()) == 1) {
            ofColor pale = me->getColor();
            pale.setSaturation(pale.getSaturation() - 110);
            fillColor = pale;
        }
        ofSetColor(fillColor);
        
        ofSetCircleResolution(70);
        //front
        ofCircle(0,0,disc->getPosition(i), disc->getRadius(i-1));
        ofCircle(0,0,disc->getPosition(i), disc->getRadius(i));
        //back
        ofCircle(0,0,disc->getPosition(i)-.2, disc->getRadius(i-1));
        ofCircle(0,0,disc->getPosition(i)-.2, disc->getRadius(i));
        ofFill();
        
        //get texture type and draw
        
        switch(disc->getTexture(i)){
                
            case 0: //blank
                
                break;
                
            case 1: //line
                
                for(int a = 0; a < 360; a++){
                    
                    if(fmodf(a, disc->getDensity(i)) == 0){
                        
                        double spikePoint = (disc->getRadius(i)+disc->getRadius(i-1))/2;
                        ofPoint p1, p2, p3;
                        ofPoint rp1, rp2, rp3;
                        
                        p1.set(disc->getRadius(i-1)*cos(a*PI/180) ,  //x1
                               disc->getRadius(i-1)*sin(a*PI/180),    //y1
                               disc->getPosition(i));
                        p2.set(disc->getRadius(i)*cos(a*PI/180),      //x2
                               disc->getRadius(i)*sin(a*PI/180),      //y2
                               disc->getPosition(i));
                        p3.set(spikePoint*cos(a*PI/180),
                               spikePoint*sin(a*PI/180),
                               disc->getPosition(i)+ disc->getSpikeDistance(i));
                        
                        rp1.set(p1.x, p1.y, p1.z-flipsideDist);
                        rp2.set(p2.x, p2.y, p2.z-flipsideDist);
                        rp3.set(p3.x, p3.y, p3.z-(flipsideDist+2*disc->getSpikeDistance(i)));
                        
                        ofLine(p1,p2);
                        //reverse
                        ofLine(rp1,rp2);
                        
                        if(disc->getSpikeDistance(i) != 0){
                            
                            ofSetColor(fillColor, 70);
                            ofBeginShape();
                            ofVertex(p1);
                            ofVertex(p3);
                            ofVertex(p2);
                            ofEndShape();
                            
                            
                            ofBeginShape();
                            ofVertex(rp1);
                            ofVertex(rp3);
                            ofVertex(rp2);
                            ofEndShape();
                            
                            ofSetColor(fillColor, 255);
                        }
                        
                    }
                }
                
                break;
                
            case 2: //triangle
                
                for(int a = 0; a < 360; a++){
                    
                    if(fmodf(a, disc->getDensity(i)) == 0){
                        
                        //spike locted at center of gravity
                        double spikePoint = (disc->getRadius(i-1)+(disc->getRadius(i)-disc->getRadius(i-1))/3);
                        
                        ofPoint p1, p2, p3, p4, p5;
                        p1.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180),
                               disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180),
                               disc->getPosition(i));
                        p2.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i)/2)*PI/180),
                               disc->getRadius(i-1)*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i));
                        p3.set(disc->getRadius(i-1)*cos(a*PI/180),
                               disc->getRadius(i-1)*sin(a*PI/180),
                               disc->getPosition(i));
                        p4.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180),
                               disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i));
                        p5.set(spikePoint*cos((a - disc->getDensity(i)/2)*PI/180),
                               spikePoint*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i) + disc->getSpikeDistance(i));
                        
                        ofPoint rp1, rp2, rp3, rp4, rp5;
                        rp1.set(p1.x, p1.y, p1.z-flipsideDist);
                        rp2.set(p2.x, p2.y, p2.z-flipsideDist);
                        rp3.set(p3.x, p3.y, p3.z-flipsideDist);
                        rp4.set(p4.x, p4.y, p4.z-flipsideDist);
                        rp5.set(p5.x, p5.y, p5.z-(flipsideDist+2*disc->getSpikeDistance(i)));
                        
                        
                        
                        ofSetPolyMode(OF_POLY_WINDING_ODD);
                        
                        ofFill();
                        ofBeginShape(); //base
                        ofVertex(p1);
                        ofVertex(p2);
                        ofVertex(p3);
                        ofVertex(p4);
                        ofEndShape();
                        
                        //reverse
                        ofBeginShape(); //base
                        ofVertex(rp1);
                        ofVertex(rp2);
                        ofVertex(rp3);
                        ofVertex(rp4);
                        ofEndShape();
                        
                        if(disc->getSpikeDistance(i) != 0){
                            
                            ofSetColor(fillColor, 70);
                            
                            ofBeginShape(); //spike
                            ofVertex(p4);
                            ofVertex(p5);
                            ofVertex(p3);
                            ofEndShape();
                            
                            ofBeginShape(); //spike
                            ofVertex(p4);
                            ofVertex(p5);
                            ofVertex(p1);
                            ofEndShape();
                            
                            
                            ofBeginShape(); //spike
                            ofVertex(rp4);
                            ofVertex(rp5);
                            ofVertex(rp3);
                            ofEndShape();
                            
                            ofBeginShape(); //spike
                            ofVertex(rp4);
                            ofVertex(rp5);
                            ofVertex(rp1);
                            ofEndShape();
                            
                            ofSetColor(fillColor, 255);
                        }
                    }
                }
                
                break;
            case 3: //saw
                
                for(int a = 0; a < 360; a++){
                    
                    if(fmodf(a, disc->getDensity(i)) == 0){
                        
                        
                        //spike locted at center of gravity
                        double spikePoint = (disc->getRadius(i-1)+(disc->getRadius(i)-disc->getRadius(i-1))/3);
                        
                        ofPoint p1, p2, p3, p4, p5;
                        p1.set(disc->getRadius(i)*cos((a - disc->getDensity(i))*PI/180),
                               disc->getRadius(i)*sin((a - disc->getDensity(i))*PI/180),
                               disc->getPosition(i));
                        p2.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180),
                               disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i));
                        p3.set(disc->getRadius(i)*cos(a*PI/180),
                               disc->getRadius(i)*sin(a*PI/180),
                               disc->getPosition(i));
                        p4.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180),                                  disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180),
                               disc->getPosition(i));
                        p5.set(spikePoint*cos((a - 2*disc->getDensity(i)/3)*PI/180),
                               spikePoint*sin((a - 2*disc->getDensity(i)/3)*PI/180),
                               disc->getPosition(i) + disc->getSpikeDistance(i));
                        
                        ofPoint rp1, rp2, rp3, rp4, rp5;
                        rp1.set(p1.x, p1.y, p1.z-flipsideDist);
                        rp2.set(p2.x, p2.y, p2.z-flipsideDist);
                        rp3.set(p3.x, p3.y, p3.z-flipsideDist);
                        rp4.set(p4.x, p4.y, p4.z-flipsideDist);
                        rp5.set(p5.x, p5.y, p5.z-(flipsideDist+2*disc->getSpikeDistance(i)));
                        
                        
                        ofSetPolyMode(OF_POLY_WINDING_ODD);
                        ofFill();
                        
                        ofBeginShape(); //base
                        ofVertex(p1);
                        ofVertex(p2);
                        ofVertex(p3);
                        ofVertex(p4);
                        ofEndShape();
                        
                        //reverse
                        ofBeginShape(); //base
                        ofVertex(rp1);
                        ofVertex(rp2);
                        ofVertex(rp3);
                        ofVertex(rp4);
                        ofEndShape();
                        
                        if(disc->getSpikeDistance(i) != 0){
                            
                            ofSetColor(fillColor, 70);
                            ofBeginShape(); //spike
                            ofVertex(p4);
                            ofVertex(p5);
                            ofVertex(p3);
                            ofEndShape();
                            
                            ofBeginShape(); //spike
                            ofVertex(p4);
                            ofVertex(p5);
                            ofVertex(p1);
                            ofEndShape();
                            
                            ofBeginShape(); //spike
                            ofVertex(rp4);
                            ofVertex(rp5);
                            ofVertex(rp3);
                            ofEndShape();
                            
                            ofBeginShape(); //spike
                            ofVertex(rp4);
                            ofVertex(rp5);
                            ofVertex(rp1);
                            ofEndShape();
                            
                            ofSetColor(fillColor, 255);
                        }
                        
                        
                        
                        
                    }
                }
                
                break;
                
            {
            case 4: //rectangle
                
                bool space = false;
                
                for(int a = 0; a < 360; a++){
                    
                    if(space == false && fmodf(a, disc->getDensity(i)) == 0){
                        
                        //spike locted at center of gravity
                        double spikePoint = (disc->getRadius(i)+disc->getRadius(i-1))/2;
                        
                        ofPoint p1, p2, p3, p4, p5, p6, p7;
                        p1.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i))*PI/180),
                               disc->getRadius(i-1)*sin((a - disc->getDensity(i))*PI/180),
                               disc->getPosition(i));
                        p2.set(disc->getRadius(i-1)*cos((a - disc->getDensity(i)/2)*PI/180),
                               disc->getRadius(i-1)*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i));
                        p3.set(disc->getRadius(i-1)*cos(a*PI/180),
                               disc->getRadius(i-1)*sin(a*PI/180),
                               disc->getPosition(i));
                        p4.set(disc->getRadius(i)*cos(a*PI/180),
                               disc->getRadius(i)*sin(a*PI/180),
                               disc->getPosition(i));
                        p5.set(disc->getRadius(i)*cos((a - disc->getDensity(i)/2)*PI/180),
                               disc->getRadius(i)*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i));
                        p6.set(disc->getRadius(i)*cos((a - disc->getDensity(i))*PI/180),
                               disc->getRadius(i)*sin((a - disc->getDensity(i))*PI/180),
                               disc->getPosition(i));
                        p7.set(spikePoint*cos((a - disc->getDensity(i)/2)*PI/180),
                               spikePoint*sin((a - disc->getDensity(i)/2)*PI/180),
                               disc->getPosition(i) + disc->getSpikeDistance(i));
                        
                        ofPoint rp1, rp2, rp3, rp4, rp5, rp6, rp7;
                        rp1.set(p1.x, p1.y, p1.z-flipsideDist);
                        rp2.set(p2.x, p2.y, p2.z-flipsideDist);
                        rp3.set(p3.x, p3.y, p3.z-flipsideDist);
                        rp4.set(p4.x, p4.y, p4.z-flipsideDist);
                        rp5.set(p5.x, p5.y, p5.z-flipsideDist);
                        rp6.set(p6.x, p6.y, p6.z-flipsideDist);
                        rp7.set(p7.x, p7.y, p7.z-(flipsideDist+2*disc->getSpikeDistance(i)));
                        
                        
                        
                        ofSetPolyMode(OF_POLY_WINDING_ODD);
                        ofFill();
                        
                        ofBeginShape(); //base
                        ofVertex(p1);
                        ofVertex(p2);
                        ofVertex(p3);
                        ofVertex(p4);
                        ofVertex(p5);
                        ofVertex(p6);
                        ofEndShape();
                        
                        //reverse
                        ofBeginShape(); //base
                        ofVertex(rp1);
                        ofVertex(rp2);
                        ofVertex(rp3);
                        ofVertex(rp4);
                        ofVertex(rp5);
                        ofVertex(rp6);
                        ofEndShape();
                        
                        
                        if(disc->getSpikeDistance(i) != 0){
                            
                            ofSetColor(fillColor, 70);
                            
                            ofBeginShape(); //spike
                            ofVertex(p6);
                            ofVertex(p7);
                            ofVertex(p4);
                            ofEndShape();
                            
                            ofBeginShape();
                            ofVertex(p6);
                            ofVertex(p7);
                            ofVertex(p1);
                            ofEndShape();
                            
                            ofBeginShape();
                            ofVertex(p4);
                            ofVertex(p7);
                            ofVertex(p3);
                            ofEndShape();
                            
                            
                            ofBeginShape(); //spike
                            ofVertex(rp6);
                            ofVertex(rp7);
                            ofVertex(rp4);
                            ofEndShape();
                            
                            ofBeginShape();
                            ofVertex(rp6);
                            ofVertex(rp7);
                            ofVertex(rp1);
                            ofEndShape();
                            
                            ofBeginShape();
                            ofVertex(rp4);
                            ofVertex(rp7);
                            ofVertex(rp3);
                            ofEndShape();
                            
                            ofSetColor(fillColor, 255);
                        }
                        
                        space = true;
                    }
                    else if (space == true && fmodf(a, disc->getDensity(i)) == 0) space = false;
                    
                }
                break;
            }
                
                
            default:
                //something something
                break;
        }
    }
}
コード例 #11
0
ファイル: Character.cpp プロジェクト: bassjansson/BassLive
//========================================================================
void Character::draw (float& x, float& y, bool vertical, bool selection, bool floating)
{
    // Init character position
    if (this->x == 0.0f) this->x = xAnim = x + charWidth;
    if (this->y == 0.0f) this->y = yAnim = y + charHeight * int(vertical);
    
    
    // Update input position
    if (ofGetMousePressed(OF_MOUSE_BUTTON_LEFT) &&
        charSelected->charType != CHAR &&
        (begin == charSelected || (begin == charSelected->end()->right && !floating)))
    {
        if (begin == charSelected)
        {
            x = mouseX - charWidth  * 0.5f;
            y = mouseY - charHeight * 0.5f;
        }
        else
        {
            x = charSelected->left->x + charWidth  * 3.0f;
            y = charSelected->left->y + charHeight * int(vertical);
        }
    }
    else
    {
        if (floating)
        {
            x = roundf(this->x / charWidth)  * charWidth;
            y = roundf(this->y / charHeight) * charHeight;
        }
        else
        {
            x += charWidth;
            y += charHeight * int(vertical);
        }
    }
    
    
    // Update character position
    this->x = x;
    this->y = y;
    
    
    // Draw character
    ofPushMatrix();
    
    float factor1 = powf(1.0f - animation, 4.0f);
    float factor2 = (1.0f - factor1);
    
    float scaling = 1.0f + ofGetHeight() / charHeight * factor1 * 0.4f;
    
    // TODO: change translate
    ofTranslate(xAnim * factor2, // + ofGetWidth()  * 0.5f * factor1,
                yAnim * factor2);// + ofGetHeight() * 0.5f * factor1);
    ofTranslate(charWidth * 0.5f, charHeight * 0.5f);
    ofRotate(factor1 * 180.0f);
    ofScale(scaling, scaling);
    charFont.drawString(charString,
                        -charWidth * 0.5f,
                        charHeight * 0.5f + charFont.getDescenderHeight());
    
    ofPopMatrix();
    
    
    // Draw selection
    if (selection)
    {
        ofSetColor(COLOR_SELECTION);
        ofDrawRectangle(xAnim, yAnim, charWidth, charHeight);
    }
    
    if ((mouseX >= xAnim && mouseX < xAnim + charWidth) &&
        (mouseY >= yAnim && mouseY < yAnim + charHeight))
    {
        ofSetColor(COLOR_SELECTION * 2);
        ofDrawRectRounded(xAnim, yAnim, charWidth, charHeight, charWidth * 0.1f);
    }
    
    
    // Draw fractal
    //if (charType == FUNC || charType == MAIN)
    //    drawFractal();
    
    
    // Update character animation position
    float factor = 0.3f;
    xAnim = (1.0f - factor) * xAnim + factor * this->x;
    yAnim = (1.0f - factor) * yAnim + factor * this->y;
    
    
    // Update animation
    if (animation >= 1.0f)
        animation  = 1.0f;
    else
        animation += 0.047f;
    
    
    // Shake characters when a key is pressed
    if (RMS > 0.0707f) // CHANGE THIS WHEN NEEDED
    {
        float factor = 0.05f;
        xAnim += ofRandom(-charWidth * factor, charWidth * factor);
        yAnim -= ofRandom(0.0f, charHeight * factor);
        
        animation *= 0.92f;
    }
}
コード例 #12
0
ファイル: Screen_game.cpp プロジェクト: DelphiClaer/Robot
//BOY PART -----------------------------------------------------------
void Screen_game::boy(){
    
    rotationStrengthOffset = fabs(rotation);
    liftLeg = 30 + rotationStrengthOffset;
    
    if(Left){
        
        ofPushMatrix();
        
            float translateposX = posX_leg + rightSide + leg_width/2;
            float translateposY = posY_leg;
        
            ofTranslate(translateposX, translateposY, 0);
            ofRotate(rotation);
        
            ofPushMatrix();
        
                ofTranslate(-translateposX, -translateposY, 0);
                boy_right_leg("left");
        
            ofPopMatrix();
        
        ofPopMatrix();
        
        
        boy_left_leg("left");
        boy_body(true);
        
        
    }else if(Right){
        
        ofPushMatrix();
        
            float translateposX = posX_leg + leg_width/2;
            float translateposY = posY_leg;
        
            ofTranslate(translateposX, translateposY, 0);
            ofRotate(rotation);
        
            ofPushMatrix();
        
                ofTranslate(-translateposX, -translateposY, 0);
                boy_left_leg("right");
        
            ofPopMatrix();
        
        ofPopMatrix();
        
        
        boy_right_leg("right");
        boy_body(true);
        
        
    }else if(!Left && !Right){
        
        boy_left_leg("normal");
        boy_right_leg("normal");
        boy_body(false);
        
    }
    
}
コード例 #13
0
void CloudsHUDController::drawLayer3D(CloudsHUDLayerSet layer, ofCamera* cam, ofVec2f& offset){
    ofPushMatrix();
    
    // Hook up to the camera to keep the layer steady.
    ofMatrix4x4 baseRotation;
    ofTranslate(cam->getPosition());
    baseRotation.makeRotationMatrix(cam->getOrientationQuat());
    ofMultMatrix(baseRotation);
    
    ofVec3f camPos = ofVec3f();  //cam->getPosition();
    
    // Calculate the base position.
    static ofVec3f yAxis = ofVec3f(0.0, 1.0, 0.0);
    static ofVec3f xAxis = ofVec3f(1.0, 0.0, 0.0);
//    ofVec3f basePos = camPos + (cam->getLookAtDir().getScaled(layerDistance[layer]));
//    ofVec3f basePos(0, 0, -layerDistance[layer]);
    ofVec3f basePos(offset.x, offset.y, -layerDistance[layer]);
    basePos.rotate(layerRotationH[layer], camPos, yAxis);
    basePos.rotate(layerRotationV[layer], camPos, xAxis);
    
    // Get the total layer bounds.
    ofRectangle layerBounds;
	for(int i = 0; i < layerSets[layer].size(); i++){
        if (i == 0) layerBounds = layerSets[layer][i]->svg.getBounds();
        else layerBounds.growToInclude(layerSets[layer][i]->svg.getBounds());
	}
    
    // Translate to the layer center pos.
    ofVec3f layerPos = basePos + (getCenter(false) - layerBounds.getCenter());
    ofTranslate(layerPos);

    if (layerBillboard[layer] == CLOUDS_HUD_BILLBOARD_OCULUS) {
        // Billboard rotation using the Oculus orientation.
        float angle;
        ofVec3f axis;
        CloudsVisualSystem::getOculusRift().getOrientationQuat().getRotate(angle, axis);
        ofRotate(angle, axis.x, axis.y, axis.z);
        ofScale(-1, 1, 1);
    }
    else if (layerBillboard[layer] == CLOUDS_HUD_BILLBOARD_CAMERA) {
        // Billboard rotation using the camera.
        ofNode node;
        node.setPosition(layerPos);
        node.lookAt(camPos);
        ofVec3f axis;
        float angle;
        node.getOrientationQuat().getRotate(angle, axis);
        ofRotate(angle, axis.x, axis.y, axis.z);
    }
    else {
//        ofRotateY(layerRotationH[layer]);
//        ofRotateX(layerRotationV[layer]);
        ofScale(-1, 1, 1);
    }
    
    // Debug circle.
//    ofSetColor(255);
//    ofCircle(0, 0, 25);
    
    // Transform for rendering the layer.
    ofScale(-scaleAmt, -scaleAmt, 1);
    ofTranslate(-layerBounds.getCenter());

    // Draw the video player if we're on the right layer.
    if (layer == CLOUDS_HUD_PROJECT_EXAMPLE && videoPlayer.isPlaying()) {
        ofSetColor(255, 255, 255, 255*0.7);
        if( !bSkipAVideoFrame ){
//            videoPlayer.draw( videoBounds.x, videoBounds.y, videoBounds.width, videoBounds.height );
        }
    }
    
    // Draw the layer.
    ofSetColor(255);
    drawLayer(layer);
    
    // Draw the home button if we're on the right layer.
    if (layer == CLOUDS_HUD_LOWER_THIRD && bDrawHome && hudOpenMap[CLOUDS_HUD_LOWER_THIRD]) {
        home.draw();
    }
    
    // Draw the associated text labels.
    for( map<string, CloudsHUDLabel*>::iterator it=hudLabelMap.begin(); it!= hudLabelMap.end(); ++it ){
        bool bFound = false;
        for(int i = 0; i < layerSets[layer].size(); i++){
            if (layerSets[layer][i]->svg.getMeshByID(it->first) != NULL) {
                bFound = true;
                break;
            }
        }
        if (bFound) {
            (it->second)->draw();
        }
    }
    
    ofPopMatrix();
}
コード例 #14
0
//--------------------------------------------------------------
void testApp::drawWithModel(){
    //leaf one
    
    ofVec3f position1 = model1.getPosition();
    
    //save the current view
    ofPushMatrix();
    
    //center ourselves there
    ofTranslate(position1);
    ofRotate(rdegree, 0, 1, 0);
    ofScale(0.15,0.15,0.15);
    ofRotate(90,1,0,0);
    ofTranslate(-position1);
    //draw the model
    model1.drawFaces();
    //restore the view position
    
    ofPopMatrix();
    model1.setPosition(ofGetWidth()*0.5, ofGetHeight()*height1, 0);
    
    
    //leaf two
    ofVec3f position2 = model2.getPosition();
    //save the current view
    ofPushMatrix();
    //center ourselves there
    ofTranslate(position2);
    ofRotate(rdegree, 0, 1, 0);
    ofScale(0.3,0.3,0.3);
    ofRotate(60,1,0,0);
    ofTranslate(-position2);
    //draw the model
    model2.drawFaces();
    //restore the view position
    ofPopMatrix();
    model2.setPosition(ofGetWidth()*0.4, ofGetHeight()*height2, 0);
    
    
    ofVec3f position3 = model3.getPosition();
    
    ofPushMatrix();
    //center ourselves there
    ofTranslate(position3);
    ofRotate(rdegree, 0, 1, 0);
    ofScale(0.15,0.15,0.15);
    ofRotate(90,1,0,0);
    ofTranslate(-position3);
    //draw the model
    model3.drawFaces();
    //restore the view position
    ofPopMatrix();
    model3.setPosition(ofGetWidth()*0.3, ofGetHeight()*height3, 0);
    
    //leaf two
    ofVec3f position4 = model4.getPosition();
    //save the current view
    ofPushMatrix();
    //center ourselves there
    ofTranslate(position4);
    ofRotate(rdegree, 0, 1, 0);
    ofScale(0.1,0.1,0.1);
    ofRotate(60,1,0,0);
    ofTranslate(-position4);
    //draw the model
    model4.drawFaces();
    //restore the view position
    ofPopMatrix();
    model4.setPosition(ofGetWidth()*0.8, ofGetHeight()*height4, 0);
    
    ofVec3f position5 = model5.getPosition();
    //save the current view
    ofPushMatrix();
    //center ourselves there
    ofTranslate(position5);
    ofRotate(rdegree, 0, 1, 0);
    ofScale(0.1,0.1,0.1);
    ofRotate(120,1,0,0);
    ofTranslate(-position5);
    //draw the model
    model5.drawFaces();
    //restore the view position
    ofPopMatrix();
    model5.setPosition(ofGetWidth()*0.2, ofGetHeight()*height5, 0);
    
    ofVec3f position7 = circle.getPosition();
    //save the current view
    ofPushMatrix();
    //center ourselves there
    ofTranslate(position7);
    //ofRotate(rdegree, 0, 1, 0);
    ofScale(radius,radius,radius);
    //ofRotate(120,1,0,0);
    ofTranslate(-position7);
    //draw the model
    circle.drawFaces();
    //restore the view position
    ofPopMatrix();
    circle.setPosition(ofGetWidth()*0.5, ofGetHeight()*0.85, 0);
    

}
コード例 #15
0
ファイル: createPrimitive.cpp プロジェクト: Mana-Hanno/oF
void createPrimitive::draw(property &p) {
    prop = p;
    if(prop.points.size() == 0) return;
    switch (prop.dType) {
        case CP_POINT:
            glDepthMask(GL_FALSE);
            ofEnableAlphaBlending();
            ofEnableBlendMode(OF_BLENDMODE_ALPHA);
            ofEnablePointSprites();
            shader.begin();
            texture.bind();
            prop.vbo.draw(GL_POINTS, 0, (int)prop.points.size());
            texture.unbind();
            
            shader.end();
            ofDisablePointSprites();
            glDepthMask(GL_TRUE);
            
            break;
        case CP_LINE:
            //ofSetLineWidth(mags[0].x/10);
            ofSetLineWidth(20);
            prop.vbo.drawElements(GL_LINE_STRIP, prop.points.size());
            break;
        case CP_CYLINDER:
            for (int i = 0; i < prop.points.size(); i++) {
                ofPushMatrix();
                //glDepthMask(GL_FALSE);
                ofEnableDepthTest();
                ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255);
                ofTranslate(prop.points[i].x, prop.points[i].y-prop.mags[i].x/2, prop.points[i].z);
                ofDrawCylinder(0,0,0, 10, prop.mags[i].x);
                //glDepthMask(GL_TRUE);
                ofPopMatrix();
            }
            break;
        case CP_CYLINDER_SPECTRUM:
            //if (!prop.drawBins.size()) break;
            for (int i = 0; i < prop.points.size(); i++) {
                if(prop.origMags[i] == 0)  continue ;
                ofPushMatrix();
                ofTranslate(prop.points[i].x, prop.points[i].y- prop.drawBins[(i % 10)] *200/2, prop.points[i].z);
                ofDrawCylinder(0,0,0, 10, prop.drawBins[(i % 10)] * 200);
                ofPopMatrix();
                
                //cout << (i % 10) << " " << prop.drawBins[(i % 10)] << endl;
                
            }
            break;
        case CP_RECT:
            //ofNoFill();
            for (int i = 0; i < prop.points.size(); i++) {
                ofPushMatrix();
                ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255);
                ofTranslate(prop.points[i].x-prop.mags[i].x/2, prop.points[i].y-prop.mags[i].x/4, prop.points[i].z);
                ofRotate(-prop.angle, 0, 0, 1);
                //ofRect(0, 0, mags[i].x, mags[i].x/2);
                ofDrawBox(0, 0, 0, prop.mags[i].x, prop.mags[i].x, prop.mags[i].x);
                ofPopMatrix();
            }
            break;
        case CP_RECT_ROUNDED:
            for (int i = 0; i < prop.points.size(); i++) {
                ofRectRounded(prop.points[i].x-prop.mags[i].x/2, prop.points[i].y-prop.mags[i].x/4, prop.mags[i].x, prop.mags[i].x/2, prop.mags[i].x/4);
            }
            break;
        case CP_ELLIPPSE:
            for (int i = 0; i < prop.points.size(); i++) {
                ofEllipse(prop.points[i].x, prop.points[i].y, prop.mags[i].x, prop.mags[i].x/2);
                //ofRect(points[i].x-mags[i].x/2, points[i].y-mags[i].x/2, mags[i].x, mags[i].x);
            }
            break;
        case CP_LINE_IND:
            ofSetLineWidth(10);
            for (int i = 0; i < prop.points.size(); i++) {
                ofLine(prop.points[i].x, prop.points[i].y, prop.points[i].x, prop.points[i].y+prop.mags[i].x);
            }
            break;
        case CP_SPHERE:
            for (int i = 0; i < prop.points.size(); i++) {
                ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255);
                ofDrawSphere(prop.points[i].x, prop.points[i].y, prop.points[i].z, prop.mags[i].x);
            }
        
            if (particleFlg) {
                for (int i = 0; i < prop.mags.size(); i++) {
                    prop.mags[i] *= 10.0;
                }
                prop.vbo.setNormalData(&prop.mags[0], prop.mags.size(), GL_DYNAMIC_DRAW);
                
                glDepthMask(GL_FALSE);
                ofEnableAlphaBlending();
                ofEnableBlendMode(OF_BLENDMODE_ALPHA);
                ofEnablePointSprites();
                shader.begin();
                texture.bind();
                prop.vbo.draw(GL_POINTS, 0, (int)prop.points.size());
                texture.unbind();
                
                shader.end();
                ofDisablePointSprites();
                glDepthMask(GL_TRUE);

            }
            break;
        case CP_TRIANGLE:
            prop.vbo.drawElements(GL_TRIANGLE_STRIP, prop.points.size());
            break;
        case CP_TRIANGLE_IND:
            prop.angle+=5;
            //ofNoFill();
            ofSetLineWidth(10);
            for (int i = 0; i < prop.points.size(); i++) {
                ofPushMatrix();
                //glDepthMask(GL_FALSE);
                ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255,prop.colors[i].a*255);
                ofTranslate(prop.points[i].x, prop.points[i].y);
                ofRotate(prop.angle, 0, 0, 1);
                /*
                ofTriangle(0,
                           -prop.mags[i].x,
                           prop.mags[i].x/-2,
                           prop.mags[i].x/2*sqrt(3),
                           prop.mags[i].x/2,
                           prop.mags[i].x/2*sqrt(3));
                 */
                ofDrawCone(0, prop.mags[i].x/-2,prop.points[i].z, prop.mags[i].x/2, prop.mags[i].x);
                //  glDepthMask(GL_TRUE);
                ofPopMatrix();
            }
            break;
        case CP_CIRCLE:
            for (int i = 0; i < prop.points.size(); i++) {
                ofSetColor(prop.colors[i].r*255, prop.colors[i].g*255, prop.colors[i].b*255);
                ofCircle(prop.points[i].x, prop.points[i].y, prop.points[i].z, prop.mags[i].x/2);
            }
        default:
            break;
    }
}
コード例 #16
0
void urgTimelapse::run(float speed, float periodSize, bool bClockwise, float alignmentAngle, float startPeriod) {
    
    // exit function if frame number is -1
    if (frameNum == -1) return;
    
    // reset frame (MUST DO THIS)
    renderedFrame.clear();
    
    // ------------------------------------
    // ------------ FILL FRAME ------------
    // ------------------------------------
    
    // reset counter
    int scanNum = 0;
    
    // add scans to the mesh as dictated by the frames
    ofBuffer::Line it = buffer.getLines().begin();
    advance(it, frames[frameNum].start);
    ofBuffer::Line end = buffer.getLines().end();
    for (it, end; it != end; ++it) {
        
        // get line
        string line = *it;
        vector<string> values = ofSplitString(line, ",");
        
        // put all the points in a scan in the mesh
        for (int i = minIndex; i < maxIndex; i++) {
            
            // find the x and y coordinates
            float px = ofToFloat(values[2 * i + 1]);
            float py = ofToFloat(values[2 * i + 2]);
            
            // find the vector to this point
            ofVec3f thisPoint(px, py, 0.);
            
            // remove points too close
            double sqDist = thisPoint.distanceSquared(ofVec3f(0.,0.,0.));
            if (sqDist < minSqDist2Cam) continue;
            
            // rotate this point 90 degrees about the z axis to orient it upwards
            thisPoint.rotate(90., ofVec3f(0., 0., 1.));
            
            // apply the alignment angle stretch or compression to realign the two chuncks
            float alignmentFactor = (float)i / 682. * alignmentAngle;
            thisPoint.rotate(alignmentFactor, ofVec3f(0., 0., 1.));
            
            // rotate this point about the y axis an amount proportional to this scanNumber and the number of scans in this frame (since this changes)
            float rotationAmt = (float)scanNum / (float)frames[frameNum].length * periodSize;
            
            // if clockwise is true, rotate in negative direction
            if (bClockwise) rotationAmt *= -1.;
            // if period is 180 and frame is odd, rotate 180 degrees
            if ((int)periodSize == 180 && (frameNum % 2)) rotationAmt += 180.;
            thisPoint.rotate(rotationAmt, ofVec3f(0., 1., 0.));
            
            // add the point to the mesh with a color
            renderedFrame.addVertex(thisPoint);
            renderedFrame.addColor(ofFloatColor(1.));
        }
        
        scanNum++;
        if (scanNum >= frames[frameNum].length) break;
    }
    
    cout << "rendered frame # " << frameNum << endl;
    
    // increment the frame number
    frameNum++;
    if (frameNum >= frames.size()) {
        // stop running this operation
        frameNum = -1;
    }
    
    
    // NOW RENDER
    ofPushMatrix();
    
    // rotate the original frame
    ofRotate(startRotateX, 1, 0, 0);
    ofRotate(startRotateY, 0, 1, 0);
    ofRotate(startRotateZ, 0, 0, 1);
    
    renderedFrame.drawVertices();
    
    ofPopMatrix();
    
    // SAVE IMAGE
    ofSaveFrame();
    
}
コード例 #17
0
//--------------------------------------------------------------
void testApp::draw(){
    // enable lighting //
    ofEnableLighting();
    // enable the material, so that it applies to all 3D objects before material.end() call //
	material.begin();
    // activate the lights //
	if (bPointLight) pointLight.enable();
	if (bSpotLight) spotLight.enable();
	if (bDirLight) directionalLight.enable();
    
    // grab the texture reference and bind it //
    // this will apply the texture to all drawing (vertex) calls before unbind() //
    if(bUseTexture) ofLogoImage.getTextureReference().bind();
    
	ofSetColor(255, 255, 255, 255);
    ofPushMatrix();
    ofTranslate(center.x, center.y, center.z-300);
    ofRotate(ofGetElapsedTimef() * .8 * RAD_TO_DEG, 0, 1, 0);
	ofDrawSphere( 0,0,0, radius);
    ofPopMatrix();
	
	ofPushMatrix();
	ofTranslate(300, 300, cos(ofGetElapsedTimef()*1.4) * 300.f);
	ofRotate(ofGetElapsedTimef()*.6 * RAD_TO_DEG, 1, 0, 0);
	ofRotate(ofGetElapsedTimef()*.8 * RAD_TO_DEG, 0, 1, 0);
	ofDrawBox(0, 0, 0, 60);
	ofPopMatrix();
	
	ofPushMatrix();
	ofTranslate(center.x, center.y, -900);
	ofRotate(ofGetElapsedTimef() * .2 * RAD_TO_DEG, 0, 1, 0);
	ofDrawBox( 0, 0, 0, 850);
	ofPopMatrix();
    
    if(bUseTexture) ofLogoImage.getTextureReference().unbind();
	
	if (!bPointLight) pointLight.disable();
	if (!bSpotLight) spotLight.disable();
	if (!bDirLight) directionalLight.disable();
	
    material.end();
	// turn off lighting //
    ofDisableLighting();
    
	ofSetColor( pointLight.getDiffuseColor() );
	if(bPointLight) pointLight.draw();
    
    ofSetColor(255, 255, 255);
	ofSetColor( spotLight.getDiffuseColor() );
	if(bSpotLight) spotLight.draw();
	
	ofSetColor(255, 255, 255);
	ofDrawBitmapString("Point Light On (1) : "+ofToString(bPointLight) +"\n"+
					   "Spot Light On (2) : "+ofToString(bSpotLight) +"\n"+
					   "Directional Light On (3) : "+ofToString(bDirLight)+"\n"+
					   "Shiny Objects On (s) : "+ofToString(bShiny)+"\n"+
                       "Spot Light Cutoff (up/down) : "+ofToString(spotLight.getSpotlightCutOff(),0)+"\n"+
                       "Spot Light Concentration (right/left) : " + ofToString(spotLight.getSpotConcentration(),0)+"\n"+
                       "Smooth Lighting enabled (x) : "+ofToString(bSmoothLighting,0)+"\n"+
                       "Textured (t) : "+ofToString(bUseTexture,0),
					   20, 20);
}
コード例 #18
0
ファイル: ofxMPMFluid.cpp プロジェクト: stpn/Turing
void ofxMPMFluid::draw(){
	
	// These improve the appearance of small lines and/or points.
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glEnable (GL_LINE_SMOOTH);
	glEnable (GL_POINT_SMOOTH); // in case you want it
	glEnable (GL_MULTISAMPLE);
	glEnable (GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
//	ofSetColor(161,196,134, 204); 
    ofSetColor(255,255,255, 204); 
	glLineWidth(1.0); // or thicker, if you prefer
	glPointSize(2.0);
	ofPushMatrix();
	ofScale(scaleFactor, scaleFactor, 1.0);
	
	// Draw the active particles as a short line, 
	// using their velocity for their length. 
	vector<ofVec2f> verts;

	for (int ip=0; ip<numParticles; ip+=100) {
        
		ofxMPMParticle* p = particles[ip];
		verts.push_back(ofVec2f(p->x, p->y));
		verts.push_back(ofVec2f(p->x - p->u, p->y - p->v));
	}
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, &(verts[0].x));
        float rot = 0;
    float radius = 3;
    for (int i = 0; i<  verts.size(); i++){
        rot += 10%360;    
        glPushMatrix();
        glTranslatef(verts[i].x, verts[i].y, 0);
        ofRotateY(rot);
        
        ofSetLineWidth(2.0f);
        ofSetColor(255, 255, 255);
        for(int i=0; i < 180; i+= 90){
            ofRotate(i);
            ofLine(-1 * radius,0,radius,0);
            ofLine(0.66 * radius, 0, radius, 0.33 * radius); 
            ofLine(0.66 * radius, 0, radius, -0.33 * radius);
            ofLine(-0.66 * radius, 0, -1 * radius, 0.33 * radius);
            ofLine(-0.66 * radius, 0, -1 * radius, -0.33 * radius);
            
        }
        ofRotate(45);
        for(int i=0; i < 180; i += 90){
            ofRotate(i);
            ofLine(-1 * radius,0,radius,0);
            ofLine(0.66 * radius, 0, radius, 0.33 * radius); 
            ofLine(0.66 * radius, 0, radius, -0.33 * radius);
            ofLine(-0.66 * radius, 0, -1 * radius, 0.33 * radius);
            ofLine(-0.66 * radius, 0, -1 * radius, -0.33 * radius);
            
        }
        
        ofPopStyle();
        
        glPopMatrix();

        
    }
    
//	glDrawArrays(GL_POINTS, 0, verts.size());
	glDisableClientState(GL_VERTEX_ARRAY);
	ofPopMatrix();
}
コード例 #19
0
void UR5KinematicModel::draw(bool bDrawDebug){
    
    if(bDrawDebug) {
        ofPushStyle(); {
            ofDrawAxis(1000);
            ofSetColor(255, 255, 0);
            ofDrawSphere(tool.position*ofVec3f(1000, 1000, 1000), 4);
            ofSetColor(225, 225, 225);
        } ofPopStyle();
    }
    
    if(bDrawModel){
        ofQuaternion q;
        ofVec3f offset;
        
        ofMatrix4x4 gmat;
        gmat.makeIdentityMatrix();
        gmat.makeScaleMatrix( 1, 1, 1 );
        
        ofPushMatrix();
        {
            ofPushMatrix();
            {
                for(int i = 0; i < joints.size(); i++)
                {
                    float x;
                    ofVec3f axis;
                    q = joints[i].rotation;
                    q.getRotate(x, axis);
                    ofTranslate(joints[i].offset*1000);
                    gmat.translate( joints[i].offset*1000 );
                    
                    if(bDrawDebug) {
                        ofDrawAxis(10);
                    }
                    ofMatrix4x4 tmat;
                    if(i >= 3){
                        ofPushMatrix();
                        {
                            ofRotateZ(-180);
                            ofRotateX(-180);
                            ofScale(100, 100, 100);
                            meshs[i].draw();
                        }
                        ofPopMatrix();
                    }
                    ofRotate(x, axis.x, axis.y, axis.z);
                    if(i < 3){
                        ofPushMatrix(); {
                            ofRotateZ(-180);
                            ofRotateX(-180);
                            ofScale(100, 100, 100);
                            
                            meshs[i].draw();
                        } ofPopMatrix();
                    }
                }
                toolMesh.draw();
            }
            ofPopMatrix();
        }
        ofPopMatrix();
        
        if (bDrawDebug) {
            ofPushMatrix();
            {
                //            ofRotate(180, 0, 0, 1);
                for(int i = 0; i < nodes.size(); i++){
                    nodes[i].draw();
                }
                tcpNode.draw();
            }
            ofPopMatrix();
        }
    }
}
コード例 #20
0
void Kingyo::display()
{
    
    ofSetColor(r, g, b);
    if (isGolden) ofSetColor(254, 247, 200);
    ofPushMatrix();
    
    
    // 移動先のポイント /////////////////////////////////////////////////////////////////////
    if(esa){
        ofCircle(movePoint.x, movePoint.y, 5);
    }
    
    // 金魚の表示//// /////////////////////////////////////////////////////////////////////
    ofTranslate(pos.x, pos.y);
    ofRotate(atan2(movePoint.y - pos.y, movePoint.x - pos.x) * 180.0 / PI + 95);
    
        
    ofPushMatrix();
    // bodyの回転軸を移動
    ofTranslate(0/CP, 40/CP);
    // 回転軸の表示
    if(kingyo_Bones){
        ofEllipse(0/CP, 0/CP, 5/CP, 5/CP);
    }
    
    // 画像の表示
    if (isGolden) g_body.draw(-21/CP, -83/CP, 43/CP, 83/CP);
    if (!isGolden) body.draw(-21/CP, -83/CP, 43/CP, 83/CP);
    
    ofPopMatrix();
    
    ///////////////////////// 左ヒレ
    ofPushMatrix();
    // ヒレの回転軸を移動
    ofTranslate(-20/CP, -10/CP);
    
    // 骨組みの表示
    if(kingyo_Bones){ ofEllipse(0/CP, 0/CP, 5/CP, 5/CP); }
    //rotate(radians(0));
    // image(名前, bodyの回転軸+ヒレの回転軸の差分, bodyの回転軸+ヒレの回転軸の差分, 位置, 位置);
    if (isGolden) g_left.draw(-15/CP, 0/CP, 13/CP, 18/CP);
    if (!isGolden) left.draw(-15/CP, 0/CP, 13/CP, 18/CP);
    ofPopMatrix();
    
    
    
    ///////////////////////// 右ヒレ
    ofPushMatrix();
    ofTranslate(20/CP, -10/CP);
    
    // 骨組みの表示
    if(kingyo_Bones){ ofEllipse(0/CP, 0/CP, 5/CP, 5/CP); }
    //rotate(radians(0));
    if (isGolden) g_right.draw(3/CP, 0/CP, 13/CP, 18/CP);
    if (!isGolden) right.draw(3/CP, 0/CP, 13/CP, 18/CP);
    ofPopMatrix();
    
    
    // bodyのpopMatrix
    
    
    
    
    ///////////////////////// 尾びれ
    // 左
    ofPushMatrix();
    ofTranslate(0/CP, 45/CP);
    if(kingyo_Bones){ ofEllipse(0/CP, 0/CP, 5/CP, 5/CP); }
    ofRotate(LeftRad);
    ofEnableAlphaBlending();
    if (isGolden) g_LeftTail.draw(-40/CP, 0/CP, 33/CP, 29/CP);
    if (!isGolden) LeftTail.draw(-40/CP, 0/CP, 33/CP, 29/CP);
    ofPopMatrix();
    
    
    ofPushMatrix();
    ofTranslate(0/CP, 45/CP);
    if(kingyo_Bones){ ofEllipse(0, 0, 5, 5); }
    ofRotate(RightRad);
    ofEnableAlphaBlending();
    if (isGolden) g_RightTail.draw(5/CP, 0/CP, 33/CP, 29/CP);
    if (!isGolden) RightTail.draw(5/CP, 0/CP, 33/CP, 29/CP);
    ofPopMatrix();
    
    
    ofPushMatrix();
    ofTranslate(0/CP, 45/CP);
    if(kingyo_Bones){ ofEllipse(0/CP, 0/CP, 5/CP, 5/CP); }
    ofRotate(rad);
    if (isGolden) g_CenterTail.draw(-12/CP, 0/CP, 24/CP, 69/CP);
    if (!isGolden) CenterTail.draw(-12/CP, 0/CP, 24/CP, 69/CP);
    ofPopMatrix();
    
    ofPopMatrix();
    
}
コード例 #21
0
//--------------------------------------------------------------
void testApp::nucleotideDraw(int type2, float nucleoPosX, float nucleoPosY, float nucleoPosZ, float rotAngle, float rotX, float rotY, float rotZ){

	posX = ofGetWidth()/2;
	posY = ofGetHeight()/2;
	posZ = 0;
	radius = 10;
	height = 200;
	dnaImage.getTextureReference().bind();
	//gluSphere(quadric, 200, 100, 100);

	for (int i = 0; i < nucleoNum; ++i){
		//type.push_back(type2);
		if (type2 == 0){
		//GUANINE
			ofPushMatrix();
			ofSetColor(100,100,240);
			ofTranslate(posX, posY, posZ);
			ofRotate(rotAngle, rotX, rotY, rotZ);
			ofSetCylinderResolution(50, 100, 2);
			ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height);
			if (invert == true){
				ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30);
			}else if(invert == false){
				ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30);
			}
			ofPopMatrix();
		}else if(type2 == 1){
		//CYTOSINE
			ofPushMatrix();
			ofSetColor(240,100,100);
			ofTranslate(posX, posY, posZ);
			ofRotate(rotAngle, rotX, rotY, rotZ);
			ofSetCylinderResolution(50, 100, 2);
			ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height);
			if (invert == true){
				ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30);
			}else if(invert == false){
				ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30);
			}
			ofPopMatrix();
		}else if(type2 == 2){
		//ADENINE
			ofPushMatrix();
			ofSetColor(100,240,100);
			ofTranslate(posX, posY, posZ);
			ofRotate(rotAngle, rotX, rotY, rotZ);
			ofSetCylinderResolution(50, 100, 2);
			ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height);
			if (invert == true){
				ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30);
			}else if(invert == false){
				ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30);
			}
			ofPopMatrix();
		}else if(type2 == 3){
		//THYMINE
			ofPushMatrix();
			ofSetColor(240,100,240);
			ofTranslate(posX, posY, posZ);
			ofRotate(rotAngle, rotX, rotY, rotZ);
			ofSetCylinderResolution(50, 100, 2);
			ofDrawCylinder(nucleoPosX, nucleoPosY, nucleoPosZ, radius, height);
			if (invert == true){
				ofDrawSphere(nucleoPosX, nucleoPosY + height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX - 15, nucleoPosY + height/2, nucleoPosZ + 50, 30);
			}else if(invert == false){
				ofDrawSphere(nucleoPosX, nucleoPosY - height/2, nucleoPosZ, 30);
				ofSetColor(255, 217, 0);
				ofDrawSphere(nucleoPosX + 15, nucleoPosY - height / 2, nucleoPosZ + 50, 30);
			}
			ofPopMatrix();
		}
	}
}
コード例 #22
0
ファイル: CloudsIntroSequence.cpp プロジェクト: wasawi/CLOUDS
void CloudsIntroSequence::drawHelperType(){

	ofPushStyle();
	glDisable(GL_DEPTH_TEST);
	ofDisableLighting();
    
	if(!helperFont.isLoaded() || currentHelperFontSize != helperFontSize){
		//helperFont.loadFont(GetCloudsDataPath() + "font/Blender-BOOK.ttf", helperFontSize);
#ifdef OCULUS_RIFT
		helperFont.loadFont(GetFontPath(), helperFontSize-2	); //hack!
#else
		helperFont.loadFont(GetFontPath(), helperFontSize	); //hack!
#endif		
		currentHelperFontSize = helperFontSize;
	}

	string helpHoverText;
	ofVec3f basePosition(0,0,0);
	float helperTextOpacity = 0.0;
	float scaleModifier = 1.0;// * ofGetMouseX() / ofGetWidth();

	
	#ifdef OCULUS_RIFT
	if(!startedOnclick){
		if(introNodeThree.hover || introNodeTwo.finished){
			helpHoverText = "< " + GetTranslationForString("LOOK CENTER");
			basePosition = introNodeTwo.worldPosition;
			helperTextOpacity = powf(ofMap(ofGetElapsedTimef(),
										   CalibrationNode::nodeActivatedTime,
										   CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.) * (1.0 - introNodeThree.percentComplete);
		}
		else if(introNodeTwo.hover || introNodeOne.finished){
			helpHoverText = GetTranslationForString("LOOK RIGHT") + " >";
			basePosition = introNodeOne.worldPosition;
			helperTextOpacity = powf(ofMap(ofGetElapsedTimef(),
										   CalibrationNode::nodeActivatedTime,
										   CalibrationNode::nodeActivatedTime+.8,0.0,.8,true), 2.);
		}
		else {
			helpHoverText = "< " + GetTranslationForString("LOOK LEFT");
			basePosition = introNodeThree.worldPosition;
			helperTextOpacity = (currentTitleOpacity - titleTypeOpacity) * (1.0 - introNodeOne.percentComplete);
		}
		helperFont.setLetterSpacing(helperFontTracking);
	}

	#endif
	
	if(caughtQuestion != NULL){
		basePosition = caughtQuestion->hoverPosition;
		helpHoverText = GetTranslationForString( caughtQuestion->question );
		helperTextOpacity = ofMap(caughtQuestion->hoverPercentComplete, 0.0, .05, 0.0, 1.0, true);

		scaleModifier = .5;
		helperFont.setLetterSpacing(helperFontTracking*.1);
	}

    //draw the text
	if(helpHoverText != ""){
        ofPushMatrix();
		helpHoverText = ofToUpper(helpHoverText);
		
		float hoverTextWidth = helperFont.stringWidth(helpHoverText);
		float hoverTextWidth2,questionTextHeight2;
		string secondLine;
		bool twoLines = hoverTextWidth > 500;
		if(helpHoverText.find("\n") != string::npos){
			twoLines = true;
			vector<string> split = ofSplitString(helpHoverText, "\n", true,true);
			helpHoverText = split[0];
			secondLine = split[1];
			hoverTextWidth = helperFont.stringWidth(helpHoverText);
			hoverTextWidth2 = helperFont.stringWidth(secondLine);
            
//            cout << "QUESTION " << helpHoverText << " " << secondLine << endl;
		}
		else if(twoLines){
			vector<string> pieces = ofSplitString(helpHoverText, " ", true,true);
			vector<string> firstHalf;
			vector<string> secondHalf;
			int halfsize = pieces.size() / 2;
			firstHalf.insert(firstHalf.begin(), pieces.begin(), pieces.begin() + halfsize);
			secondHalf.insert(secondHalf.begin(), pieces.begin() + halfsize, pieces.end());
			helpHoverText = ofJoinString(firstHalf, " ");
			secondLine = ofJoinString(secondHalf, " ");
			hoverTextWidth  = helperFont.stringWidth(helpHoverText);
			hoverTextWidth2 = helperFont.stringWidth(secondLine);
		}
		float hoverTextHeight = helperFont.stringHeight(helpHoverText);
		
        //basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max);

		#ifdef OCULUS_RIFT
		getOculusRift().multBillboardMatrix( basePosition );
		#else
		ofTranslate(basePosition);
		#endif
		ofRotate(180, 0, 0, 1); //flip around
		ofScale(scaleModifier*helperFontScale,
				scaleModifier*helperFontScale,
				scaleModifier*helperFontScale);
		
		ofSetColor(255,255*helperTextOpacity);
		
        bool showAbove = !bUseOculusRift && caughtQuestion != NULL && caughtQuestion->tunnelQuadrantIndex == 2;
		int yOffsetMult = (showAbove) ? -1 : 1;
		//helperFont.drawString(helpHoverText, -hoverTextWidth/2, yOffsetMult * (helperFontY - hoverTextHeight/2) );
        
//        cout << "helper text opacity " << helperTextOpacity << endl;
//        cout << "helper font y " << helperFontY << endl;
		if(twoLines){
            if(showAbove){
//                cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " <<  helperFontY + hoverTextHeight*1.5 << endl;
//                cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " << hoverTextHeight << endl;
                helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) );
                helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
            }
            else{
//                cout << "drawing " << secondLine << " w " << hoverTextWidth << " h " <<  hoverTextHeight << endl;
//                cout << "drawing " << helpHoverText << " w " << hoverTextWidth << " h " << hoverTextHeight << endl;
                helperFont.drawString(secondLine, -hoverTextWidth2*.5, yOffsetMult * (helperFontY + hoverTextHeight*1.5) );
                helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
            }
		}
        else{
            helperFont.drawString(helpHoverText, -hoverTextWidth*.5, yOffsetMult * (helperFontY - hoverTextHeight*.5));
        }
		ofPopMatrix();
	}
    
    if(firstQuestionStopped){
        ofPushMatrix();
        
        float questionhintAlpha = ofMap(ofGetElapsedTimef(),
                                        firstQuestionStoppedTime, firstQuestionStoppedTime+2,
                                        0.0, .2, true) * (1.0-helperTextOpacity);
        
        float hintTextWidth  = helperFont.stringWidth(GetTranslationForString("SELECT A QUESTION"));
		float hintTextHeight = helperFont.stringHeight(GetTranslationForString("SELECT A QUESTION"));
		basePosition = ofVec3f(0,0,warpCamera.getPosition().z + questionZStopRange.max);
#ifdef OCULUS_RIFT
		getOculusRift().multBillboardMatrix( basePosition );
#else
		ofTranslate(basePosition);
#endif
		ofRotate(180, 0, 0, 1); //flip around
		ofScale(helperFontScale*.8,
				helperFontScale*.8,
				helperFontScale*.8);
        
        ofSetColor(255, 255*questionhintAlpha);
		helperFont.drawString(GetTranslationForString("SELECT A QUESTION"), -hintTextWidth*.5, hintTextHeight*.5 );

        if(caughtQuestion != NULL){
            float questionHoldAlpha = ofMap(caughtQuestion->hoverPercentComplete, .2, .3, 0.0, .2, true);
            ofSetColor(255, 255*questionHoldAlpha);
#ifdef MOUSE_INPUT
//			string textPrompt = GetTranslationForString("CLICK TO SELECT");
            string textPrompt = GetTranslationForString("");
#else
			string textPrompt = GetTranslationForString("HOLD TO SELECT");
#endif
            hintTextWidth = helperFont.stringWidth(textPrompt);
            hintTextHeight = helperFont.stringWidth(textPrompt);
            helperFont.drawString(textPrompt, -hintTextWidth*.5, hintTextHeight*.5 );
        }
        
        ofPopMatrix();
    }

    ofEnableLighting();
	glEnable(GL_DEPTH_TEST);
	ofPopStyle();

}
コード例 #23
0
void ofApp::rotateScreen(float degrees, int amount) {
    ofTranslate(amount, amount, 0);
    ofRotate(degrees);
    ofTranslate(-amount, -amount, 0);
}
コード例 #24
0
ファイル: testApp.cpp プロジェクト: jchomko/CarteBlanche
void testApp::drawBoids(){
	
	//Set background to be transparent
	ofBackground(255, 255, 255, 0); 
	
	//Show Debug?
	if (cvImgDisp) {  
		pth.display();
	}
	
	//If the number of displayed boids is greater than the desired number
	if ( showBoidsHead-showBoidsTail > nrDisplaySequences ){
		removeLastBoid = true;
	}
	
	//Color affects image tint, set to full opacity
	ofSetColor(255, 255, 255,255);  
	
	//Variables for boid displaying
	ofPoint pathPoint;
	ofVec3f loc;
	
	float zScale;
	float lFlap;
    float lLastFlap;
	
	//Boid display boolean
    if(showBoids)
	{
        
	for (int j = showBoidsTail; j < showBoidsHead; j ++)
		{
            
			//Loop i around the size of the buffer using modulo
            int i = j % bufferSize;
            
			//This function can be removed once the preferred values are set
			flock.boids[i].updateValues(setSeparation,setAlignment,setCohesion,
                                    setForce*0.001,setMaxSpeed,setDesiredSeparation, setNeighbordist);
			
			flock.boids[i].update(flock.boids,hold);
		
			//Get boids location
			loc.set(flock.boids[i].getLoc());
		
			if(hold == 1)
			{ //If the boids are not flying in
			//Get the boid's predicted location
			ofVec2f pl(flock.boids[i].getPredictLoc());
			//Get the point on the path closest to that predicted location
			pathPoint = pth.points.getClosestPoint(pl);
			//Seek that point
			flock.boids[i].seek(pathPoint);
			}
		
		//Draw the Sequence 
        ofPushMatrix();
		
		//Get the dynamic scale of the boids
		//This perspective effet could be replaced by having 3d boids
		zScale = flock.boids[i].getScale();
		//Multiply this value by the scaleMagnitude slider value
		zScale *= scaleMagnitude;

		//Set coordinates
		ofTranslate(loc.x+pan, loc.y);  	
		
		//Add 90 degrees of rotation to account for the camera's orientation
		//this may need to change depending on where the camera is placed in future
		ofRotate(loc.z+90); 
		
		//Draw the desired sequence, and retrieve the flap data
		lFlap = bufferSequences[(i) % bufferSize].playBack(playbackIndex, scale+zScale);
        
        //Add flap data to that boid
			//Can also be done with a threshold
		flock.boids[i].push(lFlap*flapMagnitude);
		
		
		ofPopMatrix();
			
		//If we/re looking to remove the last boid the last boid goes offscreen
            if(removeLastBoid &&
               flock.boids[showBoidsTail%bufferSize].getLoc().x  > ofGetWidth()-100)
			{
				//Increase the show buffer
				showBoidsTail ++;
				//Stop removing the last boid
                removeLastBoid = false;
                
            }
		} 
    }
	
	
	if(play == 1) {
		
		//Check for new frame and increase index if frame is new
		if(playIndex > lastPlayIndex){ 
			
			// Dont go out of bounds
			if(playbackIndex == 99){   
				playbackIndex = 0;
			}else {
				playbackIndex++;
			}
		}
	}
	
	//Load screen data
	backgroundTex.loadScreenData(0, 0, ofGetWidth(),ofGetHeight());
	//Publish screen data to syphon 
	backgroundServer.publishTexture(&backgroundTex);
	
	
	
}
コード例 #25
0
ファイル: ofApp.cpp プロジェクト: firmread/ofDemystified
//--------------------------------------------------------------
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 );
	*/
}
コード例 #26
0
void ofxRParticlePlexusRenderer::draw()
{
    activateBlending();
    ofSetLineWidth(*lineWidth);
    billBoard();
    ofSetRectMode(OF_RECTMODE_CENTER);
    for(vector<ofxRParticle *>::iterator it = (*particles).begin(); it != (*particles).end(); it++)
    {
        ofxRParticle *p = (*it);
        ofColor clr = p->getColor();
        if(*bDrawSprites)
        {
            glPushMatrix();
            ofVec3f pos = p->getPos();
            glTranslatef(pos.x, pos.y, pos.z);
            ofRotate(angle, axis.x, axis.y, axis.z);
            ofSetColor(clr);
            float r = p->getRadius()*(*radiusScalar);
            glow->draw(0, 0, r, r);
            glPopMatrix();
        }

        if(*bDrawLines)
        {
            ofxNeighborParticleData *data = (ofxNeighborParticleData *) p->getData();

            int n = data->neighbors.size();
            if(n > *lowerRange && n < *upperRange)
            {
                glBegin(GL_TRIANGLE_FAN);
                ofSetColor(clr, (*triangleAlpha)*data->distances[0]);
                glVertex3fv(p->getPos().getPtr());
                int i = 0;
                for(vector<ofxRParticle *>::iterator nit = data->neighbors.begin(); nit != data->neighbors.end(); ++nit)
                {
                    ofxRParticle *other = (*nit);
                    ofSetColor(other->getColor(), (*triangleAlpha)*data->distances[i]);
                    glVertex3fv(other->getPos().getPtr());
                    i++;
                }
                glEnd();
            }
            else
            {
                glBegin(GL_LINES);
                int i = 0;
                for(vector<ofxRParticle *>::iterator nit = data->neighbors.begin(); nit != data->neighbors.end(); ++nit)
                {
                    ofSetColor(clr, (*lineAlpha)*data->distances[i]);
                    glVertex3fv(p->getPos().getPtr());
                    ofxRParticle *other = (*nit);

                    ofVec3f avg = (p->getPos() + other->getPos())/2.0;
                    ofSetColor(255, 255, 255, 0.0);
                    glVertex3fv(avg.getPtr());
                    glVertex3fv(avg.getPtr());

                    ofSetColor(other->getColor(), (*lineAlpha)*data->distances[i]);
                    glVertex3fv(other->getPos().getPtr());
                    i++;
                }
                glEnd();
            }
        }
    }
    ofSetRectMode(OF_RECTMODE_CORNER);
}
コード例 #27
0
//--------------------------------------------------------------
void LeapVisualizer::drawArm (Hand & hand,ofxLeapMotion & leap){
	
	// Draw the wrist and elbow points.
	Arm arm = hand.arm();
	if (arm.isValid()){
		
		ofPoint handPt   = leap.getofPoint ( hand.palmPosition());
		ofPoint handNorm = leap.getofPoint ( hand.palmNormal());
		ofPoint wristPt  = leap.getofPoint ( arm.wristPosition());
		ofPoint elbowPt  = leap.getofPoint ( arm.elbowPosition());
		
		float basisLen = 50.0;
		
		
		if (bDrawSimple){
			ofSetColor(ofColor::white);
			ofDrawSphere(handPt,  8.0);
			ofDrawSphere(wristPt, 8.0);
			ofDrawSphere(elbowPt, 8.0);
			
			ofLine(handPt, wristPt);
			ofLine(wristPt, elbowPt);
			ofLine(handPt, handPt+ basisLen*handNorm);
			ofDrawSphere(handPt+ basisLen*handNorm, 2.0);
			
			// draw the rotation vectors of the hand.
			{
				Leap::Matrix handMatrix = hand.basis();
				ofPoint handBasisX = leap.getofPoint( handMatrix.xBasis);
				ofPoint handBasisY = leap.getofPoint( handMatrix.yBasis);
				ofPoint handBasisZ = leap.getofPoint( handMatrix.zBasis);
				
				glLineWidth(2.0);
				ofSetColor(ofColor::red  );	ofLine(handPt, handPt + basisLen*handBasisX);
				ofSetColor(ofColor::green);	ofLine(handPt, handPt + basisLen*handBasisY);
				ofSetColor(ofColor::blue );	ofLine(handPt, handPt + basisLen*handBasisZ);
				glLineWidth(1.0);
				
				// draw the identity of the hand (left or right)
				string whichHandString = "RIGHT";
				if (hand.isLeft()){
					whichHandString = "LEFT";
				}
				// float handConfidence = hand.confidence();
				// whichHandString += " " + ofToString(handConfidence);
				
				ofSetColor(ofColor::white);
				ofDrawBitmapString(whichHandString, (handPt + (basisLen*1.2)*handBasisY));
			}
			
			// draw the rotation vectors of the arm.
			{
				Leap::Matrix armMatrix = arm.basis();
				ofPoint armBasisX = leap.getofPoint( armMatrix.xBasis);
				ofPoint armBasisY = leap.getofPoint( armMatrix.yBasis);
				ofPoint armBasisZ = leap.getofPoint( armMatrix.zBasis);
				
				glLineWidth(2.0);
				ofSetColor(ofColor::red  );	ofLine(wristPt, wristPt + basisLen*armBasisX);
				ofSetColor(ofColor::green);	ofLine(wristPt, wristPt + basisLen*armBasisY);
				ofSetColor(ofColor::blue );	ofLine(wristPt, wristPt + basisLen*armBasisZ);
				glLineWidth(1.0);
			}
			
		} else {
			
			// Draw a cylinder between two points, properly oriented in space.
			float armWidth = arm.width();
			float dx = wristPt.x - elbowPt.x;
			float dy = wristPt.y - elbowPt.y;
			float dz = wristPt.z - elbowPt.z;
			float dh = sqrt(dx*dx + dy*dy + dz*dz);
			
			ofPushMatrix();
			{
				ofTranslate( (elbowPt.x+wristPt.x)/2, (elbowPt.y+wristPt.y)/2, (elbowPt.z+wristPt.z)/2 );
				
				float theta =   90 - RAD_TO_DEG * asin(dz/dh);
				float phi   =        RAD_TO_DEG * atan2(dy,dx);
				ofRotate(phi,   0,0,1);
				ofRotate(theta, 0,1,0);
				ofRotate(90,	1,0,0);
				
				// Get the arm Matrix, which provides its orthogonal basis vectors.
				Leap::Matrix armMatrix = arm.basis();
				ofPoint armBasisY = leap.getofPoint( armMatrix.yBasis);
				float ax = armBasisY.x;
				float ay = armBasisY.y;
				float az = armBasisY.z;
				
				// Compute the longitudinal rotation of the arm.
				// Sheesh, I really need to learn 3D matrix math.
				ofNode armBasisYNode;
				armBasisYNode.setPosition(armBasisY);
				armBasisYNode.rotateAround(0-   phi, ofVec3f(0,0,1), ofVec3f(0,0,0));
				armBasisYNode.rotateAround(0- theta, ofVec3f(0,1,0), ofVec3f(0,0,0));
				armBasisYNode.rotateAround(0-    90, ofVec3f(1,0,0), ofVec3f(0,0,0));
				ofPoint newArmBasisY = armBasisYNode.getPosition();
				float armRotation = RAD_TO_DEG * atan2f(newArmBasisY.z, newArmBasisY.x);
				
				ofPushMatrix();
				{
					ofRotate(armRotation, 0,-1,0);
					float armThicknessRatio = 0.6;
					glScalef(armThicknessRatio, 1.0, 1.0);
					ofSetColor(ofColor::magenta);
					
					// Oblate arm cylinder
					ofDrawCylinder (armWidth/2.0, dh);
					
					// Wrist endcap
					ofPushMatrix();
					ofTranslate(ofPoint(0, dh/2,0));
					glScalef(1.0, armThicknessRatio, 1.0);
					ofDrawSphere(armWidth/2.0);
					ofPopMatrix();
					
					// Elbow endcap
					ofPushMatrix();
					ofTranslate(ofPoint(0, -dh/2,0));
					glScalef(1.0, armThicknessRatio, 1.0);
					ofDrawSphere(armWidth/2.0);
					ofPopMatrix();
					
				} // Close popMatrix
				ofPopMatrix();
			} // Close popMatrix
			ofPopMatrix();
		} // Close if !drawSimple
	} // Close if arm isValid
}
コード例 #28
0
ファイル: ofApp.cpp プロジェクト: XuXo/openFrameworks_Chinese
//--------------------------------------------------------------
void ofApp::draw(){
	if( oneShot ){
		ofBeginSaveScreenAsPDF("screenshot-"+ofGetTimestampString()+".pdf", false);
	}
	
	ofSetColor(54);
	ofDrawBitmapString("PDF OUTPUT EXAMPLE", 32, 32);
	if( pdfRendering ){
		ofDrawBitmapString("press r to stop pdf multipage rendering", 32, 92);
	}else{	
		ofDrawBitmapString("press r to start pdf multipage rendering\npress s to save a single screenshot as pdf to disk", 32, 92);
	}
		
		
	ofFill();		
	ofSetColor(54,54,54);
	ofDrawBitmapString("TTF Font embdedded into pdf as vector shapes", 32, 460);
	
	if( oneShot || pdfRendering ){
		font.drawStringAsShapes("Current Frame: ",  32, 500);
		ofSetColor(245, 58, 135);
		font.drawStringAsShapes( ofToString(ofGetFrameNum()), 32 + font.getStringBoundingBox("Current Frame: ", 0, 0).width + 9, 500);
	}else{
		font.drawString("Current Frame: ",  32, 500);	
		ofSetColor(245, 58, 135);		
		font.drawString( ofToString(ofGetFrameNum()), 32 + font.getStringBoundingBox("Current Frame: ", 0, 0).width + 9, 500);		
	}
	
	
	ofSetColor(54,54,54);
	ofDrawBitmapString("Images can also be embedded into pdf", 32, dropZoneRects[0].y - 18);
	
	ofSetRectMode(OF_RECTMODE_CORNER);
	ofNoFill();
	for(unsigned int k = 0; k < dropZoneRects.size(); k++){
		ofSetColor(54,54,54);
		ofRect(dropZoneRects[k]);
		ofSetColor(245, 58, 135);		
		ofDrawBitmapString("drop images here", dropZoneRects[k].getCenter().x - 70, dropZoneRects[k].getCenter().y);
	}

	ofSetColor(255);
	for(unsigned int j = 0; j < images.size(); j ++){
		if( images[j].width > 0 ){
			
			float tw = 300;
			float th = 200;
			
			if( images[j].getWidth() / images[j].getHeight() < tw / th ){
				tw = th * ( images[j].getWidth() / images[j].getHeight() );
			}else{
				th = tw * ( images[j].getHeight() / images[j].getWidth() );			
			}
			
			images[j].draw(dropZoneRects[j].x, dropZoneRects[j].y, tw, th);
			
		}
	}
	
	//lets draw a box with a trail
    //让我们画一个跟着尾巴的方形
	ofSetColor(245, 58, 135);
	
	ofRectangle boxBounds(32, 500, ofGetWidth()-32, 250);
	
	//lets get a noise value based on the current frame
    //让我们设置噪点值基于现在的桢
	float noiseX = ofNoise(float(ofGetFrameNum())/600.f, 200.0f);
	float noiseY = ofNoise(float(ofGetFrameNum())/800.f, -900.0f);

	ofNoFill();
	ofBeginShape();
	ofVertices(boxTrail);
	ofEndShape(false);
	
	ofFill();
	ofSetRectMode(OF_RECTMODE_CENTER);

	ofPushMatrix();
		float x = ofMap( noiseX, 0, 1, boxBounds.x, boxBounds.x + boxBounds.width, true);
		float y = ofMap( noiseY, 0, 1, boxBounds.y, boxBounds.y + boxBounds.height, true);

		ofTranslate(x, y, 0);
		ofRotate(angle);
		ofRect(0, 0, 30, 30);
	ofPopMatrix();	
	
	if( boxTrail.size() == 0 || ( boxTrail.back() - ofPoint(x, y) ).length() > 1.5 ){
		boxTrail.push_back(ofPoint(x, y));
	}
	
	if(boxTrail.size() > 800 ){
		boxTrail.erase(boxTrail.begin(), boxTrail.begin()+1);
	}
	
	if( oneShot ){
		ofEndSaveScreenAsPDF();
		oneShot = false;
	}	
}
コード例 #29
0
ファイル: testApp.cpp プロジェクト: crubier/QuaternionDisplay
//--------------------------------------------------------------
void testApp::draw(){
    
                        /////////// SHADERRRRRRRRRRR
    shader.begin();
//    //we want to pass in some varrying values to animate our type / color
//    shader.setUniform1f("timeValX", ofGetElapsedTimef() * 0.1 );
//    shader.setUniform1f("timeValY", -ofGetElapsedTimef() * 0.18 );
//    
//    //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.setUniform4f("orientation", curRot.w(), curRot.x(), curRot.y(), curRot.z());
                        /////////// SHADERRRRRRRRRRR
                        
                        
    
    
    
	ofBackground(0);
	ofSetColor(255, 255, 255, 20);
	
	
	//draw a translucent wireframe sphere (ofNoFill() is on)
	ofPushMatrix();

    //Extract the rotation from the current rotation
    ofVec3f axis;
    float angle;
    curRot.getRotate(angle, axis);
    

	ofSphere(0, 0, 0, 1);
	ofRotate(angle, axis.x, axis.y, axis.z);
	ofPopMatrix();
	
//	ofSetColor(255);	
//	for(int i = 0; i < cities.size(); i++){
//		
//		//three rotations
//		//two to represent the latitude and lontitude of the city
//		//a third so that it spins along with the spinning sphere 
//		ofQuaternion latRot, longRot, spinQuat;
//		latRot.makeRotate(cities[i].latitude, 1, 0, 0);
//		longRot.makeRotate(cities[i].longitude, 0, 1, 0);
//		spinQuat.makeRotate(angle, axis.x, axis.y, axis.z);
//		
//		//our starting point is 0,0, on the surface of our sphere, this is where the meridian and equator meet
//		ofVec3f center = ofVec3f(0,0,1);
//		//multiplying a quat with another quat combines their rotations into one quat
//		//multiplying a quat to a vector applies the quat's rotation to that vector
//		//so to to generate our point on the sphere, multiply all of our quaternions together then multiple the centery by the combined rotation
//		ofVec3f worldPoint = latRot * longRot * spinQuat * center;
//		
//		//draw it and label it
//		ofLine(ofVec3f(0,0,0), worldPoint);
//
//		//set the bitmap text mode billboard so the points show up correctly in 3d
//		ofDrawBitmapString(cities[i].name, worldPoint );
//	}
//	
//	ofPopMatrix();
    
                            /////////// SHADERRRRRRRRRRR
    shader.end();
    
                            /////////// SHADERRRRRRRRRRR
}
コード例 #30
0
void ofApp::rotateScreen(float degrees) {
    ofTranslate(gif.halfWidth, gif.halfHeight, 0);
    ofRotate(degrees);
    ofTranslate(-gif.halfWidth, -gif.halfHeight, 0);
}