예제 #1
0
void ShadowMapSample::keyDown( ci::app::KeyEvent event )
{
	switch( event.getChar() ) {
		case ' ' :
			mPaused = ! mPaused;
		break;
		case 'r': { // create a random camera position
			vec3 eyeVec = Rand::randVec3f().normalized() * 6.0f;
			if( eyeVec.y < 0 ) eyeVec.y = -eyeVec.y;
			mCamera->lookAt( eyeVec, vec3(0,-2.5,0) );
			mLight->update( *mCamera );
		}
		break;
		case 'f':
			setFullScreen( ! isFullScreen() );
		break;
		case 'l': { // create a random light position
			vec3 lightPos = Rand::randVec3f().normalized() * 4.0f;
			if( lightPos.y < 0 ) lightPos.y = -lightPos.y;			
			mLight->lookAt( lightPos, vec3::zero() );
			mLight->update( *mCamera );
		}
		break;
		case 'c':
			mLookThroughCamera = ! mLookThroughCamera;
		break;
		case 'd':
			mDrawDepthMap = ! mDrawDepthMap;
		break;
	}
}
/* 
 * @Description: render scene to FBO texture
 * @param: none
 * @return: none
 */
void Base_ThreeD_ProjectApp::renderSceneToFBO()
{
	mScreenSpace1.bindFramebuffer();
    
	glClearColor( 0.5f, 0.5f, 0.5f, 1 );
	glClearDepth(1.0f);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if (mLightingOn)
		glDisable(GL_LIGHTING);
	glColor3f( 1.0f, 1.0f, 0.1f );
	gl::drawFrustum( mLightRef->getShadowCamera() );
	glColor3f( 1.0f, 1.0f, 1.0f );
	if (mLightingOn)
		glEnable(GL_LIGHTING);
	
	mEye = mCam->getEyePoint();
	mEye.normalize();
	mEye = mEye * abs(mCameraDistance);
	mCam->lookAt( mEye, mCenter, mUp );
	gl::setMatrices( *mCam );
	mLight->update( *mCam );
	
	drawTestObjects();
	
	mScreenSpace1.unbindFramebuffer();
	
	glDisable(GL_LIGHTING);
}
예제 #3
0
void BrainbowApp::scene2(){
    //    cout << "x: " << scaledX << endl;
    //    cout << "y: " << scaledY << endl;
    //    cout << "z: " << scaledZ << endl;
    
    if (!newLight){
        mCloud.clear();
        mLight->setAmbient( Color( 0.0f, 0.0f, 0.0f ) );
        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 );
        newLight = true;
        cubeTimer.start();
    }
    
    if (scaledZ < 350 && targets.size() < 5 && cubeTimer.getSeconds() > 2){
        addTarget(Vec3f (scaledX, scaledY, scaledZ));
        cubeTimer = 0;
        cubeTimer.start();
    }
    
    if (cubes.size() >= 45){
        if ( !newCloud){
            mCloud = SphereCloud(0, 500);
            newCloud = true;
        }
        if (newCloud && mCloud.getNumber() < 300 && gongTimer.getSeconds() > .5){
            gongTimer = 0;
            gongTimer.start();
            mCloud.addSphere();
            mAudio.playTraz("bubble");
        }
    }
}
예제 #4
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( );		
}
예제 #5
0
void ShadowMapSample::updateShadowMap()
{
	mDepthFbo.bindFramebuffer();

	glPolygonOffset( 1.0f, 1.0f );
	glEnable( GL_POLYGON_OFFSET_FILL );
	glClear( GL_DEPTH_BUFFER_BIT );

	glPushAttrib( GL_VIEWPORT_BIT );
	glViewport( 0, 0, SHADOW_MAP_RESOLUTION, SHADOW_MAP_RESOLUTION );

	gl::pushMatrices();
	
		mLight->setShadowRenderMatrices();

		mBackboard.draw();
		mTorus.draw();
		gl::drawCube( vec3::zero(), vec3( 1, 1, 1 ) );
	gl::popMatrices();

	glPopAttrib();

	glDisable( GL_POLYGON_OFFSET_FILL );

	mDepthFbo.unbindFramebuffer();
}
예제 #6
0
void BrainbowApp::updateShadowMap()
{
	mDepthFbo.bindFramebuffer();
    
	glPolygonOffset( 1.0f, 1.0f );
	glEnable( GL_POLYGON_OFFSET_FILL );
	glClear( GL_DEPTH_BUFFER_BIT );
    
	glPushAttrib( GL_VIEWPORT_BIT );
	glViewport( 0, 0, SHADOW_MAP_RESOLUTION, SHADOW_MAP_RESOLUTION );
    
	gl::pushMatrices();
	
    mLight->setShadowRenderMatrices();
    
    mDisc.draw();
    //    mCyl.draw();
    //    mCur.draw();
    mDiamond.draw();
    
	gl::popMatrices();
    
	glPopAttrib();
    
	glDisable( GL_POLYGON_OFFSET_FILL );
    
	mDepthFbo.unbindFramebuffer();
}
예제 #7
0
void ShadowMapSample::draw()
{
	gl::clear();
	gl::enableDepthWrite();
	glEnable( GL_LIGHTING );
	updateShadowMap();

	gl::enableDepthRead();

	glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
	mShader.bind();
	mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) );
	
	if( mLookThroughCamera )
		gl::setMatrices( *mCamera );
	else
		gl::setMatrices( mLight->getShadowCamera() );
	mLight->update( *mCamera );

	glPushMatrix();
		mBackboard.draw();
		mTorus.draw();
		gl::drawCube( vec3::zero(), vec3( 1, 1, 1 ) );
	glPopMatrix();
	
	mShader.unbind();
	mDepthFbo.unbindTexture();
	
	// Draw the lighting frustum unless we're looking through it
	if( mLookThroughCamera ) {
		glDisable( GL_LIGHTING );
		glColor3f( 1.0f, 1.0f, 0.1f );
		gl::drawFrustum( mLight->getShadowCamera() );
	}
	
	if( mDrawDepthMap ) { // there are faster ways to achieve this, but this is a handy way to see the depth map
		gl::setMatricesWindow( getWindowSize() );
		Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() );
		ip::hdrNormalize( &shadowMapSurface );
		gl::color( Color::white() );
		gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128, 128 ) );
	}
}
예제 #8
0
void LocationApp::draw()
{
    // Clear the screen
    gl::enableDepthRead();
    gl::enableDepthWrite();
    gl::clear( Color::gray( 0.843f ) );

    CameraPersp camera;
    camera.setPerspective( 60.0f, getWindowAspectRatio(), 0.01f, 10.0f );
    camera.lookAt( Vec3f( 0.0f, 0.0f, 3.0f ), Vec3f::zero() );
    gl::setMatrices( camera );
    mLight->update( camera );

    // Rotate the globe
    gl::multModelView( Quatf(Vec3f::yAxis(), mRotationAngle ).normalized() );

    // Draw the globe with shading. Rotate it 90 degrees on
    // its Y axis to line up the texture with the location
    gl::color( ColorAf::white() );
    gl::enable( GL_LIGHTING );
    mTexture.bind( 0 );
    gl::pushMatrices();
    gl::rotate( Vec3f( 0.0f, 90.0f, 0.0f ) );
    gl::drawSphere( Vec3f::zero(), 1.0f, 32 );
    gl::popMatrices();
    mTexture.unbind();
    gl::disable( GL_LIGHTING );

    // Draw location
    gl::color( ColorAf( 1.0f, 0.2f, 0.18f, 0.667f ) );
    gl::drawSphere( mLocation, mDotRadius, 32 );

    ////////////////////////////////////////////////////
#if defined( CINDER_COCOA_TOUCH )
    gl::setMatricesWindow( getWindowSize() );
    gl::enableDepthRead( false );
    gl::enableDepthWrite( false );

    // Plot arrow position
    float radius = 256.0f;
    float rotation = toRadians( mHeading ) - (float)M_PI * 0.5f;
    float x = math<float>::cos( rotation );
    float y = math<float>::sin( rotation );
    Vec2f position = getWindowCenter() + Vec2f( x, y ) * radius;

    gl::translate( position );
    gl::rotate( Vec3f( 0.0f, 0.0f, -mHeading ) );
    gl::translate( position * -1.0f );
    gl::translate( position );

    gl::color( Colorf( 0, 0, 1 ) );
    gl::drawSolid( mArrow );
#endif
}
void SpawnObjectApp::setup()
{
    mFixtures		= Fixture::loadFixtures( getAssetPath("fixtures_001.csv") );			// load CSV fixtures file
    
    mFixtureMesh    = Fixture::loadObj( getAssetPath("sphere.obj") );						// load fixture mesh
    mVenueMesh      = Fixture::loadObj( getAssetPath("piano2.obj") );						// load venue mesh
    
    mFadeIn         = 0.5f;
    mFadeOut        = 0.1f;
    mSpeed          = 0.2f;
    mRadius         = 1.5f;
    mPointsN        = 8;
    mDeg            = 3;

    mModule         = SpawnModule::create();                                                // create module
    
    mParams         = params::InterfaceGl::create( "Params", Vec2i( 200, 240 ) );           // Gui
    
    mParams->addParam( "Fade IN",   &mFadeIn    , "min=0.001 max=1.0 step=0.001" );
    mParams->addParam( "Fade OUT",  &mFadeOut   , "min=0.001 max=1.0 step=0.001" );
    mParams->addSeparator();
    
    mParams->addParam( "Speed",     &mSpeed     , "min=0.001 max=10.0 step=0.001" );
    mParams->addParam( "Radius",    &mRadius    , "min=0.1 max=15.0 step=0.1" );
    mParams->addParam( "Points N",  &mPointsN   , "min=2 max=100 step=1" );
    mParams->addParam( "Deg",       &mDeg       , "min=1 max=10 step=1" );
    
    ci::CameraPersp initialCam;                                                             // Initialise camera
    initialCam.setPerspective( 45.0f, ci::app::getWindowAspectRatio(), 0.1, 3000 );
    mMayaCam        = MayaCamUI( initialCam );
    
    // Set up light
    mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
    mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
    mLight->setAmbient( ColorAf::gray( 0.843f ) );
    mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
    mLight->enable();
    
    // create a path
    mModule->createPath( mPointsN, mDeg, mRadius );
}
예제 #10
0
void LocationApp::setup()
{
    // Define properties
    mHeading = 0.0f;
    timeline().apply( &mRotationAngle, 0.0f, (float)(2 * M_PI), 8.0f ).loop();
    timeline().apply( &mDotRadius, 0.0f, 0.1f, 0.5f ).loop();

    LocationManager::enable();
    LocationManager::getSignalLocationChanged().connect(
        std::bind( &LocationApp::locationChanged, this, std::_1 ) );
#if defined( CINDER_COCOA_TOUCH )
    LocationManager::getSignalHeadingChanged().connect(
        std::bind( &LocationApp::headingChanged, this, std::_1 ) );
#endif

    // Load globe texture,
    setFrameRate( 60.0f );
    mTexture = gl::Texture( loadImage( loadResource( RES_EARTH_JPG ) ) );
    mTexture.setFlipped( true );

    // Set up view
    gl::enable( GL_TEXTURE_2D );
    gl::enableAlphaBlending();

    // Set up light
    mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
    mLight->setDirection( Vec3f( 0.0f, 0.1f, 0.3f ).normalized() );
    mLight->setAmbient( ColorAf::gray( 0.843f ) );
    mLight->setDiffuse( ColorAf( 1.0f, 1.0f, 1.0f, 1.0f ) );
    mLight->enable();

    // Build the heading arrow
    float size = 80.0f;
    mArrow.moveTo( Vec2f(         0.0f, -size * 0.5f  ) );
    mArrow.lineTo( Vec2f(  size * 0.5f,  size * 0.5f  ) );
    mArrow.lineTo( Vec2f(         0.0f,  size * 0.25f ) );
    mArrow.lineTo( Vec2f( -size * 0.5f,  size * 0.5f  ) );
    mArrow.close();
}
예제 #11
0
unsigned int GL::LightHandler::AddLight(const GL::Light& light) {
	if (light.GetTTL() == 0 || light.GetRadius() <= 0.0f) { return -1U; }
	if (light.GetIntensityWeight().SqLength() <= 0.01f) { return -1U; }

	if (lights.size() >= maxLights || lightIDs.empty()) {
		unsigned int minPriorityValue = light.GetPriority();
		unsigned int minPriorityHandle = -1U;

		for (std::map<unsigned int, GL::Light>::const_iterator it = lights.begin(); it != lights.end(); ++it) {
			const GL::Light& lgt = it->second;

			if (lgt.GetPriority() < minPriorityValue) {
				minPriorityValue = lgt.GetPriority();
				minPriorityHandle = it->first;
			}
		}

		if (minPriorityHandle != -1U) {
			lightIntensityWeight -= lights[minPriorityHandle].GetIntensityWeight();
			lightIDs.push_back(lights[minPriorityHandle].GetID());
			lights.erase(minPriorityHandle);
		} else {
			// no available light to replace
			return -1U;
		}
	}

	lights[lightHandle] = light;
	lights[lightHandle].SetID(lightIDs.front());
	lights[lightHandle].SetRelativeTime(0);
	lights[lightHandle].SetAbsoluteTime(gs->frameNum);

	lightIntensityWeight += light.GetIntensityWeight();
	lightIDs.pop_front();

	return (lightHandle++);
}
예제 #12
0
void ShadowMapSample::setup()
{
	glPolygonOffset( 1.0f, 1.0f );
	glEnable( GL_LIGHTING );
	glEnable( GL_DEPTH_TEST );

	mPaused = false;
	mLookThroughCamera = true;
	mDrawDepthMap = false;
	
	mCamera = new CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f );
	mCamera->lookAt( vec3( 5, 5, 5 ), vec3( 0, 0, 0 ) );
	mCamera->setPerspective( 45.0f, getWindowAspectRatio(), 0.1f, 100.0f );
	
	mLight = new gl::Light( gl::Light::POINT, 0 );
	mLight->lookAt( vec3( 1, 5, 1 ), vec3( 0, 0, 0 ) );
	mLight->setAmbient( Color( 0.3f, 0.3f, 0.3f ) );
	mLight->setDiffuse( Color( 0.5f, 0.5f, 0.5f ) );
	mLight->setSpecular( Color( 0.5f, 0.5f, 0.5f ) );
	mLight->setShadowParams( 60.0f, 0.5f, 8.0f );
	mLight->update( *mCamera );
	mLight->enable();

	gl::Material torusMaterial;
	torusMaterial.setSpecular( BLUE );
	torusMaterial.setDiffuse( BLUE );
	torusMaterial.setAmbient( Color( 0.1f, 0.1f, 0.1f ) );
	torusMaterial.setShininess( 25.0f );

	gl::Material backboardMaterial;
	backboardMaterial.setAmbient( RED );
	backboardMaterial.setDiffuse( RED );	
	backboardMaterial.setShininess( 1.0f );

	initShadowMap();

	mTorus = gl::DisplayList( GL_COMPILE );
	mTorus.newList();
		gl::drawTorus( 1.0f, 0.3f, 32, 64 );
	mTorus.endList();
	mTorus.setMaterial( torusMaterial );
	
	mBackboard = gl::DisplayList( GL_COMPILE );
	mBackboard.newList();
		gl::drawCube( vec3( 0.0f, -2.5f, 0.0f ), vec3( 5.0f, 0.1f, 5.0f ) );
	mBackboard.endList();
	mBackboard.setMaterial( backboardMaterial );

	mShader = gl::GlslProg( loadResource( RES_SHADOWMAP_VERT ), loadResource( RES_SHADOWMAP_FRAG ) );
	mShader.bind();
	mShader.uniform( "depthTexture", 0 );
}
예제 #13
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();
}
예제 #14
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::setup()
{
	loadConfig("configs/gaztank.ini");

	setupCamera();

	// Create lights
	m_light1 = new gl::Light(gl::Light::DIRECTIONAL, 0);
	m_light1->setDirection(Vec3f(0, 0, 1).normalized());
	m_light1->setAmbient(Color(0.0f, 0.0f, 0.1f));
	m_light1->setDiffuse(Color(0.9f, 0.6f, 0.3f));
	m_light1->setSpecular(Color(0.9f, 0.6f, 0.3f));

	m_light2 = new gl::Light(gl::Light::DIRECTIONAL, 1);
	m_light2->setDirection(Vec3f(0, 0, -1).normalized());
	m_light2->setAmbient(Color(0.0f, 0.0f, 0.0f));
	m_light2->setDiffuse(Color(0.2f, 0.6f, 1.0f));
	m_light2->setSpecular(Color(0.2f, 0.2f, 0.2f));

	// Setup matrix
	m_matrix.setToIdentity();
	m_matrix.translate(Vec3f::zero());
	m_matrix.rotate(Vec3f::zero());
	m_matrix.scale(Vec3f::one());

	m_rotateMesh = false;

	// Create a parameter window
	m_params = params::InterfaceGl::create(getWindow(), "Properties", Vec2i(180, 240));
	m_params->addText("LMB + drag - rotate");
	m_params->addText("RMB + drag - zoom");
	m_params->addSeparator();
	m_params->addButton("Full screen", [&] { setFullScreen(!isFullScreen()); });
	m_params->addParam("Auto rotate", &m_rotateMesh);
	m_params->addSeparator();
	m_params->addParam("Diffuse", &m_diffuseEnabled);
	m_params->addParam("Normal", &m_normalEnabled);
	m_params->addParam("Specular", &m_specularEnabled);
	m_params->addParam("AO", &m_aoEnabled);
	m_params->addParam("Emissive", &m_emissiveEnabled);
	m_params->addSeparator();
	m_params->addParam("Gamma", &m_gamma, "min=0.0 max=10.0 step=0.1");

	m_time = (float)getElapsedSeconds();
}
예제 #15
0
void BrainbowApp::update()
{
    //LEAP
    if ( mLeap && mLeap->isConnected() ) {
		mLeap->update();
	}
    //GET HAND
    for ( LeapSdk::HandMap::const_iterator handIter = mHands.begin(); handIter != mHands.end(); ++handIter ) {
		const LeapSdk::Hand& hand = handIter->second;
        //        cout << hand.getPosition().x << endl;
        //        cout << hand.getDirection();
        
        scaledX = (hand.getPosition().x *(getWindowWidth()/400))+(getWindowWidth()/2);
        scaledY = (-hand.getPosition().y*(getWindowHeight()/400) + getWindowHeight())*2.5 - 400;
        scaledZ = hand.getPosition().z*2+300;
        handPos = Vec3f(scaledX, scaledY, scaledZ);
    }
    
    //AUDIO
    //    mAudio.update();
    
    
    //SCENES
    if (sceneOne)
        scene1();
    if (sceneTwo)
        scene2();
    
    
    //LIGHT
    
    mLight->lookAt( handPos, Vec3f::zero() );
    
    //ROTATE DIAMOND
    if (gong)
        mDiamond.getModelMatrix().rotate( Vec3f( 0.0f, 0.5f, 0), 0.01f );

    
}
void RodSoundApp::draw() {
  while (running &&
//         app::getElapsedSeconds() - tAtLastDraw < 1.0/app::getFrameRate() &&
         fe.nextTimestep(c) > 1.0 / (real) SampleRate) {
    update();
  }
  tAtLastDraw = app::getElapsedSeconds();
  
  PROFILER_START("Draw");
  
	// Clear out the window with grey
	gl::clear(Color(0.45, 0.45, 0.5));
  
  // Enable alpha blending and depth testing
  gl::enableAlphaBlending();
	gl::enableDepthRead(true);
	gl::enableDepthWrite(true);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
  // Draw framerate counter
  gl::setMatricesWindow(getWindowSize());
  std::stringstream ss;
  ss << getAverageFps();
  gl::drawStringRight(ss.str(),
                      Vec2c(getWindowWidth()-toPixels(10), getWindowHeight()-toPixels(20)),
                      Color(0.0, 0.0, 0.0),
                      Font("Arial", toPixels(12)));
  
  // Set projection/modelview matrices
  gl::setMatrices(cam);
  
  // Draw the rod and the normal of the bishop frame
  for(int i=0; i<r->numEdges(); i++) {
    Vec3c p0 = EtoC(r->cur().POS(i));
    Vec3c p1 = EtoC(r->cur().POS(i+1));
    gl::drawLine(p0, p1);
    gl::color(1.0, 1.0, 0.0);
    gl::lineWidth(1.0);
    Vec3c u = EtoC(r->cur().u[i]);
    gl::drawLine((p0+p1)/2.0, (p0+p1)/2.0+u*(p1-p0).length()*2.0);
  }
  
  m.apply();
  
  l->setDiffuse(Color::white());
  l->setAmbient(Color::white());
  l->setPosition(Vec3c(0.0, 50.0, 0.0));
  l->enable();
  
  diffuseProg.bind();
  for (int i=0; i<r->numCPs(); i++) {
    gl::pushModelView();
    gl::translate(EtoC(r->cur().POS(i)));
    spheredl->draw();
    gl::popModelView();
  }
  diffuseProg.unbind();
  
  rodProg.bind();

  floorTex.enableAndBind();
  gl::draw(floor);
  floorTex.disable();
  
  rodProg.unbind();
  
  // Draw rod edges
  rodProg.bind();
  rodTex.enableAndBind();
  for (int i=0; i<r->numEdges(); i++) {
    gl::pushModelView();
    Vec3c v = EtoC(r->cur().edge(i).normalized());
    
    gl::translate(EtoC(r->cur().POS(i)));
    Quaternion<real> q(Vec3c(0.0, 1.0, 0.0), v);
    real angle = acos(std::max((real)-1.0, std::min((real)1.0, (q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().u[i])))));
    if ((q*Vec3c(-1.0, 0.0, 0.0)).dot(EtoC(r->cur().v(i))) > 0.0) angle = -angle;
    gl::rotate(Quaternion<real>(v, angle));
    gl::rotate(q);
    gl::rotate(Vec3c(0.0, r->cur().rot(i)*180.0/constants::pi, 0.0));
    gl::scale(1.0, r->cur().edgeLength(i), 1.0);
    cylinderdl->draw();
    gl::popModelView();
  }
  rodTex.unbind();
  rodProg.unbind();

  for (RodEnergy* e : energies) {
    e->draw(c.timestep());
  }
  integrator->draw();
 
  fe.record(c);
  
  PROFILER_STOP("Draw");
}
/* 
 * @Description: setup function ( more aesthetic as could be in constructor here )
 * @param: none
 * @return: none
 */
