void StereoController::TakeScreenshots(QString path, QString filename)
    {
      
      if (stereo_views_.count() == 0) 
      {
          LogError("StereoController: Cannot take stereographic screenshots. Stereo not enabled!");
          return;
      }

      // FIXME relies on that there is only one external window and
      // its the right side window for stereographical stuff
      QString leftname = filename.replace(".jpg", "_left.jpg");
      QString rightname = filename.replace("_left.jpg", "_right.jpg");

      Ogre::CompositorInstance* comp = stereo_views_["stereoview0"]->GetCompositor();

      if (!comp) 
      {
          LogError("StereoController: Wrong stereographic mode. No Compositor. Cannot take screenshots!");
          return;
      }

      comp->getRenderTarget("Stereo/Left")->writeContentsToFile(path.toStdString() + leftname.toStdString());
      comp->getRenderTarget("Stereo/Right")->writeContentsToFile(path.toStdString() + rightname.toStdString());
    }
Esempio n. 2
0
void CameraBlurListener::notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat)
{
	if (pass_id == 999) 
	{
		if(mApp->pGame->pause == false)
		{
			//acquire the texture flipping attribute in the first frame
			if(compositorinstance)
			{
				mRequiresTextureFlipping  = compositorinstance->getRenderTarget("previousscene")->requiresTextureFlipping();
				compositorinstance=NULL;
			}
			// this is the camera you're using
			#ifndef ROAD_EDITOR
			Ogre::Camera *cam = mApp->mSplitMgr->mCameras.front();
			#else
			Ogre::Camera *cam = mApp->mCamera;
			#endif
			// get the pass
			Ogre::Pass *pass = mat->getBestTechnique()->getPass(0);
			Ogre::GpuProgramParametersSharedPtr  params = pass->getFragmentProgramParameters();
       
			const Ogre::RenderTarget::FrameStats& stats =  mApp->getWindow()->getStatistics();
			float m_lastFPS =stats.lastFPS;
	
			Ogre::Matrix4 projectionMatrix   = cam->getProjectionMatrix();
			if (mRequiresTextureFlipping)
            {
                // Because we're not using setProjectionMatrix, this needs to be done here
                // Invert transformed y
                projectionMatrix[1][0] = -projectionMatrix[1][0];
                projectionMatrix[1][1] = -projectionMatrix[1][1];
                projectionMatrix[1][2] = -projectionMatrix[1][2];
                projectionMatrix[1][3] = -projectionMatrix[1][3];
            }
			Ogre::Matrix4 iVP = (projectionMatrix * cam->getViewMatrix()).inverse();

			if (params->_findNamedConstantDefinition("EPF_ViewProjectionInverseMatrix"))
				 params->setNamedConstant("EPF_ViewProjectionInverseMatrix", iVP);
			if (params->_findNamedConstantDefinition("EPF_PreviousViewProjectionMatrix"))
				params->setNamedConstant("EPF_PreviousViewProjectionMatrix", prevviewproj);
			if (params->_findNamedConstantDefinition("intensity"))
				params->setNamedConstant("intensity", mApp->pSet->motionblurintensity);
	
			float interpolationFactor = m_lastFPS * 0.03f ; //* m_timeScale m_timeScale is a multiplier to control motion blur interactively
			Ogre::Quaternion current_orientation = cam->getDerivedOrientation();
			Ogre::Vector3 current_position = cam->getDerivedPosition();
			Ogre::Quaternion estimatedOrientation = Ogre::Quaternion::Slerp(interpolationFactor, current_orientation, (m_pPreviousOrientation));
			Ogre::Vector3 estimatedPosition    = (1-interpolationFactor) * current_position + interpolationFactor * (m_pPreviousPosition);
			Ogre::Matrix4 prev_viewMatrix = Ogre::Math::makeViewMatrix(estimatedPosition, estimatedOrientation);//.inverse().transpose();
			// compute final matrix
			prevviewproj = projectionMatrix * prev_viewMatrix;

			// update position and orientation for next update time
			m_pPreviousOrientation = current_orientation;
			m_pPreviousPosition = current_position;			
		}

	}
}