Ejemplo n.º 1
0
void AppBase::privateUpdate__()
{
	mFrameCount++;

	// service asio::io_service
	mIo->poll();

	if( getNumWindows() > 0 ) {
		WindowRef mainWin = getWindowIndex( 0 );
		if( mainWin )
			mainWin->getRenderer()->makeCurrentContext();
	}

	mSignalUpdate.emit();

	update();

	mTimeline->stepTo( static_cast<float>( getElapsedSeconds() ) );

	double now = mTimer.getSeconds();
	if( now > mFpsLastSampleTime + mFpsSampleInterval ) {
		//calculate average Fps over sample interval
		uint32_t framesPassed = mFrameCount - mFpsLastSampleFrame;
		mAverageFps = (float)(framesPassed / (now - mFpsLastSampleTime));

		mFpsLastSampleTime = now;
		mFpsLastSampleFrame = mFrameCount;
	}
}
Ejemplo n.º 2
0
void ViewerConfiguration::updateViewer(void)
	{
	if(viewer!=0)
		{
		/* Update the controlled viewer: */
		Vector currentViewDirection=viewer->getHeadTransformation().inverseTransform(viewer->getViewDirection());
		viewer->setEyes(currentViewDirection,eyePos[0],(eyePos[2]-eyePos[1])*Scalar(0.5));
		
		/* Notify all VR windows that their viewers might have changed: */
		int numWindows=getNumWindows();
		for(int i=0;i<numWindows;++i)
			getWindow(i)->updateViewerState(viewer);
		}
	}
/**********************************************************************************

Function Name = SecurityProjectDemoApp::createInfectedWindow

Descriptive Name = Create custom image with data inside.

Function =

    This function is used to create windows based on the configuration that is passed in
    to the function. Also supports adding images into the windows while creating the image.

Input =
    
    std::string securityImageRef  - The location of the image that needs to be displayed
    int windowWidth               - The width of the window
    int windowHeight              - The height of the window
    int windowXPos                - The x position where the window is to be placed
    int windowYPos                - The y position where the window is to be placed

Output =
   
   Currently there are no outputs from this functions as it only performs the action. 

******************************************************************************/
void SecurityProjectDemoApp::createInfectedWindow ( cinder::DataSourceRef securityImageRef, int windowWidth, int windowHeight, int windowXPos, int windowYPos )
{
    // Load the image that was passed in into a proper format
    gl::Texture securityImage = gl::Texture ( loadImage ( securityImageRef ) );
    
    // Create the window of size passed in, set the image into the windowData object and set it as borderless and
    app::WindowRef newWindow = createWindow ( Window::Format ().size ( windowWidth, windowHeight ) ) ;
    newWindow->setUserData ( new WindowData ( securityImage ) );
    newWindow->setBorderless ( true ) ;
    newWindow->setPos ( windowXPos, windowYPos ) ;
    newWindow->setTitle ( "SecurityProjectDemoApp" ) ;

    // Get a unique id for the window that is used to identify the window
    int uniqueId = getNumWindows () ;

    // Set the unique number for the new window that was created
    newWindow->getSignalClose ().connect (
        [uniqueId, this]
        {
           this->console () << "You closed window #" << uniqueId << std::endl ; // Action performed when the window is closed
        }
    ) ;
}
Ejemplo n.º 4
0
void InputDeviceAdapterPlayback::updateInputDevices(void)
	{
	/* Do nothing if at end of file: */
	if(done)
		return;
	
	if(synchronizePlayback)
		{
		Misc::Time rt=Misc::Time::now();
		double realTime=double(rt.tv_sec)+double(rt.tv_nsec)/1000000000.0;
		
		if(firstFrame)
			{
			/* Calculate the offset between the saved timestamps and the system's wall clock time: */
			timeStampOffset=nextTimeStamp-realTime;
			}
		else
			{
			/* Check if there is positive drift between the system's offset wall clock time and the next time stamp: */
			double delta=nextTimeStamp-(realTime+timeStampOffset);
			if(delta>0.0)
				{
				/* Block to correct the drift: */
				vruiDelay(delta);
				}
			}
		}
	
	/* Update time stamp and synchronize Vrui's application timer: */
	timeStamp=nextTimeStamp;
	synchronize(timeStamp);
	
	/* Start sound playback: */
	if(firstFrame&&soundPlayer!=0)
		soundPlayer->start();
	
	/* Update all input devices: */
	for(int device=0;device<numInputDevices;++device)
		{
		/* Update tracker state: */
		if(inputDevices[device]->getTrackType()!=InputDevice::TRACK_NONE)
			{
			TrackerState::Vector translation;
			inputDeviceDataFile.read(translation.getComponents(),3);
			Scalar quat[4];
			inputDeviceDataFile.read(quat,4);
			inputDevices[device]->setTransformation(TrackerState(translation,TrackerState::Rotation::fromQuaternion(quat)));
			}
		
		/* Update button states: */
		for(int i=0;i<inputDevices[device]->getNumButtons();++i)
			{
			int buttonState=inputDeviceDataFile.read<int>();
			inputDevices[device]->setButtonState(i,buttonState);
			}
		
		/* Update valuator states: */
		for(int i=0;i<inputDevices[device]->getNumValuators();++i)
			{
			double valuatorState=inputDeviceDataFile.read<double>();
			inputDevices[device]->setValuator(i,valuatorState);
			}
		}
	
	/* Read time stamp of next data frame: */
	try
		{
		nextTimeStamp=inputDeviceDataFile.read<double>();
		
		/* Request an update for the next frame: */
		requestUpdate();
		}
	catch(Misc::File::ReadError)
		{
		done=true;
		nextTimeStamp=Math::Constants<double>::max;
		
		if(quitWhenDone)
			{
			/* Request exiting the program: */
			shutdown();
			}
		}
	
	if(saveMovie)
		{
		if(firstFrame)
			{
			/* Get a pointer to the window from which to save movie frames: */
			if(movieWindowIndex>=0&&movieWindowIndex<getNumWindows())
				movieWindow=getWindow(movieWindowIndex);
			else
				std::cerr<<"InputDeviceAdapterPlayback: Not saving movie due to invalid movie window index "<<movieWindowIndex<<std::endl;
			}
		
		if(movieWindow!=0)
			{
			/* Copy the last saved screenshot if multiple movie frames needed to be taken during the last Vrui frame: */
			while(nextMovieFrameTime<timeStamp)
				{
				/* Copy the last saved screenshot: */
				pid_t childPid=fork();
				if(childPid==0)
					{
					/* Create the old and new file names: */
					char oldImageFileName[1024];
					snprintf(oldImageFileName,sizeof(oldImageFileName),movieFileNameTemplate.c_str(),nextMovieFrameCounter-1);
					char imageFileName[1024];
					snprintf(imageFileName,sizeof(imageFileName),movieFileNameTemplate.c_str(),nextMovieFrameCounter);
					
					/* Execute the cp system command: */
					char* cpArgv[10];
					int cpArgc=0;
					cpArgv[cpArgc++]=const_cast<char*>("/bin/cp");
					cpArgv[cpArgc++]=oldImageFileName;
					cpArgv[cpArgc++]=imageFileName;
					cpArgv[cpArgc++]=0;
					execvp(cpArgv[0],cpArgv);
					}
				else
					{
					/* Wait for the copy process to finish: */
					waitpid(childPid,0,0);
					}
				
				/* Advance the frame counters: */
				nextMovieFrameTime+=movieFrameTimeInterval;
				++nextMovieFrameCounter;
				}
			
			if(nextTimeStamp>nextMovieFrameTime)
				{
				/* Request a screenshot from the movie window: */
				char imageFileName[1024];
				snprintf(imageFileName,sizeof(imageFileName),movieFileNameTemplate.c_str(),nextMovieFrameCounter);
				movieWindow->requestScreenshot(imageFileName);
				
				/* Advance the movie frame counters: */
				nextMovieFrameTime+=movieFrameTimeInterval;
				++nextMovieFrameCounter;
				}
			}
		}
	
	firstFrame=false;
	}
