コード例 #1
0
ファイル: Compositor.cpp プロジェクト: sureandrew/stuntrally
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;			
		}

	}
}
コード例 #2
0
 void FacingObject::setOrientation(rviz::DisplayContext* context)
 {
   rviz::ViewManager* manager = context->getViewManager();
   rviz::RenderPanel* panel = manager->getRenderPanel();
   Ogre::Camera* camera = panel->getCamera();
   Ogre::Quaternion q = camera->getDerivedOrientation();
   setOrientation(q);
 }
コード例 #3
0
ファイル: camera_bind.cpp プロジェクト: holocronweaver/llcoi
//Ogre::Camera::getDerivedOrientation() const
void camera_get_derived_orientation(CameraHandle handle, coiQuaternion* orientation)
{
    Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle);
    const Ogre::Quaternion & getter = camera->getDerivedOrientation();

    orientation->w = getter.w;
    orientation->x = getter.x;
    orientation->y = getter.y;
    orientation->z = getter.z;
}
コード例 #4
0
void EC_OgreMovableTextOverlay::Update()
{
    if (!node_ || !visible_ || !placeable_ || renderer_.expired())
        return;

    if(!node_->isInSceneGraph())
    {
        overlay_->hide();
        return;
    }

    Ogre::Camera* camera = renderer_.lock()->GetCurrentCamera();
    if (!camera)
        return;

    Ogre::Viewport* viewport = camera->getViewport();
    Ogre::Vector3 point = node_->_getDerivedPosition();

    // Is the camera facing that point? If not, hide the overlay and return.
    Ogre::Plane cameraPlane = Ogre::Plane(Ogre::Vector3(camera->getDerivedOrientation().zAxis()), camera->getDerivedPosition());
    if(cameraPlane.getSide(point) != Ogre::Plane::NEGATIVE_SIDE)
    {
        overlay_->hide();
        return;
    }

    // Hide the overlay if it's too far.
    Ogre::Vector3 res = camera->getDerivedPosition() - point;
    float distance = sqrt(res.x * res.x + res.y * res.y + res.z * res.z);

    if (distance > MAX_VISIBILITY_DISTANCE)
    {
        overlay_->hide();
        return;
    }

    // Set the alpha channel for the overlay.
    if (materialHasAlpha_)
        SetAlphaChannelIntensity(distance);

    // Derive the 2D screen-space coordinates for node point.
    point = camera->getProjectionMatrix() * (camera->getViewMatrix() * point);

    // Transform from coordinate space [-1, 1] to [0, 1]
    float x = (point.x / 2) + 0.5f;
    float y = 1 - ((point.y / 2) + 0.5f);

    // Update the position (centering the text)
    container_->setPosition(x - (textDim_.x / 2), y);

    // Update the dimensions also if the window is resized.
    if (windowWidth_ != viewport->getActualWidth() ||
        windowHeight_ != viewport->getActualHeight())
    {
        windowWidth_ = viewport->getActualWidth();
        windowHeight_ = viewport->getActualHeight();
        
        textDim_ = GetTextDimensions(text_);
        container_->setDimensions(textDim_.x, textDim_.y);
    }

    ///\todo Scale the text and width and height of the container?
//        text_element_->setMetricsMode(Ogre::GMM_RELATIVE);
//        text_element_->setPosition(textDim_.x, textDim_.y);
//        text_element_->setPosition(textDim_.x / 10, 0.01);
//        text_element_->setCharHeight(max_x - min_x/*2*0.0175f*///);

    overlay_->show();
}