Ejemplo n.º 1
0
void TextComponent::OnUpdate(double time_diff) {
    if(mRefresh && mFont != "") {
        // calculate the text width
        mTextWidth = 0;
        Ogre::Font* font = dynamic_cast<Ogre::Font*>(Ogre::FontManager::getSingleton().getByName(Utils::ToStdString(mFont)).getPointer());
        if(font == nullptr) {
            Logger::Get().Warning("Cannot find font: \"" + mFont + "\".");
        } else {
            std::string str = Utils::ToStdString(mText);
            for(Ogre::String::iterator iter = str.begin(); iter < str.end(); ++iter) {
                if(*iter == 0x0020) {
                    mTextWidth += font->getGlyphAspectRatio(0x0030);
                } else {
                    mTextWidth += font->getGlyphAspectRatio(*iter);
                }
            }
            mTextWidth *= mFontSize;
        }
        mRefresh = false;
    }

    // set the position

    if(DisplayManager::Get()->GetMainCamera() == nullptr) {
        Logger::Get().Error("Cannot get main camera for text component: no main camera set. Disabling text component " + mName + ".");
        Disable();
        return;
    }
    Ogre::Camera* camera = DisplayManager::Get()->GetMainCamera()->GetCamera();
    Ogre::Vector3 screen_pos(camera->getProjectionMatrix() * camera->getViewMatrix() * GetNode()->GetPosition(Node::SCENE));

    if(screen_pos.z >= 1) {
        // behind or in the camera, hide
        mOverlay->hide();
    } else {
        mOverlay->show();
    }

    float x = 1.0f - ((-screen_pos.x * 0.5f) + 0.5f);   // 0 <= x <= 1 // left := 0,right := 1
    float y = ((-screen_pos.y * 0.5f) + 0.5f);          // 0 <= y <= 1 // bottom := 0,top := 1

    x *= camera->getViewport()->getActualWidth();
    y *= camera->getViewport()->getActualHeight();

    mPanel->setMetricsMode(Ogre::GMM_PIXELS);
    mPanel->setWidth(mTextWidth + 2 * mPadding.x);
    mPanel->setHeight(mFontSize + 2 * mPadding.y);
    mPanel->setLeft(x - mTextWidth / 2 - mPadding.x);
    mPanel->setTop(y - mFontSize / 2 - mPadding.y);

    mLabel->setPosition(mPadding.x, mPadding.y);
    mLabel->setDimensions(mTextWidth, mFontSize);
}
Ejemplo n.º 2
0
//! Remove materials
void srs_ui_but::CButProjection::removeMaterials()
{
	connectML(false);

//	std::cerr << "Removing compositior" << std::endl;

	// Get camera and discard compositor.
	rviz::RenderPanel * panel = vis_manager_->getRenderPanel();
	if( panel != 0 )
	{
		Ogre::Camera * camera = panel->getCamera();

		Ogre::CompositorManager::getSingleton().setCompositorEnabled(camera->getViewport(), "zTestedProjection", false);
		Ogre::CompositorManager::getSingleton().removeCompositor( camera->getViewport(), "zTestedProjection" );
	}


//	std::cerr << m_projectionData->getMaterialPtr() << std::endl;
//	std::cerr << "Removing listener" << std::endl;
    delete m_ml;

 //   std::cerr << m_projectionData->getMaterialPtr() << std::endl;
//    std::cerr << "Removing projection data "  << std::endl;
    if( m_projectionData != 0 )
    {
    	delete m_projectionData;
    }

 //   std::cerr << m_projectionData->getMaterialPtr() << std::endl;

//    std::cerr << "Destroying resource groups." << std::endl;

//	Ogre::String nameOfResourceGroup( "MaterialGroup1" );
	Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton();
	//Ogre::MaterialManager &mMgr = Ogre::MaterialManager::getSingleton();

//	std::cerr << "RG: srs_ui_but. Status: " << lRgMgr.isResourceGroupInGlobalPool( "srs_ui_but" ) << ", " << lRgMgr.isResourceGroupInitialised("srs_ui_but") << ", " << lRgMgr.isResourceGroupLoaded("srs_ui_but") << std::endl;

//	lRgMgr.unloadResourceGroup("srs_ui_but");
	lRgMgr.destroyResourceGroup("srs_ui_but");
//	lRgMgr.clearResourceGroup(nameOfResourceGroup);

//	std::cerr << "RG: " << nameOfResourceGroup << std::endl;

//	lRgMgr.destroyResourceGroup( nameOfResourceGroup );


}
void OgrePlanarReflectionMaterial::updateReflectionCamera(const Ogre::MovablePlane& plane)
{
    Ogre::Camera* sofaCamera = mSceneMgr->getCamera("sofaCamera");
    assert(sofaCamera);

    //mCamera->setNearClipDistance(sofaCamera->getNearClipDistance());
    mCamera->setFarClipDistance(sofaCamera->getFarClipDistance());
    mCamera->setAspectRatio(sofaCamera->getViewport()->getActualWidth() /
            sofaCamera->getViewport()->getActualHeight());
    mCamera->setFOVy(sofaCamera->getFOVy());
    mCamera->setOrientation(sofaCamera->getOrientation());
    mCamera->setPosition(sofaCamera->getPosition());

    mCamera->enableReflection(&plane);
    mCamera->enableCustomNearClipPlane(&plane);

}
Ejemplo n.º 4
0
void OGKSceneManager::setActiveScene(const Ogre::String name, Ogre::Real transitionTime)
{
    mPreviousScene = mActiveScene;
    mActiveScene = getScene(name);
    
    Ogre::ColourValue bg = Ogre::ColourValue::Black;
    
    if(mPreviousScene) {
        if(mPreviousScene->mCamera) {
            // save viewport settings for rtt
            Ogre::Camera *cam = mPreviousScene->mCamera->getCamera();
            bg = cam->getViewport()->getBackgroundColour();
        }
        mPreviousScene->onExitTransitionDidStart();
    }
    
    if(mActiveScene) {
        OGKLOG("Transitioning to " + name + " scene");
        mActiveScene->onEnter();
    }
    
    if(transitionTime > 0.01) {
        // transition
        mTransitionTime = transitionTime;
        mTransitionTimeRemaining = transitionTime;
        
        _initRTT();
        
        if(mPreviousScene && mPreviousScene->mCamera &&
           mPreviousScene->mCamera->getCamera()) {
            // render to texture instead
            Ogre::Camera *cam = mPreviousScene->mCamera->getCamera();
            mRenderTexture->removeAllViewports();
            Ogre::Viewport *vp = mRenderTexture->addViewport(cam);
            if(vp) {
                //OGKLOG("Preparing rtt viewport");
                vp->setClearEveryFrame(true);
                vp->setBackgroundColour(bg);
                vp->setOverlaysEnabled(true);
                vp->setCamera(cam);
            }
        }

        if(mOverlay) {
            //OGKLOG("Showing Overlay");
            mOverlay->show();
        }
    }
    else {
        if(mPreviousScene) mPreviousScene->onExit();
        if(mActiveScene) mActiveScene->onEnterTransitionDidFinish();
    }
}
Ejemplo n.º 5
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();
}