Example #1
0
void StarsApp::render()
{
	// draw background
	mBackground.draw();

	// draw grid
	if(mIsGridVisible) 
		mGrid.draw();

	// draw stars
	mStars.draw();

	// draw constellations
	if(mIsConstellationsVisible) 
		mConstellations.draw();

	// draw labels (for now, labels don't behave well in cylindrical view)
	if(mIsLabelsVisible && !mIsCylindrical) {
		mLabels.draw();

		if(mIsConstellationsVisible) 
			mConstellationLabels.draw();
	}
}
Example #2
0
void StarsApp::update()
{	
	double elapsed = getElapsedSeconds() - mTime;
	mTime += elapsed;

	double time = getElapsedSeconds() / 200.0;
	if(mSoundEngine && mMusic && mPlayMusic) time = mMusic->getPlayPosition() / (double) mMusic->getPlayLength();

	// animate camera
	mCamera.setDistanceTime(time);
	mCamera.update(elapsed);

	// adjust content based on camera distance
	float distance = mCamera.getCamera().getEyePoint().length();
	mBackground.setCameraDistance( distance );
	mLabels.setCameraDistance( distance );
	mConstellations.setCameraDistance( distance );
	mConstellationLabels.setCameraDistance( distance );
	mUserInterface.setCameraDistance( distance );

	//
	if(mSoundEngine) {
		// send camera position to sound engine (for 3D sounds)
		Vec3f pos = mCamera.getPosition();
		mSoundEngine->setListenerPosition( 
			vec3df(pos.x, pos.y, pos.z), 
			vec3df(-pos.x, -pos.y, -pos.z), 
			vec3df(0,0,0), 
			vec3df(0,1,0) );

		// if music has finished, play next track
		if( mPlayMusic && mMusic && mMusic->isFinished() ) {
			playMusic( getNextFile(mMusicPath) );
		}
	}
}
Example #3
0
void StarsApp::setup()
{
	// create the spherical grid mesh
	mGrid.setup();

	// load the star database and create the VBO mesh
	if( fs::exists( getAssetPath("") / "stars.cdb" ) )
		mStars.read( loadFile( getAssetPath("") / "stars.cdb" ) );

	if( fs::exists( getAssetPath("") / "labels.cdb" ) )
		mLabels.read( loadFile( getAssetPath("") / "labels.cdb" ) );

	if( fs::exists( getAssetPath("") / "constellations.cdb" ) )
		mConstellations.read( loadFile( getAssetPath("") / "constellations.cdb" ) );

	if( fs::exists( getAssetPath("") / "constellationlabels.cdb" ) )
		mConstellationLabels.read( loadFile( getAssetPath("") / "constellationlabels.cdb" ) );

	// create user interface
	mUserInterface.setup();

	// initialize background image
	mBackground.setup();

	// initialize camera
	mCamera.setup();

	CameraPersp cam( mCamera.getCamera() );
	cam.setNearClip( 0.01f );
	cam.setFarClip( 5000.0f );

	//
	mIsGridVisible = true;
	mIsLabelsVisible = true;
	mIsConstellationsVisible = true;
	mIsStereoscopic = false;
	mIsCylindrical = false;

	// create stars
	mStars.setup();
	mStars.setAspectRatio( mIsStereoscopic ? 0.5f : 1.0f );

	// create labels
	mLabels.setup();
	mConstellationLabels.setup();

	//
	mMusicExtensions.push_back( ".flac" );
	mMusicExtensions.push_back( ".ogg" );
	mMusicExtensions.push_back( ".wav" );
	mMusicExtensions.push_back( ".mp3" );

	mPlayMusic = true;

	// initialize the IrrKlang Sound Engine in a very safe way
	mSoundEngine = shared_ptr<ISoundEngine>( createIrrKlangDevice(), std::mem_fun(&ISoundEngine::drop) );

	if(mSoundEngine) {
		// play 3D Sun rumble
		mSound = createSound( getAssetPath("") / "sound/low_rumble_loop.mp3" );
		if(mSound) {
			mSound->setIsLooped(true);
			mSound->setMinDistance(2.5f);
			mSound->setMaxDistance(12.5f);
			mSound->setIsPaused(false);
		}

		// play background music (the first .mp3 file found in ./assets/music)
		fs::path path = getFirstFile( getAssetPath("") / "music" );
		playMusic(path);
	}

	//
	createShader();

	//
	mTimer.start();

#if (defined WIN32 && defined NDEBUG)
	forceHideCursor();
#else
	forceShowCursor();
#endif

	mTime = getElapsedSeconds();
}
Example #4
0
void StarsApp::draw()
{		
	float w = 0.5f * getWindowWidth();
	float h = 1.0f * getWindowHeight();

	gl::clear( Color::black() ); 

	if(mIsStereoscopic) {
		glPushAttrib( GL_VIEWPORT_BIT );

		// render left eye
		gl::setViewport( Area(0, 0, w, h) );
		mCamera.enableStereoLeft();
		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		{
			// draw background
			mBackground.draw();

			// draw grid
			if(mIsGridVisible) 
				mGrid.draw();

			// draw stars
			mStars.draw();

			// draw constellations
			if(mIsConstellationsVisible) {
				mConstellations.draw();
				mConstellationLabels.draw();
			}

			// draw labels
			if(mIsLabelsVisible)
				mLabels.draw();
		}
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw();

		// render right eye
		gl::setViewport( Area(w, 0, w * 2.0f, h) );
		mCamera.enableStereoRight();
		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		{
			// draw background
			mBackground.draw();

			// draw grid
			if(mIsGridVisible) 
				mGrid.draw();

			// draw stars
			mStars.draw();

			// draw constellations
			if(mIsConstellationsVisible) {
				mConstellations.draw();
				mConstellationLabels.draw();
			}

			// draw labels
			if(mIsLabelsVisible)
				mLabels.draw();
		}
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw();
		
		glPopAttrib();
	}
	else {
		mCamera.disableStereo();
		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		{
			// draw background
			mBackground.draw();

			// draw grid
			if(mIsGridVisible) 
				mGrid.draw();

			// draw stars
			mStars.draw();

			// draw constellations
			if(mIsConstellationsVisible) {
				mConstellations.draw();
				mConstellationLabels.draw();
			}

			// draw labels
			if(mIsLabelsVisible)
				mLabels.draw();
		}
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw();
	}

	// fade in at start of application
	gl::enableAlphaBlending();
	double t = math<double>::clamp( mTimer.getSeconds() / 3.0, 0.0, 1.0 );
	float a = ci::lerp<float>(1.0f, 0.0f, (float) t);

	if( a > 0.0f ) {
		gl::color( ColorA(0,0,0,a) );
		gl::drawSolidRect( getWindowBounds() );
	}
	gl::disableAlphaBlending();
}