Esempio n. 1
0
void StarsApp::setup()
{
	mTime = getElapsedSeconds();

	// create the spherical grid mesh
	mGrid.setup();

	// load the star database and create the VBO mesh
	mStars.load( loadAsset("hygxyz.csv") );
	//mStars.write( writeFile( getAssetPath("") / "hygxyz.dat" ) );	// TODO

	// load texture and shader
	mStars.setup();

	// create user interface
	mUserInterface.setup();

	// initialize background image
	mBackground.setup();

	// initialize camera
	mCamera.setup();

	//
	mIsGridVisible = false;

	//
	forceHideCursor();

	//
	mTimer.start();
}
Esempio n. 2
0
void StarsApp::draw()
{		
	gl::clear( Color::black() ); 

	gl::pushMatrices();
	gl::setMatrices( mCamera.getCamera() );
	{
		// draw background
		mBackground.draw();

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

		// draw stars
		mStars.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();
}
Esempio n. 3
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();
	}
}
Esempio n. 4
0
void StarsApp::keyDown( KeyEvent event )
{
#ifdef WIN32
	// allows the use of the media buttons on your Windows keyboard to control the music
	switch( event.getNativeKeyCode() )
	{
	case VK_MEDIA_NEXT_TRACK:
		// play next music file
		playMusic( getNextFile(mMusicPath) );
		return;
	case VK_MEDIA_PREV_TRACK:
		// play next music file
		playMusic( getPrevFile(mMusicPath) );
		return;
	case VK_MEDIA_STOP:
		stopMusic();
		return;
	case VK_MEDIA_PLAY_PAUSE:
		if( mSoundEngine && mMusic ) {
			if( mMusic->isFinished() )
				playMusic( mMusicPath );
			else
				mMusic->setIsPaused( !mMusic->getIsPaused() );
		}
		return;
	}
#endif

	switch( event.getCode() )
	{
	case KeyEvent::KEY_f:
		// toggle full screen
		setFullScreen( !isFullScreen() );
		if( !isFullScreen() )
			forceShowCursor();
		break;
	case KeyEvent::KEY_v:
		gl::enableVerticalSync( !gl::isVerticalSyncEnabled() );
		break;
	case KeyEvent::KEY_ESCAPE:
		// quit the application
		quit();
		break;
	case KeyEvent::KEY_SPACE:
		// enable animation
		mCamera.setup();
		break;
	case KeyEvent::KEY_g:
		// toggle grid
		mIsGridVisible = !mIsGridVisible;
		break;
	case KeyEvent::KEY_l:
		// toggle labels
		mIsLabelsVisible = !mIsLabelsVisible;
		break;
	case KeyEvent::KEY_c:
		// toggle constellations
		mIsConstellationsVisible = !mIsConstellationsVisible;
		break;
	case KeyEvent::KEY_a:
		// toggle cursor arrow
		if(mIsCursorVisible) 
			forceHideCursor();
		else 
			forceShowCursor();
		break;
	case KeyEvent::KEY_s:
		// toggle stereoscopic view
		mIsStereoscopic = !mIsStereoscopic;
		mIsCylindrical = false;
		mStars.setAspectRatio( mIsStereoscopic ? 0.5f : 1.0f );
		break;
	case KeyEvent::KEY_d:
		// cylindrical panorama
		mIsCylindrical = !mIsCylindrical;
		mIsStereoscopic = false;
		// adjust line width
		mGrid.setLineWidth( mIsCylindrical ? 3.0f : 1.5f );
		mConstellations.setLineWidth( mIsCylindrical ? 2.0f : 1.0f );
		break;
	case KeyEvent::KEY_RETURN:
		createShader();
		break;
	case KeyEvent::KEY_PLUS:
	case KeyEvent::KEY_EQUALS:
	case KeyEvent::KEY_KP_PLUS:
		mCamera.setFov( mCamera.getFov() + 0.1 );
		break;
	case KeyEvent::KEY_MINUS:
	case KeyEvent::KEY_UNDERSCORE:
	case KeyEvent::KEY_KP_MINUS:
		mCamera.setFov( mCamera.getFov() - 0.1 );
		break;
	}
}
Esempio n. 5
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();
}
Esempio n. 6
0
void StarsApp::keyDown( KeyEvent event )
{
#ifdef WIN32
	// allows the use of the media buttons on your Windows keyboard to control the music
	switch( event.getNativeKeyCode() )
	{
	case VK_MEDIA_NEXT_TRACK:
		// play next music file
		playMusic( getNextFile(mMusicPath) );
		return;
	case VK_MEDIA_PREV_TRACK:
		// play next music file
		playMusic( getPrevFile(mMusicPath) );
		return;
	case VK_MEDIA_STOP:
		stopMusic();
		return;
	case VK_MEDIA_PLAY_PAUSE:
		if( mSoundEngine && mMusic ) {
			if( mMusic->isFinished() )
				playMusic( mMusicPath );
			else
				mMusic->setIsPaused( !mMusic->getIsPaused() );
		}
		return;
	}
#endif

	switch( event.getCode() )
	{
	case KeyEvent::KEY_f:
		// toggle full screen
		setFullScreen( !isFullScreen() );
		if( !isFullScreen() )
			forceShowCursor();
		break;
	case KeyEvent::KEY_v:
		gl::enableVerticalSync( !gl::isVerticalSyncEnabled() );
		break;
	case KeyEvent::KEY_ESCAPE:
		// quit the application
		quit();
		break;
	case KeyEvent::KEY_SPACE:
		// enable animation
		mCamera.setup();
		break;
	case KeyEvent::KEY_g:
		// toggle grid
		mIsGridVisible = !mIsGridVisible;
		break;
	case KeyEvent::KEY_l:
		// toggle labels
		mIsLabelsVisible = !mIsLabelsVisible;
		break;
	case KeyEvent::KEY_c:
		// toggle constellations
		mIsConstellationsVisible = !mIsConstellationsVisible;
		break;
	case KeyEvent::KEY_a:
		// toggle cursor arrow
		if(mIsCursorVisible) 
			forceHideCursor();
		else 
			forceShowCursor();
		break;
	case KeyEvent::KEY_s:
		// toggle stereoscopic view
		mIsStereoscopic = !mIsStereoscopic;
		mStars.setAspectRatio( mIsStereoscopic ? 0.5f : 1.0f );
		break;
	/*// 
	case KeyEvent::KEY_KP7:
		mBackground.rotateX(-0.05f);
		break;
	case KeyEvent::KEY_KP9:
		mBackground.rotateX(+0.05f);
		break;
	case KeyEvent::KEY_KP4:
		mBackground.rotateY(-0.05f);
		break;
	case KeyEvent::KEY_KP6:
		mBackground.rotateY(+0.05f);
		break;
	case KeyEvent::KEY_KP1:
		mBackground.rotateZ(-0.05f);
		break;
	case KeyEvent::KEY_KP3:
		mBackground.rotateZ(+0.05f);
		break;
	//*/
	}
}
Esempio n. 7
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();
}