Esempio n. 1
0
// activation des lumières dynamiques
void Renderer::lightingOff()
{
	ofSetGlobalAmbientColor(ofColor(0, 0, 0));
	lightDirectional->disable();
	lightPoint->disable();
	lightSpot->disable();
}
Esempio n. 2
0
// désactivation des lumières dynamiques
void Renderer::lightingOn()
{
	if(isActiveLightAmbient)
		ofSetGlobalAmbientColor(*lightAmbient);
	else
		ofSetGlobalAmbientColor(ofColor(0, 0, 0));

	if(isActiveLightDirectional)
		lightDirectional->enable();

	if(isActiveLightPoint)
		lightPoint->enable();

	if(isActiveLightSpot)
		lightSpot->enable();
}
Esempio n. 3
0
//--------------------------------------------------------------
void ofApp::setup(){
	/********************
	********************/
	ofBackground(0);
	ofSetFrameRate(30);
	ofEnableAlphaBlending();
	ofEnableSmoothing();
	// ofSetSphereResolution(100);

	ofSetGlobalAmbientColor(ofColor(0, 0, 0));
	ofSetSmoothLighting(true);
	
	/********************
	********************/
	glEnable(GL_DEPTH_TEST);
	
	/********************
	http://www.komoto.org/opengl/sample10.html
	
	ポリゴンの表裏は、処理軽くするために使われます。
	つまり、ポリゴンのおもて面のみを描き、裏を描かないようにすることで、描くポリゴンを減らし、処理を軽くします。
	使う関数は、次の2つです。
		glEnable(GL_CULL_FACE)			...片面表示を有効にします。
		void glCullFace(GLenum mode)	...どの面を描画しないようにするかを指定します。
		
	modeは、
		GL_FRONT
		GL_BACK
		GL_FRONT_AND_BACK
	のいずれかです。
	GL_FRONTを指定すると、表面を描画しない、つまり、裏面のみを描画します。
	GL_BACKなら、表面のみが描かれ、GL_FRONT_AND_BACKなら、ポリゴンは描かれなくなります。

  まとめると、次のようになります。
		両面を描く
			glDisable(GL_CULL_FACE);
			
		表面のみを描く
			glEnable(GL_CULL_FACE); 
			glCullFace(GL_BACK);
			
		裏面のみを描く
			glEnable(GL_CULL_FACE); 
			glCullFace(GL_FRONT);
	********************/
	glDisable(GL_CULL_FACE);
	
	/********************
	********************/
	setup_gui();
	init();
	
	/********************
	********************/
	b_test = false;
}
Esempio n. 4
0
//--------------------------------------------------------------
void testApp::setup(){
	
	ofSetFrameRate(60);		
	int mcres = 32;
	
	mc.setup(ofGetWidth(),ofGetHeight(),-ofGetWidth(), mcres, mcres, mcres);
		
//	ofEnableLighting();
	ofSetGlobalAmbientColor(ofColor(200,255,250));

	mc.isolevel = 0.02;
}
Esempio n. 5
0
//--------------------------------------------------------------
void ofApp::setup(){
  
  // of stuff
	ofSetVerticalSync(true);
  ofSetFrameRate(60);
  ofEnableDepthTest();
  ofSetFullscreen(true);

  
  // settings
  showHelp = false;
  editMode = false;
  camMouse = false;
  mouseDragging = false;
  nearestIndex = 0;
  normalSmoothAmt = 20;
  

  // set up material
  // shininess is a value between 0 - 128, 128 being the most shiny //
	material.setShininess( 120 );
	material.setSpecularColor(ofColor(255, 255, 255));
  material.setAmbientColor(ofColor(0, 0, 0));
  material.setShininess(10.0f);

  
  // load mesh
  mesh.load("landscape.ply");
  
  // test sphere
  sphere.setRadius(20);
  
  // set up lights
  ofSetGlobalAmbientColor(ofColor(0, 0, 0));
  ofSetSmoothLighting(true);
  
  sun.setup();
  sun.setDirectional();
  sun.setDiffuseColor( ofFloatColor(0.7f, 0.7f, 0.7f) );
  sun.setSpecularColor( ofFloatColor(0.3f, 0.3f, 0.3f) );
  
  moon.setup();
  moon.setDirectional();
  moon.setDiffuseColor( ofFloatColor(0.0f, 0.0f, 0.15f) );
  moon.setSpecularColor( ofFloatColor(0.0f, 0.0f, 0.08f) );
  
  // start w/ mouse input disabled
  cam.disableMouseInput();
  //  cam.setFov(5);
  
  loadScene();
}
Esempio n. 6
0
//--------------------------------------------------------------
void ofApp::setup(){
    ofSetFullscreen(true);
    ofBackground(0);
    ofSetFrameRate(30);
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofSetGlobalAmbientColor(ofColor(0, 0, 0));
    ofSetSmoothLighting(true);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    doReset = guiAlloc = false;
    ofSetSphereResolution(100);
    reset();
    wModActive = false;
}
Esempio n. 7
0
void ParametricObject::setup(){
	ofBackground(0);
    ofSetFrameRate(30);
    ofEnableAlphaBlending();
    ofEnableSmoothing();
    ofSetGlobalAmbientColor(ofColor(0, 0, 0));
    ofSetSmoothLighting(true);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    ofSetSphereResolution(100);
     //sphere radius
    
    spot.setDiffuseColor(ofFloatColor(255.0, 0.0, 0.0f));
    spot.setSpecularColor(ofColor(0, 0, 255));
    spot.setSpotlight();
    spot.setSpotConcentration(5);
    spot.setSpotlightCutOff(10);
    spot_rot = ofVec3f(0, 0, 0);
    setLightOri(spot, spot_rot);

    spot.setPosition(0, 0, 300);
    
    point.setDiffuseColor(ofColor(0.0, 255.0, 0.0));
    
    point.setPointLight();
    
    dir.setDiffuseColor(ofColor(0.0f, 0.0f, 255.0f));
    dir.setSpecularColor(ofColor(255.0f, 0.0f, 0.0f));
    
    dir.setDirectional();
    dir_rot = ofVec3f(0, -95, 0);
    setLightOri(dir, dir_rot);
    
    amb.setAmbientColor(ofColor(20.0, 20.0, 20.0, 20.0));
    
    material.setShininess(120);

    material.setSpecularColor(ofColor(255, 255, 255, 255));
    material.setEmissiveColor(ofColor(0, 0, 0, 255));
    material.setDiffuseColor(ofColor(255, 255, 255, 255));
    material.setAmbientColor(ofColor(255, 255, 255, 255));
    
    
    
}
Esempio n. 8
0
		//--------------------------------------------------------------
		void Particles::setup()
		{
			ofSetGlobalAmbientColor(ofFloatColor(parameters.rendering.ambientLight));

			for (unsigned i = 0; i < 4000; ++i)
			{
				glm::vec3 position = glm::vec3(
					ofRandom(-HALF_DIM, HALF_DIM),
					ofRandom(-HALF_DIM, HALF_DIM),
					ofRandom(-HALF_DIM, HALF_DIM)
				);

				float speed = glm::gaussRand(60.f, 20.f);
				glm::vec3 velocity = glm::sphericalRand(speed);

				particleSystem.addParticle((nm::Particle::Type)(i % 6), position, velocity);
			}
		}
