Exemple #1
0
void triMeshApp::setup(){
	// cam, lights material
	mCam = new CameraPersp(getWindowWidth(), getWindowHeight(), 45.0f);
	mCam->lookAt( Vec3f(300, 700, -600), Vec3f(0,0,0) );
	mCam->setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 5000.0f );
	yrot = 0;
	
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);

	mLight = new gl::Light(gl::Light::DIRECTIONAL, 0);
	mLight->setDirection( Vec3f(0,0.1,0.3).normalized());
	mLight->setAmbient( Color( 0.2f, 0.2f, 0.2f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->update( *mCam );
	mLight->enable();
	
	mMaterial1.setSpecular( Color(0.5,0.5,0.5) );
	mMaterial1.setDiffuse( Color( 0.0f, 1.0f, 0.0f ) );
	mMaterial1.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	mMaterial1.setShininess( 20.0f );
	mMaterial1.apply();
	
	mMaterial2.setSpecular( Color(0,0,0) );
	mMaterial2.setDiffuse( Color(1,0,0) );
	mMaterial2.setAmbient( Color( 0.4f, 0.0f, 0.0f ) );
	mMaterial2.setEmission(Color(1,0,0));
	
	initPhysics();
	
	
	ObjLoader loader( loadResource( RES_LOSPHERE )->createStream() );
	loader.load( &mConvex );
	mVBO = gl::VboMesh( mConvex );
	
	ObjLoader loader2( loadResource( RES_TORUS )->createStream() );
	loader2.load( &mConcave );
	mVBOTerrain = gl::VboMesh( mConcave );

	btConvexHullShape* shape = bullet::createConvexHullShape(mConvex, Vec3f(CONVEX_SCALE, CONVEX_SCALE, CONVEX_SCALE));
	m_convexRigidBody = bullet::createConvexHullBody(m_dynamicsWorld, shape, Vec3f(0,500,0), 10000);
	
	btBvhTriangleMeshShape* concaveShape = bullet::createStaticConcaveMeshShape(mConcave, Vec3f(CONCAVE_SCALE, CONCAVE_SCALE, CONCAVE_SCALE), 5.0f);
	m_concaveRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, concaveShape, Vec3f(0,255,0));
	
	m_hfImage = loadImage(loadResource(RES_HEIGHTMAP));
	m_hfChannel = new Channel32f(m_hfImage);
	// note that HF_HEIGHTSCALE is ignored since we are using float data. we adjust the y-scale with the local scaling parameter only!
	btHeightfieldTerrainShape* hfShape = bullet::createHeightfieldTerrainShape(m_hfChannel, 64, 64, HF_HEIGHTSCALE, -500, 500, 1, Vec3f(HF_SCALE,HF_SCALEY,HF_SCALE));
	m_hfRigidBody = bullet::createStaticRigidBody(m_dynamicsWorld, hfShape, Vec3f(0,0,0));
	
	gl::VboMesh::Layout layout;
	layout.setDynamicColorsRGB();
	layout.setDynamicPositions();
	mVBOHeightfield = gl::VboMesh( m_hfImage.getWidth() * m_hfImage.getHeight(), 0, layout, GL_POINTS );
	
	updateData( );		
}
Exemple #2
0
void MaterialApp::setup(){
  font = Font(loadAsset("player1up.ttf"), 20);
  
  rotate = Vec3f::zero();
  
  eye = Vec3f(0, 0, 700);
  target = Vec3f::zero();
  camera = CameraPersp(getWindowWidth(), getWindowWidth(), 35.0f, 0.5f, 800.f);
  camera.lookAt(eye, target);
  
  light = std::make_unique<gl::Light>(gl::Light::DIRECTIONAL, 0);
  light->setAmbient(Color(0.6f, 0.6f, 0.6f));
  light->setDiffuse(Color(1.f, 1.f, 1.f));
  light->setDirection(Vec3f::zAxis());
  
  material.setAmbient(Color(0.3f, 0.3f, 0.3f));
  material.setDiffuse(Color(0.6f, 0.6f, 0.6f));
  material.setShininess(60);
  material.setEmission(Color(0.f, 0.f, 0.f));
  
  //gl::enable(GL_LIGHTING);
  gl::enable(GL_CULL_FACE);
  gl::enableDepthRead();
  gl::enableDepthWrite();
}
Exemple #3
0
void winBodiesApp::setup(){
	// cam, lights material
	mCam = new CameraPersp(getWindowWidth(), getWindowHeight(), 45.0f);
	mCam->lookAt( Vec3f(100, 400, -400), Vec3f(0,0,0) );
	mCam->setPerspective( 60.0f, getWindowAspectRatio(), 0.1f, 5000.0f );
	
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_LIGHTING);

	mLight = new gl::Light(gl::Light::DIRECTIONAL, 0);
	mLight->setDirection( Vec3f(0,0.1,0.3));
	mLight->setAmbient( Color( 0.2f, 0.2f, 0.2f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->update( *mCam );
	mLight->enable();
	
	mMaterial1.setSpecular( Color(0.5,0.5,0.5) );
	mMaterial1.setDiffuse( Color( 0.33f, 0.24f, 1.0f ) );
	mMaterial1.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	mMaterial1.setShininess( 20.0f );
	mMaterial1.apply();
	
	mMaterial2.setSpecular( Color(0,0,0) );
	mMaterial2.setDiffuse( Color(1,0,0) );
	mMaterial2.setAmbient( Color( 0.4f, 0.0f, 0.0f ) );
	mMaterial2.setEmission(Color(1,0,0));
	
	mMaterialG.setSpecular(Color(0,0,0));
	mMaterialG.setDiffuse(Color(0,0,0.03));
	mMaterialG.setAmbient(Color(0.1,0.1,0.1));
	
	initPhysics();
	
	lastTime = getElapsedSeconds();
}
Exemple #4
0
void TerrainApp::update()
{
	static float height = 0;
	static float noiseScale = 0;

	if ( ( height != mHeight ) || ( noiseScale != mNoiseScale ) )
	{
		generateTerrain();
		height = mHeight;
		noiseScale = mNoiseScale;
	}

	mMaterial.setAmbient( mAmbient );
	mMaterial.setDiffuse( mDiffuse );
	mMaterial.setSpecular( mSpecular );
	mMaterial.setShininess( mShininess );
	mMaterial.setEmission( mEmission );

	mLight->setDirection( mLightDirection );
	mLight->update( mMayaCam.getCamera() );

	mFps = getAverageFps();
}
Exemple #5
0
void BrainbowApp::scene1(){
    
    if (!musicOn && getElapsedSeconds() > 1){
        mAudio.playTraz("drone");
    }
    
    //    //addspheres
    if (lightFade >= 0.45f && ballTimer.getSeconds() > 0.5f && mCloud.getNumber() < 20){
        mCloud.addSphere();
        mAudio.playTraz("bubble");
        ballTimer = 0;
        ballTimer.start();
    }
    
        //into diamond
    if (gongTimer.getSeconds()>1 && scaledZ < 290 && scaledZ > 100 && !gong && getElapsedSeconds() > 30){
        mAudio.playTraz("activate");
        gong = true;
        gongTimer.stop();
        gongTimer.start();
    }
    
    if (gong && zshift < 500 ){
        //        zshift = 1;
        zshift++;
        scaledZ += zshift;
    }
    if (mCloud.getNumber() < 300 && ballTimer.getSeconds() > 0.1f && gong && zshift > 0){
        mCloud.addSphere();
        //        mAudio.playTraz("bubble");
        ballTimer = 0;
        ballTimer.start();
    }
    
    //    cout << "x: " << scaledX << endl;
    //    cout << "y: " << scaledY << endl;
    //    cout << "z: " << scaledZ << endl;
    
    if ((mCloud.getHexClear() || shift2) && getElapsedSeconds() > 10 && zshift < 750 && gong){
        //        if (getElapsedSeconds() > 10 && zshift < 720){
        shift2 = true;
        zshift++;
        scaledZ += zshift;
        discMaterial.setSpecular( ColorA(colorSat, colorSat, colorSat, .4f + discOp ) );
        discMaterial.setDiffuse( ColorA(colorSat, colorSat, colorSat, .4f + discOp) );
        discMaterial.setAmbient( ColorA(colorSat, colorSat, colorSat, .05f ) );
        discMaterial.setShininess( 600.0f );
        discMaterial.setEmission(ColorA(1, 1, 1, 1 ));
        mDisc.setMaterial( discMaterial );
        
        discOp += .01;
        if (zshift > 680){
            
            diamondFade += .005;
            sphereMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f-diamondFade ) );
            sphereMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f-diamondFade ) );
            sphereMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f-diamondFade ) );
            mDiamond.setMaterial( sphereMaterial );
            //                drawDiamond = false;
        }
        if (!musicOn){
            mAudio.playTraz("activate2");
            musicOn = true;
        }
    }
    if (zshift >= 750 && scaledZ > 700 && scaledY < 450 && scaledY > 320 && scaledX <685 && scaledX > 590){
        sceneOne = false;
        sceneTwo = true;
        zshift = 0;
    }
}
Exemple #6
0
void BrainbowApp::setup()
{
    // LOAD AUDIO
    mAudio = AudioCont();
    mAudio.setUp();
    
    // START SCENE 1
    sceneOne = true;
    sceneTwo = false;
    
    // Set up OpenGL
    
	gl::enableAlphaBlending();
	gl::enableDepthRead();
	gl::enableDepthWrite();
    
    gongTimer.start();
    ballTimer.start();
    
    // LIGHTING
    //here
    glPolygonOffset( 1.0f, 1.0f );
	glEnable( GL_LIGHTING );
	glEnable( GL_DEPTH_TEST );
    
    
    mLight = new gl::Light( gl::Light::POINT, 0 );
	mLight->lookAt( Vec3f( 1, 5, 1 ), Vec3f (getWindowWidth(), getWindowHeight() * 0.5f, 0.0f ));
    mLight->setAmbient( Color( 0.3f, 0.3f, 0.3f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setSpecular( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setShadowParams( 60.0f, 0.5f, 8.0f );
    //	mLight->update( *mCamera );
	mLight->enable();
    
    
    //LOAD SHAPES
    colorSat = 1.0f;
    
	sphereMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	sphereMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	sphereMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) );
	sphereMaterial.setShininess( 1.0f );
    
    sphereMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    gl::Material cylMaterial;
    cylMaterial.setSpecular( ColorA(0, 1.0f, 1.0f, .2f ));
	cylMaterial.setDiffuse( ColorA(0, 1.0f, 1.0f, .2f ) );
	cylMaterial.setAmbient( ColorA(0, 1.0f, 1.0f, .2f ) );
	cylMaterial.setShininess( 600.0f );
    cylMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    gl::Material curMaterial;
    curMaterial.setSpecular( ColorA(1, .5, 0, .5f ));
	curMaterial.setDiffuse( ColorA(1, .5, 0, .5f ) );
	curMaterial.setAmbient( ColorA(1, 1.0f, 1.0f, .05f ) );
	curMaterial.setShininess( 600.0f );
    curMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    
	discMaterial.setSpecular( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	discMaterial.setDiffuse( ColorA(colorSat-0.3f, colorSat, colorSat, .4f ) );
	discMaterial.setAmbient( ColorA(colorSat-0.3f, colorSat, colorSat, .05f ) );
	discMaterial.setShininess( 600.0f );
    discMaterial.setEmission(ColorA(1, 1, 1, 1 ));
    
    initShadowMap();
    
    mCloud = SphereCloud(0, 70);
    
    mDiamond = gl::DisplayList( GL_COMPILE );
    mDiamond.newList();
    gl::drawSphere(Vec3f(0, 0, 0), 300, 4);
    mDiamond.endList();
    mDiamond.setMaterial( sphereMaterial );
    
    mCyl = gl::DisplayList( GL_COMPILE );
    mCyl.newList();
    //    gl::drawCylinder(200, 200, 200);
    gl::drawColorCube(Vec3f(0, 0, 0), Vec3f(300, 300, 300));
    mCyl.endList();
    mCyl.setMaterial(cylMaterial);
    
    mCur = gl::DisplayList( GL_COMPILE );
    mCur.newList();
    gl::drawSphere(Vec3f(0, 0, 0), 5);
    mCur.endList();
    mCur.setMaterial(curMaterial);
    
    mDisc = gl::DisplayList( GL_COMPILE );
    mDisc.newList();
    gl::drawSolidCircle(Vec2f(0, 0), 60, 6);
    mDisc.endList();
    mDisc.setMaterial( discMaterial );
	
	// START LEAP
	mLeap 		= LeapSdk::Device::create();
	mCallbackId = mLeap->addCallback( &BrainbowApp::onFrame, this );
    
    
    mShader = gl::GlslProg( loadResource( RES_SHADOWMAP_VERT ), loadResource( RES_SHADOWMAP_FRAG ) );
	mShader.bind();
	mShader.uniform( "depthTexture", 0 );
}