Exemple #1
0
//--------------------------------------------------------------
void ofxOcean::keyPressed(int key){
    ofApp *app = (ofApp *)ofxGetAppPtr();

    
    if( key == 'h' ){
        bShowGui = !bShowGui;
				if (bShowGui){
			//app->transformer.cam.disableMouseInput();
		}
		else {
			//app->transformer.cam.enableMouseInput();
		}
    }
    if (key =='<') {
        waveHeight -= 10;
        waveHeight = ofClamp(waveHeight, 0, 500);
    }
    if (key =='>') {
        waveHeight += 10;
    }
    if(key == 's') {
        gui.saveToFile(OCEAN_SETTINGS_FILE);
    }
    if(key == 'l') {
        gui.loadFromFile(OCEAN_SETTINGS_FILE);
        
    }
   
}
// scene setup
void KinectScene2::setup() {
	ofLogNotice("KinectScene2") << "start setup";
	parentApp = (ofApp*) (ofxGetAppPtr());
	diffImg.allocate(512,424);
	img.loadImage("nasturtium.png");

	for(int i = 0; i < MAX_PARTICLES; i++) 
	{
		NoiseParticle p((float)i/10000.0f);
		flow.push_back(p);
	}
	ofLogNotice("KinectScene2") << "finished setup";
}
Exemple #3
0
//--------------------------------------------------------------
void ofxOcean::update(){

    float radius = 500;
    ofVec3f center = ofVec3f(0,0,-500);
    pointLight.setPosition(cos(ofGetElapsedTimef()*.6f) * radius * 2 + center.x,
                           sin(ofGetElapsedTimef()*.8f) * radius * 2 + center.y,
                           -cos(ofGetElapsedTimef()*.8f) * radius * 2 + center.z);
    
    Filled = filled;
    
    updateMesh(meshSize*100, meshSize*100, MAX(1, (int)meshResolution)*10);
    NoiseAmp = noiseAmp;
    NoiseHeight = noiseHeight;
    NoiseSpeed = noiseSpeed;
    WaveSpeed = waveSpeed;
    WaveHeight = waveHeight;
    WaveDirection = ((ofVec3f)waveDirection).normalize();
    WaveAmplitude = waveAmp;
    WaveSpeed2 = waveSpeed2;
    WaveHeight2 = waveHeight2;
    WaveDirection2 = ((ofVec3f)waveDirection2).normalize();
    WaveAmplitude2 = waveAmp2;
    
    
    // z = sin(y)
    
    int W = width/gridSize;
    int H = height/gridSize;
    float time = ofGetElapsedTimef();
    //Change vertices
    for (int y=0; y<H; y++) {
        
        //float waveZ = sin(y * waveAmplitude + time * waveSpeed) * waveHeight;
        
        for (int x=0; x<W; x++) {
        
            float waveZ = sin((y*WaveDirection.y + x*WaveDirection.x)  * WaveAmplitude + time * WaveSpeed) * WaveHeight;
            waveZ += sin((y*WaveDirection2.y + x*WaveDirection2.x)  * WaveAmplitude2 + time * WaveSpeed2) * WaveHeight2;
            
            int i = x + W * y;       //Vertex index
            ofPoint p = mesh.getVertex( i );
            //Get Perlin noise value
            float value =
            ofNoise( x * gridSize * noiseAmp * 0.001, y * gridSize * noiseAmp * 0.001, time * noiseSpeed * 0.2 ); // 0.2
            //Change z-coordinate of vertex
            p.z = value * noiseHeight; //25
        
            p.z += waveZ;
            
            mesh.setVertex( i, p );
            //Change color of vertex
            mesh.setColor( i, Color);
                    }
        
    }
    setNormals( mesh );  //Update the normals
    
    
    
    directionalLight.setDiffuseColor(diffuseColor);
    directionalLight.setSpecularColor(specularColor);
    directionalLight.setAmbientColor(ambientColor);
    
    pointLight.setDiffuseColor(diffuseColor);
    pointLight.setSpecularColor(specularColor);
    pointLight.setAmbientColor(ambientColor);
    
    directionalLight.setDirectional();
    directionalLight.setOrientation((ofVec3f)dirLightOrientation);
    
    material.setShininess(shininess);
    material.setColors(matDiffuseColor, matAmbientColor, matSpecularColor, matEmissiveColor);
    
    ofApp *app = (ofApp *)ofxGetAppPtr();

//    cout << "llokAt" << app->transformer.cam.getLookAtDir() << endl;
//
//    cout << "pos" << app->transformer.cam.getPosition() << endl;
    
}
Exemple #4
0
//--------------------------------------------------------------
void ofxOcean::draw(){
	ofApp *app = (ofApp *)ofxGetAppPtr();
	//app->transformer.cam.end();

    ofBackgroundGradient(ofColor::fromHex(0xFFFFFF), ofColor::fromHex(0x82CAFF));
    ofEnableDepthTest();
    ofEnableAlphaBlending();
    
    
    // enable the material, so that it applies to all 3D objects before material.end() call //
    if (useMaterial) {
        material.begin();
    }
    
    if (useLights) {
        ofEnableLighting();
        ofSetSmoothLighting(smoothLighting);
        // activate the lights //
        if (usePointLight && useLights) pointLight.enable();
        if (useDirLight && useLights) directionalLight.enable();
    } else {
        ofDisableLighting();
    }
    
    

//    app->transformer.cam.begin();
//
//
//    app->transformer.cam.setFarClip(100000);

    
    ofPushMatrix();
    ofTranslate(-width/2, -height/2, -500);
    ofTranslate(0,1000);
    
//    mesh.setMode( OF_PRIMITIVE_TRIANGLES );
//    vector<ofMeshFace> triangles = mesh.getUniqueFaces();
//    mesh.setFromTriangles(triangles, false);

    if (filled) {
        mesh.drawFaces();
        //mesh.draw();
    } else {
        mesh.drawWireframe();
    }
    
    ofPopMatrix();

	//app->transformer.cam.end();
    
    if (useLights) {
        // activate the lights //
        if (!usePointLight) pointLight.disable();
        if (!useDirLight) directionalLight.disable();
    }
    
    
    // turn off lighting //
    ofDisableLighting();
    material.end();
    
    
    if (bShowGui) {
        ofDisableDepthTest();
        gui.draw();
    }
	//app->transformer.cam.begin();
}
Exemple #5
0
//--------------------------------------------------------------
void ofxOcean::setup(){
    
	ofApp *app = (ofApp *)ofxGetAppPtr();
//    app->transformer.cam.reset();
//    
//    app->transformer.cam.lookAt(ofVec3f(0.151753, 0.923233, -0.353005));
//    app->transformer.cam.setPosition(ofVec3f(-600.906, -3368.04, 538.046));
//    
    
    // turn on smooth lighting //
    smoothLighting     = true;
    ofSetSmoothLighting(true);
    
    // Point lights emit light in all directions //
    // set the diffuse color, color reflected from the light source //
    // specular color, the highlight/shininess color //
    
    pointLight.setPointLight();
    
    // Directional Lights emit light based on their orientation, regardless of their position //
    directionalLight.setDirectional();
    
    // set the direction of the light
    // set it pointing from left to right -> //
    
    // shininess is a value between 0 - 128, 128 being the most shiny //
    material.setShininess(shininess);
    // the light highlight of the material //
    material.setColors(matDiffuseColor, matAmbientColor, matSpecularColor, matEmissiveColor);

    
    width = 1000;
    height = 1000;
    resolution = 100;
    gridSize = width / resolution;
    
    setupMesh(width,height,gridSize);
    
    gui.setup("panel",Globals::hostName + OCEAN_SETTINGS_FILE); // most of the time you don't need a name but don't forget to call setup
    gui.add(filled.set("bFill", true));
    gui.add(useLights.set("Use lights", true));
    gui.add(smoothLighting.set("Smooth Lighting", false));
    gui.add(usePointLight.set("usePointLight", false));
    gui.add(useDirLight.set("useDirLight", true));
    gui.add(useMaterial.set("useMaterial", true));
    
    meshParams.setName("Ocean mesh");
    meshParams.add(meshColor.set("meshColor", ofFloatColor(1, 0.72449, 1, 1),ofFloatColor(0,0,0,0),ofColor::white));
    meshParams.add(meshSize.set("size", 10, 10,100));
    meshParams.add(meshResolution.set("resolution", 2, 1,10));
    meshParams.add(noiseAmp.set("noiseAmp", 2, 0,50));
    meshParams.add(noiseSpeed.set("noiseSpeed", 2, 0,50));
    meshParams.add(noiseHeight.set("noiseHeight", 2, 0,500));
    meshParams.add(waveAmp.set("waveAmp", 0,0,PI));
    meshParams.add(waveSpeed.set("waveSpeed", 0,0,10));
    meshParams.add(waveHeight.set("waveHeight", 0,0,500));
    meshParams.add(waveDirection.set("waveDirection", ofVec3f(0),ofVec3f(-1),ofVec3f(1)));
    meshParams.add(waveAmp2.set("waveAmp2", 0,0,PI));
    meshParams.add(waveSpeed2.set("waveSpeed2", 0,0,10));
    meshParams.add(waveHeight2.set("waveHeight2", 0,0,500));
    meshParams.add(waveDirection2.set("waveDirection2", ofVec3f(0),ofVec3f(-1),ofVec3f(1)));
    
    gui.add(meshParams);
    
    lightParams.setName("Lights");
    lightParams.add(dirLightOrientation.set("Orientation (x,z,y angles)", ofVec3f(180, -42.2449, 117.551), ofVec3f(-180), ofVec3f(180)));
    lightParams.add(diffuseColor.set("diffuseColor", ofFloatColor(1, 1, 1, 1),ofFloatColor(0,0,0,0),ofColor::white));
    lightParams.add(specularColor.set("specularColor", ofFloatColor(1, 1, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    lightParams.add(ambientColor.set("ambientColor", ofFloatColor(0, 0.00510204, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    gui.add(lightParams);
    
    materialParams.setName("Material");
    materialParams.add(shininess.set("shininess", 128, 0, 128));
    materialParams.add(matDiffuseColor.set("matDiffuseColor", ofFloatColor(0, 0.204082, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    materialParams.add(matSpecularColor.set("matSpecularColor", ofFloatColor(1, 1, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    materialParams.add(matEmissiveColor.set("matEmissiveColor", ofFloatColor(0, 0.540816, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    materialParams.add(matAmbientColor.set("matAmbientColor", ofFloatColor(0, 0.55102, 1, 1), ofFloatColor(0,0,0,0),ofColor::white));
    gui.add(materialParams);
    bShowGui = false;
    
}