void Base_ThreeD_ProjectApp::setup()
{
	RENDER_MODE = 3;
	
	glEnable( GL_LIGHTING );
	glEnable( GL_DEPTH_TEST );
	glEnable(GL_RESCALE_NORMAL); //important if things are being scaled as OpenGL also scales normals ( for proper lighting they need to be normalized )
	
	mParams = params::InterfaceGl( "3D_Scene_Base", Vec2i( 225, 125 ) );
	mParams.addParam( "Framerate", &mCurrFramerate, "", true );
	mParams.addParam( "Eye Distance", &mCameraDistance, "min=-100.0 max=-5.0 step=1.0 keyIncr== keyDecr=-");
	mParams.addParam( "Lighting On", &mLightingOn, "key=l");
	mParams.addParam( "Show/Hide Params", &mShowParams, "key=x");
	mParams.addSeparator();
    
	
	mCurrFramerate = 0.0f;
	mLightingOn = true;
	mViewFromLight = false;
	mShowParams = true;
	
	//create camera
	mCameraDistance = CAM_POSITION_INIT.z;
	mEye		= Vec3f(CAM_POSITION_INIT.x, CAM_POSITION_INIT.y, CAM_POSITION_INIT.z);
	mCenter		= Vec3f::zero();
	mUp			= Vec3f::yAxis();
	
	mCam = new CameraPersp( getWindowWidth(), getWindowHeight(), 180.0f );
	mCam->lookAt(mEye, mCenter, mUp);
	mCam->setPerspective( 45.0f, getWindowAspectRatio(), 1.0f, 50.0f );
	gl::setMatrices( *mCam );
	
	//create light
	mLight = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLight->lookAt( Vec3f(LIGHT_POSITION_INIT.x, LIGHT_POSITION_INIT.y * -1, LIGHT_POSITION_INIT.z), Vec3f( 0, 0, 0 ) );
	mLight->setAmbient( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setDiffuse( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setSpecular( Color( 1.0f, 1.0f, 1.0f ) );
	mLight->setShadowParams( 100.0f, 1.0f, 20.0f );
	mLight->update( *mCam );
	mLight->enable();
	
	//create light ref
	mLightRef = new gl::Light( gl::Light::DIRECTIONAL, 0 );
	mLightRef->lookAt( LIGHT_POSITION_INIT, Vec3f( 0, 0, 0 ) );
	mLightRef->setShadowParams( 100.0f, 1.0f, 20.0f );
	
	//DEBUG Test objects
	ci::ColorA pink( CM_RGB, 0.84f, 0.49f, 0.50f, 1.0f );
	ci::ColorA green( CM_RGB, 0.39f, 0.78f, 0.64f, 1.0f );
	ci::ColorA blue( CM_RGB, 0.32f, 0.59f, 0.81f, 1.0f );
	ci::ColorA orange( CM_RGB, 0.77f, 0.35f, 0.35f, 1.0f );
	
	gl::Material torusMaterial;
	torusMaterial.setSpecular( ColorA( 1.0, 1.0, 1.0, 1.0 ) );
	torusMaterial.setDiffuse( pink );
	torusMaterial.setAmbient( ColorA( 0.3, 0.3, 0.3, 1.0 ) );
	torusMaterial.setShininess( 25.0f );
	
	gl::Material boardMaterial;
	boardMaterial.setSpecular( ColorA( 0.0, 0.0, 0.0, 0.0 ) );
	boardMaterial.setAmbient( ColorA( 0.3, 0.3, 0.3, 1.0 ) );
	boardMaterial.setDiffuse( green );	
	boardMaterial.setShininess( 0.0f );
	
	gl::Material boxMaterial;
	boxMaterial.setSpecular( ColorA( 0.0, 0.0, 0.0, 0.0 ) );
	boxMaterial.setAmbient( ColorA( 0.3, 0.3, 0.3, 1.0 ) );
	boxMaterial.setDiffuse( blue );	
	boxMaterial.setShininess( 0.0f );
	
	gl::Material sphereMaterial;
	sphereMaterial.setSpecular( ColorA( 1.0, 1.0, 1.0, 1.0 ) );
	sphereMaterial.setAmbient( ColorA( 0.3, 0.3, 0.3, 1.0 ) );
	sphereMaterial.setDiffuse( orange ) ;	
	sphereMaterial.setShininess( 35.0f );	
	
    //using DisplayLists for simplicity but highly recommend to use VBO's for serious work ( as DisplayLists will be deprecated soon ... and speed difference in now negligible )
	mTorus = gl::DisplayList( GL_COMPILE );
	mTorus.newList();
	gl::drawTorus( 1.0f, 0.3f, 32, 64 );
	mTorus.endList();
	mTorus.setMaterial( torusMaterial );
	
	mBoard = gl::DisplayList( GL_COMPILE );
	mBoard.newList();
	gl::drawCube( Vec3f( 0.0f, 0.0f, 0.0f ), Vec3f( 10.0f, 0.1f, 10.0f ) );
	mBoard.endList();
	mBoard.setMaterial( boardMaterial );
	
	mBox = gl::DisplayList( GL_COMPILE );
	mBox.newList();
	gl::drawCube( Vec3f( 0.0f, 0.0f, 0.0f ), Vec3f( 1.0f, 1.0f, 1.0f ) );
	mBox.endList();
	mBox.setMaterial( boxMaterial );
	
	mSphere = gl::DisplayList( GL_COMPILE );
	mSphere.newList();
	gl::drawSphere( Vec3f::zero(), 0.8f, 30 );
	mSphere.endList();
	mSphere.setMaterial( sphereMaterial );
	
    //noise texture required for SSAO calculations
	mRandomNoise = gl::Texture( loadImage( loadResource( NOISE_SAMPLER ) ) );
	
	initFBOs();
	initShaders();
}
예제 #18
0
void BrainbowApp::draw()
{
	gl::setViewport( getWindowBounds() );
    
    // SCREENPULSE
    // changes every 12.5 seconds
    float gray = (cos(getElapsedSeconds()/4)*.3)/2 ;
    float otherCol = (sin(getElapsedSeconds()/4)*.2)/2;
    
    screenCol = Vec3f (lightFade+gray, lightFade, (lightFade*2)-otherCol);
    
    if (sceneOne)
        gl::clear( Color(lightFade+gray, lightFade, (lightFade*2)-otherCol) );
    if (sceneTwo)
        gl::clear( Color(1, 1, 1) );
    
    
    // FADE IN INTRO
    if (lightFade < .5){
        lightFade += .0005;
    }
    
    if (mHands.empty())
        mLight->disable();
    
    updateShadowMap();
    
    gl::enableDepthRead();
    gl::enableDepthWrite();
    mShader.bind();
    glEnable( GL_TEXTURE_2D );
	mDepthFbo.bindDepthTexture();
    mShader.bind();
    
    
    // FIRST SCENE
    if (sceneOne){
        
        // disc
        if (zshift > 0){
            glPushMatrix();
            glTranslated( 640, 400, zshift - 200);
            if (shift2 && discOp > 1)
                glScalef(discOp, discOp, 0);
            //    cout << discOp << endl;
            mDisc.draw();
            glPopMatrix();
        }
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        //    if (lightFade > .45f)
        mCloud.update(scaledX, scaledY, scaledZ, diamondFade, 1);
        glPopMatrix();
        
        if (drawDiamond){
            glPushMatrix();
            glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift);
            mDiamond.draw();
            glPopMatrix();
        }
    }
    
    // SECOND SCENE
    if (sceneTwo){
        
        mLight->lookAt( Vec3f(scaledX, scaledY, scaledZ +200), Vec3f (getWindowWidth()*.05, getWindowHeight() * 0.5f, 0.0f ));
        
        // cursor
        glPushMatrix();
        glTranslated( scaledX, scaledY, scaledZ );
        mCur.draw();
        
        if (scaledZ < 375 && scaledZ > 350)
            gl::drawSphere(Vec3f(0,0,0), (scaledZ-350)*.4);
        if (scaledZ >= 375)
            gl::drawSphere(Vec3f(0,0,0), 25*.4);
        glPopMatrix();
        
        
        // rotate whole scene; implement this later:
        
        //        if (targetFilled){
        //            glPushMatrix();
        //            glRotatef(getElapsedSeconds()*10, Vec3f (640, 400, 350) );
        //        }
        for (int i = 0; i < cubes.size() ; i++){
            glPushMatrix();
            glTranslatef(cubes[i].getLocation());
            cubes[i].update(.01f, screenCol);
            glPopMatrix();
        }
        offCounter = 0;        
        for (int i = 0; i < targets.size() ; i++){
            glPushMatrix();
            glTranslatef(targets[i].getLocation());
            targets[i].update(.01f, handPos, screenCol);
            if (targets[i].getBoxed() && targets[i].getBoxNumber() < 15 ){
                addCube(targets[i].getLocation().x, targets[i].getLocation().y, targets[i].getLocation().z);
                targets[i].addBox();
                if (targets[i].getBoxNumber() == 15)
                mAudio.playTraz("box");   
            }
            
            glPopMatrix();
            if (targets[i].getChargeSound()){
                if (!mAudio.isPlaying("charge")){
                    offCounter = 0;
                    mAudio.playTraz("charge");
                }
            }
            //stop charge if deactivated
            if (!targets[i].getChargeSound()){
                offCounter++;
            }
            if (offCounter == targets.size()){
                mAudio.stopTraz("charge");
            }
        }
        //  (from above)
        //   if (targetFilled)
        //   glPopMatrix();
        //
        
        //cloud
        glPushMatrix();
        glTranslated( getWindowWidth() * 0.5f, getWindowHeight() * 0.5f, zshift );
        mCloud.update(0, 0, 0, 0, 2);
        glPopMatrix();
    }
    
    mShader.unbind();
    mDepthFbo.unbindTexture();
    
    //    writeImage( getHomeDirectory() / ("image_" + toString( getElapsedFrames() ) + ".png"), copyWindowSurface() );
	
}
예제 #19
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 );
}
예제 #20
0
void PopGameApp::setup()
{
    
   
    
    speed2 =3.5;
    setWindowSize(1920,1080);
    //setWindowSize(1080/2,1920/2);
    setWindowPos(0, 0);
	mCamera = new CameraPersp( getWindowWidth(), getWindowHeight(), 45.0f );
	mCamera->lookAt( Vec3f( 0, -300, -400 ), Vec3f( 0, 0, 50 ) );
	mCamera->setPerspective( 80.0f, getWindowAspectRatio(),200.0f, 4000.0f );

    
    mLight = new gl::Light( gl::Light::POINT, 0 );
  
	mLight->lookAt( Vec3f(1000,-1000, -2000 ), Vec3f( 0, 1000, 0 ) );
    mLight->setShadowParams(60.0f,2000.f, 3500.0f );
	mLight->update( *mCamera );
	mLight->enable();
    

    
  
    mShader = gl::GlslProg( loadAsset("shadowMap_vert.glsl"),loadAsset("shadowMap_frag.glsl") );
    
	mShader.bind();
	mShader.uniform( "depthTexture", 1 );
    mShader.uniform( "difTexture", 0 );
    mShader.unbind();
    
     initShadowMap();
    
   
   
    groundHolder.setup();
    stage.addChild(&groundHolder);
    
    enemyHandler.setup();
    stage.addChild(&enemyHandler);
    BulletHandler::getInstance()->enemyHandler =&enemyHandler;
   
    
    
    
    plane =new Hero();
    plane->load("plane.png","planeh.png");
    plane->setAlign(neuro::ALIGN_CENTER);
    
    plane->z = 0;
   
   
    
 
    
     stage.addChild(plane);
    prevTime = cinder::app::getElapsedSeconds();
    
    BulletHandler::getInstance()->stage =&stage;
    
    
    logo =new Image();
    logo->load("logo.png");
  // logo->rotationX =-3.1415;
    logo->setAlign(neuro::ALIGN_BOTTOM_LEFT);
    logo->x =0;
    logo->y =1080*2;
    //logo->scaleX =logo->scaleY =logo->scaleZ =4;
    stage2D.scaleX=stage2D.scaleY =0.5;
    stage2D.addChild(logo);
    
}
예제 #21
0
void PopGameApp::draw()
{
    if(getElapsedFrames()>200)return;
    
    gl::pushMatrices();
    
    
    gl::setMatrices( *mCamera );
    gl::enable(GL_DEPTH_TEST);
   
    gl::clear(ColorA(0.5,0.5,0.5,1));
 gl::enableDepthWrite();
	glEnable( GL_LIGHTING );
	updateShadowMap();
    
	gl::enableDepthRead();
	// clear out the window with black
    glEnable( GL_TEXTURE_2D );
 
    
    glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER, 0.5);
	mShader.bind();
	mDepthFbo.bindDepthTexture(1);

  
	mShader.uniform( "shadowTransMatrix", mLight->getShadowTransformationMatrix( *mCamera ) );
    //gl::enable(GL_BLEND);
  	mLight->update( *mCamera );
    
    gl::pushMatrices();
    stage.int_draw();
    gl::popMatrices();
    
    
    
    gl::popMatrices();
   // gl::setMatrices( *mCamera );
    
    mShader.unbind();
    
    gl::disable (GL_DEPTH_TEST);