Ejemplo n.º 5
0
bool InputDeviceAdapterMouse::keyPressed(int keyCode,int modifierMask,const char* string)
{
    bool stateChanged=false;

    if(keyCode==keyboardModeToggleKeyCode)
    {
        keyboardMode=!keyboardMode;
        if(fakeMouseCursor)
        {
            /* Change the glyph renderer's cursor type to a text cursor: */
        }
        else if(keyboardMode)
        {
            /* Change the cursor in all windows to a text cursor: */
            for(int i=0; i<getNumWindows(); ++i)
            {
                VRWindow* win=Vrui::getWindow(i);
                if(win!=0)
                {
                    Cursor cursor=XCreateFontCursor(win->getContext().getDisplay(),XC_xterm);
                    XDefineCursor(win->getContext().getDisplay(),win->getWindow(),cursor);
                    XFreeCursor(win->getContext().getDisplay(),cursor);
                }
            }
        }
        else
        {
            /* Change the cursor in all windows back to the regular: */
            for(int i=0; i<getNumWindows(); ++i)
            {
                VRWindow* win=Vrui::getWindow(i);
                if(win!=0)
                    XUndefineCursor(win->getContext().getDisplay(),win->getWindow());
            }
        }
    }
    else if(keyboardMode)
    {
        /* Process the key event: */
        ControlKeyMap::Iterator ckmIt=controlKeyMap.findEntry(ControlKey(keyCode,modifierMask&(ShiftMask|ControlMask)));
        if(!ckmIt.isFinished())
        {
            /* Store a text control event: */
            textControlEvents.push_back(std::pair<int,GLMotif::TextControlEvent>(nextEventOrdinal,ckmIt->getDest()));
            ++nextEventOrdinal;
        }
        else if(string!=0&&string[0]!='\0')
        {
            /* Store a text event: */
            textEvents.push_back(std::pair<int,GLMotif::TextEvent>(nextEventOrdinal,GLMotif::TextEvent(string)));
            ++nextEventOrdinal;
        }

        stateChanged=true;
    }
    else
    {
        /* Check if the key is a button key: */
        int buttonIndex=getButtonIndex(keyCode);
        if(buttonIndex>=0)
        {
            /* Set button state: */
            int stateIndex=(numButtons+numButtonKeys)*modifierKeyMask+numButtons+buttonIndex;
            stateChanged=changeButtonState(stateIndex,true);
        }

        /* Check if the key is a modifier key: */
        int modifierIndex=getModifierIndex(keyCode);
        if(modifierIndex>=0)
        {
            /* Change current modifier mask: */
            changeModifierKeyMask(modifierKeyMask|(0x1<<modifierIndex));
            stateChanged=true;
        }
    }

    // requestUpdate();

    return stateChanged;
}