Esempio n. 9
0
void offFloor::setup()
{
    tri.setupColors();
    nTri = ofRandom(1000,2000);
    nVert = nTri * 3;
    float Rad = 250;
    float rad = 1000;
    vertices.resize(nVert);
    
    
    for(int i = 0; i < nTri; i++)
    {
        tri.addPoint(ofRandom(-ofGetWidth(),ofGetWidth()), ofRandom(-ofGetHeight(),ofGetHeight()), ofRandom(20));
        /*ofPoint center (ofRandom(-1,1), ofRandom(-1,1),0);// ofRandom(-1,1));
        center.normalize();
        center *= ofRandom(100,Rad);
        
        
        tri.addPoint(center + ofPoint(ofRandom(200, rad), ofRandom(200, rad), ofRandom(0,50)));
        for(int j = 0; j < 3; j++)
        {
            vertices[i*3 + j] = center + ofPoint(ofRandom(-rad, rad), ofRandom(-rad, rad), 0);//ofRandom( -rad, rad ));
        }*/
    }
    //Fill the array of triangles' colors
    colors.resize( nTri );
    for (int i=0; i<nTri; i++) {
        //Take a random color from black to red
        colors[i] = ofColor( ofRandom( 0, 255 ), 0, 0 );
    }
    //Set up vertices and colors
    tri.triangulate();
    ofEnableSmoothing();
    ofSetGlobalAmbientColor(ofColor(0, 0, 0));
    ofSetSmoothLighting(true);
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);

    ofSetSphereResolution(100);
    amb.setAmbientColor(ofColor(200.0, 200.0, 200.0, 200.0));

}
//--------------------------------------------------------------
void ofApp::setup(){
	ofEnableAntiAliasing();
	ofEnableSmoothing();
	ofEnableDepthTest();

	bResample = true;
	resampleSpacing = 5.0;
	letterThickness = 145.0;

	ofTrueTypeFont ttf;
	// to extract points, loadFont must be called with makeContours set to true
	ttf.loadFont(OF_TTF_SANS, 300, true, false, true);
	string s = "TYPE";

	// Center string code from:
	// https://github.com/armadillu/ofxCenteredTrueTypeFont/blob/master/src/ofxCenteredTrueTypeFont.h
	ofRectangle r = ttf.getStringBoundingBox(s, 0, 0);
	center = ofVec2f(floor(-r.x - r.width * 0.5f), floor(-r.y - r.height * 0.5f));

	vector <ofTTFCharacter> letters = ttf.getStringAsPoints(s);

	for(int i = 0; i < letters.size(); i++){
		ofPath resampledPath = bResample ? resamplePath(letters[i], resampleSpacing) : letters[i];
		ofMesh meshLetter = createMeshFromPath(resampledPath, letterThickness);
		mesh.append(meshLetter);
	}

	getBoundaries(mesh);

	numSpheres = 7000; // the maximum number of Spheres
	addSpeed = 25; // the number of Spheres that is added per update() loop

	ofEnableLighting();
	ofSetGlobalAmbientColor(ofColor(128));

	directionalLight.setDiffuseColor(ofColor(128));
	directionalLight.setPosition(boundsMax);
	directionalLight.enable();

	cam.setVFlip(true);
}
Esempio n. 11
0
//----------------------------------------
void ofSetGlobalAmbientColor(float r, float g, float b, float a) {
	ofSetGlobalAmbientColor( ofColor(r, g, b, a) );
}
Esempio n. 12
0
void ofApp::update(){
    
    // lights
    spotLight.setPosition( 60, 60, 200);
    spotLight.lookAt(ofVec3f(30, 0, -50));
    // from GUI
    ofSetGlobalAmbientColor( globalAmbient.get() );
    //spotLight.setGlobalPosition( lightPosition.get() );
    spotLight.setAmbientColor( lightAmbient.get() );
    spotLight.setDiffuseColor( lightDiffuse.get() );
    spotLight.setSpecularColor( lightSpecular.get() );
    
    // Material from GUI
    //material.setColors(matDiffuse.get(), matAmbient.get(), matEmissive.get(), matSpecular.get());
    material.setShininess(matShiny.get());
    
    // mesh
    auto mesh = sphereBase.getMeshPtr();
    auto MeshOut = sphere.getMeshPtr();
    updateMesh(mesh, MeshOut);
    if (isIcoSphere) {
        mesh = icoSphereBase.getMeshPtr();
        MeshOut = icoSphere.getMeshPtr();
        updateMesh(mesh, MeshOut);
    }
    if (!ofGetKeyPressed('r')) {
        if (isIcoSphere) setNormals(*MeshOut);
        else updateNormals(MeshOut);
    }
    
    // depth of field
    depthOfField.setBlurAmount(blurAmount);
    depthOfField.setFocalDistance(focalDistance);
    depthOfField.setFocalRange(focalRange);
    
    
    // FFT
    fftLive.update();
    int n  = levels.size();
    float * audioData = new float[n];
    fftLive.getFftPeakData(audioData, n);
    for(int i=0; i<levels.size(); i++) {
        float audioValue = audioData[i];
        levels[i] = audioValue;
    }
    delete[] audioData;
    
    // animate noise
    if (isNoiseAnimated) {
        
        
        float time = ofGetElapsedTimef();
        ofVec3f noiseAnim(
                          (ofNoise(time/2)-0.5) * 80,
                          (ofNoise(time/3)-0.5) * 80,
                          (ofNoise(time/4)-0.5) * 80);
        noiseIn.set(noiseAnim);
        
        //if (levels.size() > 0) noiseIn.set(ofVec3f(levels[0] * 20, levels[1] * 20, levels[2] * 20));
        
        //spotLight.setDiffuseColor( ofColor(ofNoise(ofGetElapsedTimef()/2)*255, ofNoise(ofGetElapsedTimef()/3)*255, ofNoise(ofGetElapsedTimef()/4)*255) );
    }
    
}
Esempio n. 13
0
// ------------------------------------------------------------------------------------------------------
//
void ofApp::update()
{
	// Update time, this let's us hit space and slow down time, even reverse it.
	if( ofGetKeyPressed(' ') ) { timeStep = ofLerp( timeStep, ofMap( ofGetMouseX(), 0, ofGetWidth(), -(1.0f/60.0f), (1.0f/60.0f) ), 0.1f );} else { timeStep = ofLerp( timeStep, 1.0f / 60.0f, 0.1f ); }
	time += timeStep;
	
	float mx = ofMap( ofGetMouseX(), 0, ofGetWidth()-1,  0, 1 );
	float my = ofMap( ofGetMouseY(), 0, ofGetHeight()-1, 0, 1 );
	
	ofSetGlobalAmbientColor( globalAmbient.get() );

	light[0].setAmbientColor( light1Ambient.get() ); // If you're having trouble passing an 'ofParameter<ClassX>' into something that expects a 'ClassX' use .get()
	light[0].setDiffuseColor( light1Diffuse.get() );
	light[0].setSpecularColor( light1Specular.get() );

	light[0].setPosition( light1Position );
	

	if( currAppMode == APP_MODE_LIVE  )
	{
		kinectToWorld.makeIdentityMatrix();
		kinectToWorld.scale( ofVec3f(kinectPointCloudScale) );
		kinectToWorld.scale( ofVec3f(1,-1,-1) );
		kinectToWorld.translate( kinectPointCloudOffset );
		
		worldToKinect = kinectToWorld.getInverse();
		
		particles.setWorldToFlowParameters( worldToKinect );
		
		
		// Copy the points and colors every frame for now, can be optimized
		kinectManager.getCurrentPointCloud( pointCloudPoints, pointCloudColors );
		
		if( pointCloudPoints.size() != pointCloudColors.size() ) ofLogError() << "ofApp::update() pointCloudPoints.size() != pointCloudColors.size()";
		
		
		//ofVec3f kinectCoordinateCorrection(1,-1,1);
		
		pointCloudMesh.clear();
		for( int i = 0; i < pointCloudPoints.size(); i++ )
		{
			//pointCloudMesh.addVertex( ((pointCloudPoints.at(i) * kinectPointCloudScale) * kinectCoordinateCorrection) + kinectPointCloudOffset );
			pointCloudMesh.addVertex( pointCloudPoints.at(i) * kinectToWorld );
			pointCloudMesh.addColor( pointCloudColors.at(i) );
		}
		
		// Spawn positions
		bool haveNewData = pointCloudMesh.getNumVertices() > 2; // We'll be grabbing the vertices from the mesh, a bit hacky but the rescaled data is right there
		if( haveNewData )
		{
			// Fill in the span buffer for the particles with random point cloud locations
			int tmpIndex = 0;
			for( int y = 0; y < particles.textureSize; y++ )
			{
				for( int x = 0; x < particles.textureSize; x++ )
				{
					int randomIndex = (int)ofRandom(pointCloudMesh.getNumVertices()-1);
					ofVec3f spawnPos = pointCloudMesh.getVertex( randomIndex );
					
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 0 ] = spawnPos.x;
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 1 ] = spawnPos.y;
					particles.spawnPosBuffer.getPixels()[ (tmpIndex * 3) + 2 ] = spawnPos.z;
					
					tmpIndex++;
				}
			}
			particles.spawnPosTexture.loadData( particles.spawnPosBuffer );
		}
		
		// Optical Flow
		
		ofxCv::FlowFarneback& flowObj = kinectManager.getFlowObject();
		int targetNumChannels = 3;
		
		if( particles.opticalFlowBuffer.getWidth() != flowObj.getWidth() ||
		   particles.opticalFlowBuffer.getHeight() != flowObj.getHeight() )
		{
			particles.opticalFlowBuffer.allocate( flowObj.getWidth(), flowObj.getHeight(), targetNumChannels );
			
			particles.opticalFlowTexture.allocate( flowObj.getWidth(), flowObj.getHeight(), GL_RGB32F, false );
			
			cout << "** Alocating flow " << particles.opticalFlowBuffer.getWidth() << ", " << particles.opticalFlowBuffer.getHeight() << "  " << particles.opticalFlowBuffer.getNumChannels() << endl;
		}
		
		// We are going to copy the flow data into am RGB texture rather than RG, having trouble getting that working,
		// otherwise it would (without filtering) just be ofxCv::toOf( flowObj.getFlow(), particles.opticalFlowBuffer );
		
		int numChannels = particles.opticalFlowBuffer.getNumChannels();
		
		int w = particles.opticalFlowBuffer.getWidth();
		int h = particles.opticalFlowBuffer.getHeight();
		int tmpIndex = 0;
		int windowSize = 4;
		int windowSizeHalf = windowSize / 2;
		for( int y = windowSize; y < h - windowSize; y++ )
		{
			for( int x = windowSize; x < w - windowSize; x++ )
			{
				tmpIndex = ((y*w) + x) * numChannels;
				//ofVec2f flowOffset = flowObj.getFlowOffset( x, y );
				ofVec2f flowOffset = flowObj.getAverageFlowInRegion( ofRectangle( x-windowSizeHalf, y-windowSizeHalf, windowSize, windowSize) );
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 0 ] = flowOffset.x;
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 1 ] = flowOffset.y;
				particles.opticalFlowBuffer.getPixels()[ tmpIndex + 2 ] = 0;
			}
		}
		
		particles.opticalFlowTexture.loadData( particles.opticalFlowBuffer );
		
		particles.setAverageFlow( kinectManager.getAverageFlowSmoothed() );
		
	}
	else if ( currAppMode == APP_MODE_TOUCH_SETUP )
	{
		
	}
	
}