glDisable( GL_LIGHTING );
    glDisable (GL_ALPHA_TEST);
   glEnable(GL_BLEND);
    gl::enableAlphaBlending();
    
    stage2D.int_draw();
    glDisable(GL_BLEND);
    gl::disableAlphaBlending();
    
   
    
/*
    glDisable( GL_LIGHTING );
     
    gl::setMatricesWindow( getWindowSize() );
    Surface32f shadowMapSurface( mDepthFbo.getDepthTexture() );
    ip::hdrNormalize( &shadowMapSurface );
    gl::color( Color::white() );
    gl::draw( gl::Texture( shadowMapSurface ), Rectf( 0, 0, 128*2, 128*2 ) );
*/
}
/* 
 * @Description: Listen for key presses
 * @param: KeyEvent
 * @return: none
 */
void Base_ThreeD_ProjectApp::keyDown( KeyEvent event ) 
{
	//printf("%i \n", event.getCode());
	
	switch ( event.getCode() ) 
	{
		case KeyEvent::KEY_1:
		{
			RENDER_MODE = 0;
		}
			break;
		case KeyEvent::KEY_2:
		{
			RENDER_MODE = 1;
		}
			break;
		case KeyEvent::KEY_3:
		{
			RENDER_MODE = 2;
		}
			break;
		case KeyEvent::KEY_4:
		{
			RENDER_MODE = 3;
		}
			break;		
			
		case KeyEvent::KEY_UP:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0, 0.0, 0.1);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0, 0.0, 0.1);
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_DOWN:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0, 0.0, -0.1);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0, 0.0, -0.1);	
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_LEFT:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(0.1, 0, 0);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(0.1, 0, 0);
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_RIGHT:
		{
			Vec3f lightPos = mLight->getPosition();
			if ( lightPos.y > 0 )
				lightPos.y *= -1;
			lightPos = lightPos + Vec3f(-0.1, 0, 0);		
			mLight->lookAt( lightPos, Vec3f::zero() );
			//mLight->update( *mCam );
			
			lightPos = mLightRef->getPosition() + Vec3f(-0.1, 0, 0);	
			mLightRef->lookAt( lightPos, Vec3f::zero() );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_w:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(1, 0, 0), -0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_a:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(0, 1, 0), 0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;	
		case KeyEvent::KEY_s:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(1, 0, 0), 0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		case KeyEvent::KEY_d:
		{
			mEye = mCam->getEyePoint();
			mEye = Quatf( Vec3f(0, 1, 0), -0.03f ) * mEye;
			mCam->lookAt( mEye, Vec3f::zero() );
			//mLight->update( *mCam );
			mLightRef->update( *mCam );
		}
			break;
		default:
			break;
	}
}
예제 #23
0
파일: MeshViewApp.cpp 프로젝트: zulis/Imrod
void MeshViewApp::draw()
{
	// Clear the window
	gl::clear();
	gl::color(Color::white());

	if(isInitialized())
	{
		// Get ready to draw in 3D
		gl::pushMatrices();
		gl::setMatrices(m_camera);

		gl::enableDepthRead();
		gl::enableDepthWrite();

		// Bind textures
		if(m_texDiffuse)
			m_texDiffuse->enableAndBind();

		if (m_texNormal)
			m_texNormal->bind(1);

		if (m_texSpecular)
			m_texSpecular->bind(2);

		if(m_texAO)
			m_texAO->bind(3);

		if(m_texEmissive)
			m_texEmissive->bind(4);

		// Bind shader
		m_shader->bind();
		m_shader->uniform("texDiffuse", 0);
		m_shader->uniform("texNormal", 1);
		m_shader->uniform("texSpecular", 2);
		m_shader->uniform("texAO", 3);
		m_shader->uniform("texEmissive", 4);
		m_shader->uniform("texDiffusePower", m_texDiffusePower);
		m_shader->uniform("texNormalPower", m_texNormalPower);
		m_shader->uniform("texSpecularPower", m_texSpecularPower);
		m_shader->uniform("texAOPower", m_texAOPower);
		m_shader->uniform("texEmissivePower", m_texEmissivePower);
		m_shader->uniform("diffuseEnabled", m_diffuseEnabled);
		m_shader->uniform("normalEnabled", m_normalEnabled);
		m_shader->uniform("specularEnabled", m_specularEnabled);
		m_shader->uniform("aoEnabled", m_aoEnabled);
		m_shader->uniform("emissiveEnabled", m_emissiveEnabled);

		m_shader->uniform("material.Ka", m_matAmbient);
		m_shader->uniform("material.Kd", m_matDiffuse);
		m_shader->uniform("material.Ks", m_matSpecular);
		m_shader->uniform("material.Shininess", m_matShininess);
		m_shader->uniform("gamma", m_gamma);

		// Enable lights
		m_light1->enable();
		m_light2->enable();

		// Render model
		gl::pushModelView();
		gl::multModelView(m_matrix);
		m_assimpLoader.draw();
		gl::popModelView();

		// Disable lights
		m_light1->disable();
		m_light2->disable();

		// Unbind shader
		m_shader->unbind();

		// Unbind textures
		gl::disable(m_texDiffuse->getTarget());

		// Disable 3D rendering
		gl::disableDepthWrite();
		gl::disableDepthRead();

		// Restore matrices
		gl::popMatrices();

		// Enable 2D rendering
		gl::setMatricesWindow(getWindowSize());
		gl::setViewport(getWindowBounds());

		// Render parameter window
		if(m_params)
			m_params->draw();
	}

	// Render debug information
	Debug::get().draw(ColorAf::white());
}