void ofxMarchingCubes::vertexInterp(float threshold,const ofPoint& p1,const ofPoint& p2, float valp1, float valp2, ofPoint& theVertice){
	float mu;
	if (ABS(threshold-valp1) < 0.00001){
		theVertice.set(p1.x, p1.y, p1.z);
		return;
	}
	if (ABS(threshold-valp2) < 0.00001){
		theVertice.set(p2.x, p2.y, p2.z);
		return;
	}
	if (ABS(valp1-valp2) < 0.00001){
		theVertice.set(p1.x, p1.x, p1.z);
		return;
	}
	mu = (threshold - valp1) / (valp2 - valp1);
	theVertice.x = p1.x + mu * (p2.x - p1.x);
	theVertice.y = p1.y + mu * (p2.y - p1.y);
	theVertice.z = p1.z + mu * (p2.z - p1.z);
}
bool findClosestIntersectionLineAndPoly( ofPoint a, ofPoint b, vector<ofPoint> pts, ofPoint & closestPoint, int & sideId )
{
    if(pts.size() <= 0 ) return false;
	
	vector<float> dist;
    vector<ofPoint> ipts;
	vector<int> ids;
	
	//if( pts[0].x != pts[ pts.size()-1].x && pts[0].y != pts[ pts.size()-1].y)
	pts.push_back(pts[0]);
		
    for( int i = 1; i < pts.size(); i++)
    {
		ofPoint iPt;
		if ( intersectionTwoLines( pts[i-1], pts[i], a, b, &iPt ) )
		{
			dist.push_back( ( (a.x-iPt.x) *(a.x-iPt.x) + (a.y-iPt.y)*(a.y-iPt.y) ) );
			ipts.push_back( iPt );
			ids.push_back(i-1);
		}
    }
	
	closestPoint.set(0,0);
	if( ipts.size() <= 0 ) return false;
	
    ofPoint p = ofPoint(0,0);
    float cdist = 0;
	
    for( int i = 0; i < dist.size(); i++)
    {
        if( i == 0 || dist[i] < cdist )
        {
            cdist = dist[i];
            p.set( ipts[i].x,ipts[i].y );
			sideId = ids[i];
        }
    }
	
	closestPoint.set(p.x,p.y);
    
	return true;
	
}
//--------------------------------------------------------------
void ofApp::setup(){
    ofSetWindowShape(1024,1024);
    ofSetBackgroundAuto(true);
    //ofBackground(0,0,0); // background
    ofBackground(128,128,128); // background
    
    imageCrystal.loadImage("crystal.jpg");  //load initial image
    
    
    point.set(10,10);
    ofEnableBlendMode(OF_BLENDMODE_SUBTRACT);
}
//--------------------------------------------------------------
void camApp::draw(){

	//hitTest();
	ofSetupScreen();
	
	float width  = ofGetWidth();
	float height = ofGetHeight();

	//TODO: check why the background was fading weird on rise background - OpenGL related bug?

	ofEnableAlphaBlending();	
	ofSetColor(255, 255, 255, 255);
	background.draw(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight() );	

	ofSetColor(255, 255, 255, ofMap(riseFallPct, 0.49, 0.0, 0, 255, true));	
	background2.draw(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight());

	world.setScale(ofGetWidth(), ofGetHeight(), ofGetWidth());
	world.setOrigin(ofPoint(ofGetWidth()/2, ofGetHeight()/2, 0.0));
	world.begin();
				
		world.ourCameraSetup(width/2, height/2, 0.0, width, height, fov );	

		//world.drawDebugGrid();
		glDisable(GL_DEPTH_TEST);			

		sceneGraph.updateCameraPos(world.camPos + ofPoint(0, 0, world.camDist));
		sceneGraph.sortZ();
		
		ofRectangle clipRect;
		
		clipRect.width	= 2.0 * ofGetWidth();
		clipRect.height	= 2.2 * ofGetHeight(); // lets give us some extra room!
		clipRect.x		= world.camPos.x - clipRect.width/2;
		clipRect.y      = world.camPos.y - clipRect.height/2;
		
		//TODO: MAKE PLANT CLIPPING BETTER
		sceneGraph.renderWithClipping(clipRect, -180+world.camPos.z, 100 + world.camPos.z,  world.camDist, fov );	
				
		hand.updateCamToScreenCoords();
		
		GLdouble model_view[16];
		glGetDoublev(GL_MODELVIEW_MATRIX, model_view);

		GLdouble projection[16];
		glGetDoublev(GL_PROJECTION_MATRIX, projection);

		GLint viewport[4];
		glGetIntegerv(GL_VIEWPORT, viewport);			
												
		GLdouble X, Y, Z = 0;	
		gluProject(myPerson.pos.x, myPerson.pos.y, myPerson.pos.z, model_view, projection, viewport, &X, &Y, &Z);
		
		personScreenPos.set(X, ofGetHeight()-Y, Z);
	
	world.end();
	
	ofSetupScreen();	
	
	//this node draws in screen space.
	hand.draw();
	
	if( percentOver > 0.0 ){
		ofSetColor(255, 255, 255, 255*percentOver*1.2);	
		
		if( endCreatedInRise ){
			backgroundEnd.draw(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight());
		}else{
			backgroundEnd2.draw(ofGetWidth()/2, ofGetHeight()/2, ofGetWidth(), ofGetHeight());
		}
		
		world.begin();
			world.ourCameraSetup(width/2, height/2, 0.0, width, height, fov );
			endGraphic.draw();	
			myPerson.draw();
		world.end();
		ofSetupScreen();	
	}
	
	if( howTo.state != NODE_INACTIVE ){
		howTo.draw();
		myPerson.drawAtScreenPos(personScreenPos.x, personScreenPos.y, 0);
	}	
					
	ofSetColor(10, 50, 150);
	ofDrawBitmapString(hitsString, 10, 50);
	
	ofEnableAlphaBlending();

}
Example #5
0
void testApp::draw() {
	// clear depth buffer (but not color buffer)
	glClear(GL_DEPTH_BUFFER_BIT);
	
	// enable blending
	glEnable(GL_BLEND);
	
	// choose semi-transparent black color
	myObj.setColor(0, 0, 0, 0.05f);
	
	// draw a black semi-transparent rectangle across whole screen to fade it out a bit
	myObj.drawRect(0, 0, ofGetWidth(), ofGetHeight());
	
	// disable blending
	glDisable(GL_BLEND);
	
	
	// get current time (could use ofGetElapsedTimef() but I DONT want it to be fps independant
	// cos when I'm saving frames and it's running slow I want it to behave the same
	float curTime = ofGetFrameNum() * 1.0f/60.0f;
	
	// choose start rotation based on curTime
	float theta = sin(curTime * 0.17f) * TWO_PI;
	
	// set start position offset from center of screen
	float startOffset = -50.0f * sin(curTime * 0.09f);
	pos.set(ofGetWidth()/2 + cos(theta) * startOffset, ofGetHeight()/2 + sin(theta) * startOffset, 0);
	
	// begin a triangle strip
	myObj.begin(GL_TRIANGLE_STRIP);
	for(int i=0; i<5000; i++) {
		// calculate and set colors
		// RGB components modulate sinusoidally, frequency increases with iteration count
		myObj.setColor(sin(curTime * 0.8f + i * 0.0011f) * 0.5f + 0.5f, sin(curTime * 0.7f + i * 0.0013f) * 0.5f + 0.5f, sin(curTime * 0.3f + i * 0.0017f) * 0.5f + 0.5f);
		
		// do some maths to calculate vertex positions
		// modulate theta (offset rotation) sinusoidally, frequency increases with iteration count
		// use two modulations with different frequencies to create complex harmonic motion 
		theta += sin(curTime * 0.1f + i * 0.00062f) * 2.0f * DEG_TO_RAD * i * 0.0004 + sin(curTime*0.2f + i * 0.0009f) * 3.0f * DEG_TO_RAD;
		float cos_t = cos(theta);
		float sin_t = sin(theta);
		
		// x, y position cumulatively rotates
		// z position modulates sinusoidally, frequency increases with iteration count
		pos += ofPoint(cos_t, sin_t, sin(curTime * 0.5f + i*0.002f) * 0.5);
		
		// send vertex data to myObj
		myObj.addVertex(pos.x, pos.y, pos.z);
		
		// do some math to calculate another vertex position
		// perpendicular to rotation
		// thickness modulates sinusoidally, frequency increases with iteration count
		// also modulation frequency sinusoidally
		ofPoint pos2 = pos + ofPoint(sin_t, -cos_t) * ofMap(sin(curTime * 0.4f * ( 1.0f + i * 0.001f) + i * 0.06f + sin(i*0.001f) * 0.2f), -1, 1, 5, 10 +  i * 0.01f);
		
		// place second vertex (can also pass pointer (array) to coordinates)
		myObj.addVertex2v(pos2.v);
	}
	
	// end vertices and draw to screen
	myObj.end();
}
Example #6
0
//--------------------------------------------------------------
void testApp::setup(){

    
    fadeActiveVal = 0;
    fadeToBlack = 0;
    
  
    // --------------- setup the gui window
    GUI.setup(ofRectangle(0,0,500,800), "my sample gui");
    GUI.setEventInterface(this);
    GUI.addButton("repeatSound", "repeat sound", ofRectangle(10,10,120,30));
    GUI.addButton("newColor", "new color", ofRectangle(10,50,120,30));
    GUI.addTextEntry("textBox", "please enter text here", ofRectangle(10,120,180,90));
    
    
    GUI.addSlider("volSmth", ofRectangle(10,260,180,30), 0, 1, 0.8, &ACM.volumeSmoothing);
    GUI.addSlider("hueRange", ofRectangle(10,300,180,30), 0,400,35, &ACM.hueRange);
    GUI.addSlider("hueShiftValStart", ofRectangle(10,340,180,30), 0,1,0.2, &ACM.hueShiftValStart);
    GUI.addSlider("darkness", ofRectangle(10,340+40,180,30), 0,1,0.5, &ACM.darkness);
    GUI.addSlider("hueFadeRate", ofRectangle(10,340+80,180,30), 0,1,0.96, &ACM.hueFadeRate);
    GUI.addSlider("fadeToBlack", ofRectangle(10,340+120,180,30), 0,1,1, &fadeToBlack);
    
    
    
    
    
    GUI.addSlider("delay", ofRectangle(10,340+160,180,30), 0,200,10, &XBC.delay);
    GUI.addSlider("balloonFade", ofRectangle(10,340+200,180,30), 0,255,10, &XBC.balloonFade);
    
    
    
    
       
    left = new float[256];
	
    AA.setup(44100);    // sample rate!
    ACM.setup();
    
    
    
    bPlaying = false;

    ofSoundStreamSetup(2, 0, this, 44100, 256, 4);	
	
    ofSetFrameRate(30);
    
    
    
    
    // ------- midi 
    
    // print input ports to console
    midiIn.listPorts();
    
    // open port by number
    midiIn.openPort(0);
    //midiIn.openPort("IAC Pure Data In");	// by name
    //midiIn.openVirtualPort("ofxMidiIn Input");	// open a virtual port
    
    // don't ignore sysex, timing, & active sense messages,
    // these are ignored by default
    midiIn.ignoreTypes(false, false, false);
    
    // add testApp as a listener
    midiIn.addListener(this);
    
    // print received messages to the console
    midiIn.setVerbose(true);
    
    midiColor.set(0,0,0);
    
   
}