Example #1
0
QFundamental::QFundamental(const QEssential & essential, const Cam & kL, const Cam & kR)
{
	
	( *this ).inject(kR.transpose().invert() * ( essential * kL.invert()), 0,0);
	focalLeft = kL.getFocal();
	focalRight = kR.getFocal();
}
Example #2
0
void firstPaint(void)
{
    //Clear Zone
    glClearColor(0.0 , 0.0, 0.0,0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    //Set Up Enables Only first time
    glEnable(GL_DEPTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    
    //Cam Set Up
    camera.updateCamType(aWidth, aheigth);
    camera.updateCamPos();
    
    //Drawing Zone
    scene.setUpLights();
    scene.drawScene(lightMode);
    scene.drawExam();
    //scene.drawAxes();
    
    contSphere = scene.calculateSphere();
    camera.updateCamSphere(contSphere, aWidth, aheigth);
    
    //End zone
    glutSwapBuffers();
    
}
Example #3
0
void	Game_Screen::Refresh()
{
	Cam*	c;

	c = Cam::GetInstance();
	c->Refresh();
	c->RefreshScrolling();
	RefreshSelector(this);
}
Example #4
0
void StarsApp::update()
{	
	double elapsed = getElapsedSeconds() - mTime;
	mTime += elapsed;

	// animate camera
	mCamera.update(elapsed);

	// update background and user interface
	mBackground.setCameraDistance( mCamera.getCamera().getEyePoint().length() );
	mUserInterface.setCameraDistance( mCamera.getCamera().getEyePoint().length() );
}
/**
 * Implements CamInitializerListener callback.
 */
void OpenNiManager::onInitializedCams(std::vector<Cam*> cams) {
	LOG->info("onInitializedCams(cams)");
	// TODO delete this->cams; ??
	this->cams = cams;

	const int n = (int) (int) cams.size();
	printf("Successfully found %i cam(s):\n--------------------------\n\n", n);
	for(int i = 0; i < n; i++) {
		Cam* currentCam = cams.at(i);
		std::cout << "\t" << (i+1) << ". " << currentCam->toString() << std::endl;
	}
	printf("\n");
}
Example #6
0
void reshape(int x, int y) {
    glViewport(0,0,x,y);
    camera.updateCamType(aWidth, aheigth);
    glutPostRedisplay();
    aWidth = x;
    aheigth = y;
}
Example #7
0
void StarsApp::keyDown( KeyEvent event )
{
	switch( event.getCode() )
	{
	case KeyEvent::KEY_f:
		// toggle full screen
		setFullScreen( !isFullScreen() );
		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_c:
		// toggle cursor
		if(mIsCursorVisible) 
			forceHideCursor();
		else 
			forceShowCursor();
		break;
	}
}
Example #8
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();
}
Example #9
0
void TheAbyssApp::setup()
{
    
    // WINDOW NAMING
    ci::app::getWindow()->setTitle("TheAbyss"); // added
    
    // FADEs
    r = *new Rectf(0, 0, getWindowWidth(), getWindowHeight());

    // INSTATIATE AND INIT CAMERA
    mCam = *new Cam();
    mCam.init();
    
    //INSTANTIATE AND INIT ABYSSGUI
    mAbyssGUI = *new AbyssGUI();
    mAbyssGUI.init();
    
    // INSTANTIATE MANAGER
    manager = *new CreatureManager();
    
    // INSTANTIATE BCI WAVE REPRESENTATION
    mBCIWave2 = *new BCIWave(9001, "/wave2/", "/trigger2/",getWindowWidth() - 33   , 30.f , 1.f , 480  , false);
    mBCIWave1 = *new BCIWave(9000, "/wave1/", "/trigger1/",33   , 30.f , 1.f , 480  , false);
                          //port  address    offset maxAmp speed size verbose
    }
Example #10
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();
}
void OpenNiManager::startAll() {
	LOG->info("startAll()");

	for(int i = 0, n = this->cams.size(); i < n; i++) {
		Cam* currentCam = cams.at(i);
		std::cout << (i+1) << ". " << currentCam->toString() << std::endl;

		if(this->initDescriptor->isImageGeneratorRequired()) {
			xn::ImageGenerator generator = currentCam->getImageGenerator();
			CHECK_RC(generator.StartGenerating(), "generator.StartGenerating()");
		}

		if(this->initDescriptor->isUserGeneratorRequired()) {
			this->userManager->start();
		}
	}
}
Example #12
0
inline void	SetCam(ID::Drawable* d, int x, int y)
{
	Cam*	c;
	int	offsetX;
	int	offsetY;
	int16_t	posX;
	int16_t	posY;
	int	caseX;
	int	caseY;

	c = Cam::GetInstance();
	d->GetOffset(&offsetX, &offsetY);
	d->GetPos(&posX, &posY);
	caseX = c->GetMapWidth() * (x - offsetX - posX) / d->GetWidth();
	caseY = c->GetMapHeight() * (y - offsetY - posY) / d->GetHeight();
	c->SetCam(caseX, caseY);
}
Example #13
0
void mouseMovement(int xMouse, int yMouse) {
    Point rotate = {0.0,0.0,0.0};
    switch (mode) {
        case ZOOM_MODE:
            double z;
            if((yO - yMouse) > 0) z = -1;
            else if((yO - yMouse) < 0) z = 1;
            else z = 0;
            
            if(zoomMode == CAM_ZOOM_MOVEMENT) {
                if(camera.type == AXONOMETRIC_CAM) cerr << "Axonometric camera with fovy change zoom type has no effect" << endl;
                else camera.moveCam(Point(0.0,0.0,z), aWidth, aheigth);
            }
            else camera.applyZoom(z, aWidth, aheigth);
            break;
        case PAN_MODE:
            double x,y;
            if((yO - yMouse) > 2) y = -1;
            else if((yO - yMouse) < -2) y = 1;
            else y = 0.0;
            
            if((xO - xMouse) > 2) x = 1;
            else if((xO - xMouse) < -2) x = -1;
            else x = 0.0;
            
            camera.applyPAN(Point(x,y,0.0)); 
            
            break;
        default:
            if (abs(xMouse - xO) > 5 and (xMouse - xO) > 0) rotate.y = -3.0;
            else if (abs(xMouse - xO) > 5) rotate.y = 3.0;
            
            if (abs(yMouse - yO) > 5 and (yMouse - yO) > 0) rotate.x = 3.0;
            else if(abs(yMouse - yO) > 5) rotate.x = -3.0;
            break;
    }
    
    if(rotate.x != 0.0 or rotate.y != 0.0 or rotate.z != 0.0) {
        camera.rotateCam(rotate, aWidth, aheigth);
        glutPostRedisplay();
    }
    xO = xMouse;
    yO = yMouse;    
}
Example #14
0
void StarsApp::mouseDrag( MouseEvent event )
{
	mCursorPos += event.getPos() - mCursorPrevious;
	mCursorPrevious = event.getPos();

	constrainCursor( event.getPos() );

	// allow user to control camera
	mCamera.mouseDrag( mCursorPos, event.isLeftDown(), event.isMiddleDown(), event.isRightDown() );
}
Example #15
0
int main() {

    Cam WebCam;
    // Params by device
    WebCam.setDevice(0);
    WebCam.setResolution(640,480);

    // Capture fuction
    Mat image;
    WebCam.Capture(image);

    namedWindow("Imagen obtenida", WINDOW_NORMAL);
    imshow("Imagen obtenida", image);

/*
    // Creamos una instancia de Camara
    Camara WebCam;
    WebCam.setResolution(2592, 1944); //Poner la resolucion de tu camara

    Mat imagen;
    String r_imagen = "240712.jpg";

    // Funcion que obtiene la imagen de la camara
    //WebCam.GetImage( imagen, 0, "", false /*true para que muestre la captura*);

    WebCam.Test( imagen, -1, r_imagen, true /*true para que muestre la captura*);

    //imagen = imread("10MPX01.jpg");
    if (imagen.empty()) {
        cout << "No se pudo abrir el archivo o el numero de dispositivo no existe"<<endl;
        return 1;
    }
    
    WebCam.showTest();
    //namedWindow("Obtenida de la camara..", WINDOW_NORMAL);
    //imshow("Obtenida de la camara..", imagen);
*/
    cvWaitKey();
    return 0;
}
Example #16
0
void StarsApp::keyDown( KeyEvent event )
{
	switch( event.getCode() )
	{
	case KeyEvent::KEY_f:
		// toggle full screen
		setFullScreen( !isFullScreen() );
		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_c:
		// toggle cursor
		if(mIsCursorVisible) 
			forceHideCursor();
		else 
			forceShowCursor();
		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;
		//*/
	}
}
Example #17
0
void renderScene(bool miniMapOption)
{
    light.makeLight();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // limpar o depth buffer

    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	if(miniMapOption)
        miniMapCam.setMiniMapCam();
    else
        cam.updateCam(game_map.player);

	loadPlayer();
	loadEnemies();
	loadIsland();
    glBindTexture(type, texture);
	renderSea();

	if(!PlaySound("Sounds\\56_Rocket_Tower_Takeover.wav", NULL, SND_ASYNC|SND_FILENAME|SND_LOOP|SND_NOSTOP ))
        PlaySound("Sounds\\56_Rocket_Tower_Takeover.wav", NULL, SND_ASYNC|SND_FILENAME|SND_LOOP|SND_NOSTOP );
}
int main(){
    int keypress = 0;
    Cam Camera;

    // Change the resolutions
    Camera.Devices[0].resolution_active = Camera.Devices[0].resolutions[8];
    Camera.Devices[1].resolution_active = Camera.Devices[1].resolutions[8];
    Camera.Devices[2].resolution_active = Camera.Devices[2].resolutions[2];

    // Activating all the devices
    // Camera.changeStatus();
    // Activating the devices 0 and 1
    Camera.changeStatus(0);
    Camera.changeStatus(1);

    // Show all the devices information
    Camera.printDevicesInfo();

    int imgCont = 1;
    while ( 1 ) {
        Camera.streamImage();

        for(int i=0; i<Camera.get_devices_number(); i++){
            if( Camera.Devices[i].capturing ){
                // Show images dynamically
                stringstream str;
                str << "Cam: " << i;
                cv::imshow(str.str().c_str(), Camera.Devices[i].image_buffer);
            }
        }

        // Eliminate High bits in keypress with AND operator
        keypress = cvWaitKey(1) & 255;

        // If the press key Esc...
        if( keypress == 27 ){
            break;
        }

        // If the press key Enter...
        if( keypress == 13 ){
            for(int i=0; i<Camera.get_devices_number(); i++){
                if( Camera.Devices[i].capturing ){
                    // Save images dynamically
                    stringstream str;
                    str << "../../resources/images/C" << setw(2) << setfill('0') << i <<
                           "-" << setw(2) << setfill('0') << imgCont << ".jpg";
                    cv::imwrite( str.str().c_str(), Camera.Devices[i].image_buffer);
                }
            }
            imgCont++;
        }
    }

    // std::cout << "Press any key to finish.." << std::endl;
    // cv::waitKey();
    cvDestroyAllWindows();
}
void OpenNiManager::shutdown() {
	LOG->info("shutdown()");

	for(int i = 0, n = this->cams.size(); i < n; i++) {
		Cam* currentCam = cams.at(i);

		if(this->initDescriptor->isImageGeneratorRequired()) {
			xn::ImageGenerator generator = currentCam->getImageGenerator();
			if(generator.IsGenerating()) {
				printf("stop generating cam %s\n", currentCam->toString().c_str());
				generator.StopGenerating();
				// TODO "SOFT"_CHECK_RC(generator.StopGenerating(), "generator.StopGenerating()");
			}
		}

		if(this->initDescriptor->isUserGeneratorRequired()) {
			this->userManager->stop();
		}
	}

	this->context.StopGeneratingAll();
	this->context.Shutdown();
}
Example #20
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 #21
0
ASI_ERROR_CODE ASIGetVideoData(int iCameraID, unsigned char* pBuffer, long lBuffSize, int iWaitms) {
   if (iCameraID != cam.info.CameraID)
      return ASI_ERROR_INVALID_ID;
   if (!cam.open || !cam.initialized)
      return ASI_ERROR_CAMERA_CLOSED;
   if (!cam.capturing)
      return ASI_ERROR_GENERAL_ERROR;

   auto left_ms = cam.exposure_ms - cam.timer.elapsed();
   if (left_ms > 0) {
      auto sleep_ms = (iWaitms == -1) ? left_ms : std::min(left_ms, (qint64)iWaitms);
      QThread::msleep(sleep_ms);
      if (left_ms > sleep_ms)
         return ASI_ERROR_TIMEOUT;
   }
   cam.newFrame();
   memcpy(pBuffer, cam.frame.constBits(), std::min(lBuffSize, (long)cam.frame.byteCount()));
   return ASI_SUCCESS;
}
Example #22
0
inline void	RefreshSelector(Game_Screen* gs)
{
	if (gs->refreshSelector == false)
		return ;
	Cam*	c;
	int16_t	newX;
	int16_t	newY;
	int16_t	newW;
	int16_t	newH;

	c = Cam::GetInstance();
	if (gs->nXSelector >= gs->xSelector)
	{
		newX = gs->xSelector;
		newW = gs->nXSelector - gs->xSelector;
	}
	else
	{
		newX = gs->nXSelector;
		newW = gs->xSelector - gs->nXSelector;
	}
	if (gs->nYSelector >= gs->ySelector)
	{
		newY = gs->ySelector;
		newH = gs->nYSelector - gs->ySelector;
	}
	else
	{
		newY = gs->nYSelector;
		newH = gs->ySelector - gs->nYSelector;
	}
//	std::cout << "SetPos(" << newX - c->GetOffsetX() << ", " << newY - c->GetOffsetY() << ")" << std::endl;
//	std::cout << "SetDim(" << newW << ", " << newH << ")" << std::endl;
	if (newX - c->GetOffsetX() >= UI_WIDTH ||
	    newY - c->GetOffsetY() >= UI_HEIGHT ||
	    newX - c->GetOffsetX() + newW >= UI_WIDTH ||
	    newY - c->GetOffsetY() + newH >= UI_HEIGHT)
	{
		gs->refreshSelector = false;
		return ;
	}
	gs->selector.SetPos(newX - c->GetOffsetX(), newY - c->GetOffsetY());
	gs->selector.SetDimension(newW, newH);
	gs->refreshSelector = false;
}
Example #23
0
void TheAbyssApp::draw()
{
//    frameCount++;
	// CLEAR BACKGROUND
	gl::clear( Color( 0, 0, 0 ) );
    gl::enableAlphaBlending();
    
    // SET CAMERA
    mCam.setCam();
    
    // CREATURE DRAW
    manager.draw();
    
    // DRAW BCI WAVE REPRESENTATION
    mBCIWave1.draw();
    mBCIWave2.draw();
    
    // DRAW FADES
    fadeIn();
    fadeOut();
    
    // DRAW ABYSSGUI
    mAbyssGUI.draw();
}
Example #24
0
void keyboardSpecialKeysInteraction(int key, int xMouse, int yMouse) {

    bool refresh, updateCam = true;
    Point trans = Point(0.0, 0.0, 0.0);
    switch (key) {
        case GLUT_KEY_UP:
            trans.y -= 1;
            break;
        case GLUT_KEY_RIGHT:
            trans.x = 1;
            break;
        case GLUT_KEY_DOWN:
            trans.y += 1;
            break;
        case GLUT_KEY_LEFT:
            trans.x -= 1;
            break;
        default:
            refresh = false;
            break;
    }
    if(updateCam) camera.moveCam(trans, aWidth, aheigth);
    if(refresh) glutPostRedisplay();
} 
Example #25
0
void StarsApp::resize()
{
	mCamera.resize();
}
Example #26
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;
	}
}
Example #27
0
void StarsApp::mouseUp( MouseEvent event )
{
	// allow user to control camera
	mCursorPos = mCursorPrevious = event.getPos();
	mCamera.mouseUp( mCursorPos );
}
Example #28
0
void StarsApp::draw()
{		
	int w = getWindowWidth();
	int h = getWindowHeight();

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

	if(mIsStereoscopic) {
		glPushAttrib( GL_VIEWPORT_BIT );
		gl::pushMatrices();

		// render left eye
		mCamera.enableStereoLeft();

		gl::setViewport( Area(0, 0, w / 2, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		// render right eye
		mCamera.enableStereoRight();

		gl::setViewport( Area(w / 2, 0, w, h) );
		gl::setMatrices( mCamera.getCamera() );
		render();
	
		// draw user interface
		mUserInterface.draw("Stereoscopic Projection");

		gl::popMatrices();		
		glPopAttrib();
	}
	else if(mIsCylindrical) {
		// make sure we have a frame buffer to render to
		createFbo();

		// determine correct aspect ratio and vertical field of view for each of the 3 views
		w = mFbo.getWidth() / 3;
		h = mFbo.getHeight();

		const float aspect = float(w) / float(h);
		const float hFoV = 60.0f;
		const float vFoV = toDegrees( 2.0f * math<float>::atan( math<float>::tan( toRadians(hFoV) * 0.5f ) / aspect ) );

		// for values smaller than 1.0, this will cause each view to overlap the other ones
		const float overlap = 1.0f;	

		// bind the frame buffer object
		mFbo.bindFramebuffer();

		// store viewport, camera and matrices, so we can restore later
		glPushAttrib( GL_VIEWPORT_BIT );
		CameraStereo original = mCamera.getCamera();
		gl::pushMatrices();

		// setup camera	
		CameraStereo cam = mCamera.getCamera();
		cam.disableStereo();
		cam.setAspectRatio(aspect);
		cam.setFov( vFoV );

		Vec3f right, up;	
		cam.getBillboardVectors(&right, &up);
		Vec3f forward = up.cross(right);

		// render left side
		gl::setViewport( Area(0, 0, w, h) );

		cam.setViewDirection( Quatf(up, overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// render front side
		gl::setViewport( Area(w, 0, w*2, h) );

		cam.setViewDirection( forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();	
	
		// draw user interface
		mUserInterface.draw( (boost::format("Cylindrical Projection (%d degrees)") % int( (1.0f + 2.0f * overlap) * hFoV ) ).str() );

		// render right side
		gl::setViewport( Area(w*2, 0, w*3, h) );

		cam.setViewDirection( Quatf(up, -overlap * toRadians(hFoV)) * forward );
		cam.setWorldUp( up );
		gl::setMatrices( cam );
		render();
		
		// unbind the frame buffer object
		mFbo.unbindFramebuffer();

		// restore states
		gl::popMatrices();		
		mCamera.setCurrentCam(original);
		glPopAttrib();

		// draw frame buffer and perform cylindrical projection using a fragment shader
		if(mShader) {
			float sides = 3;
			float radians = sides * toRadians( hFoV );
			float reciprocal = 0.5f / sides;

			mShader.bind();
			mShader.uniform("texture", 0);
			mShader.uniform("sides", sides);
			mShader.uniform("radians", radians );
			mShader.uniform("reciprocal", reciprocal );
		}

		Rectf centered = Rectf(mFbo.getBounds()).getCenteredFit( getWindowBounds(), false );
		gl::draw( mFbo.getTexture(), centered );

		if(mShader) mShader.unbind();
	}
	else {
		mCamera.disableStereo();

		gl::pushMatrices();
		gl::setMatrices( mCamera.getCamera() );
		render();
		gl::popMatrices();
	
		// draw user interface
		mUserInterface.draw("Perspective Projection");
	}

	// 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();
}
Example #29
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 #30
0
void StarsApp::resize( ResizeEvent event )
{
	mCamera.resize( event );
}