예제 #1
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;			
		}

	}
}
예제 #2
0
//Ogre::Camera::getDerivedPosition() const
void camera_get_derived_position(CameraHandle handle, coiVector3* position)
{
    Ogre::Camera* camera = static_cast<Ogre::Camera*>(handle);
    const Ogre::Vector3& getter = camera->getDerivedPosition();

    position->x = getter.x;
    position->y = getter.y;
    position->z = getter.z;
}
예제 #3
0
	void DebugWindow::updateFps()
	{
		const RenderTarget::FrameStats& stats = Root::getSingleton().getAutoCreatedWindow()->getStatistics();

		Ogre::String textSt = "Current FPS: " + 
			StringConverter::toString(stats.lastFPS)+
			"\nBest/worst/avg FPS: " + 
			StringConverter::toString(stats.bestFPS) + "/" + 
			StringConverter::toString(stats.worstFPS) + "/" + 
			StringConverter::toString(stats.avgFPS)+
			"\nBest/worst Frame times: " + 
			StringConverter::toString(stats.bestFPS) + "/" + 
			StringConverter::toString(stats.worstFPS)+
			"\nTriangle Count: " + 
			StringConverter::toString(stats.triangleCount);

		if (UiSubsystem::getSingleton().getActiveCharacter() != NULL && 
			UiSubsystem::getSingleton().getActiveCharacter()->getActor() != NULL)
		{
            ActorControlledObject* charObj = UiSubsystem::getSingletonPtr()->
				getActiveCharacter()->getActor()->getControlledObject();

            if( charObj != NULL )
            {
			    Ogre::Vector3 pos = charObj->getMovableObject()->getParentNode()->getWorldPosition();

			    textSt += "\nPlayer Position [ "
				    + StringConverter::toString(pos.x,2,0,32,std::ios_base::fixed)+", "
				    + StringConverter::toString(pos.y,2,0,32,std::ios_base::fixed)+", "
				    + StringConverter::toString(pos.z,2,0,32,std::ios_base::fixed)+" ]";
            }
		}

        Actor* camActor = ActorManager::getSingleton().getActor("DefaultCamera");
		if( camActor != 0 && camActor->_getSceneNode() != NULL )
		{
			Ogre::Camera* cam = dynamic_cast<CameraObject*>(camActor->getControlledObject())->getCamera();
            Ogre::Vector3 pos = cam->getDerivedPosition();

			textSt += "\nCamera Position [ "
				+ StringConverter::toString(pos.x,2,0,32,std::ios_base::fixed)+", "
				+ StringConverter::toString(pos.y,2,0,32,std::ios_base::fixed)+", "
				+ StringConverter::toString(pos.z,2,0,32,std::ios_base::fixed)+" ]";
		}

        setPageText(mDebugPageName, textSt);
	}
예제 #4
0
bool EC_WaterPlane::IsCameraInsideWaterCube()
{
    // Check that is camera inside of defined water plane.
    if (entity_ == 0)
        return false;

    Ogre::Camera *camera = world_.lock()->GetRenderer()->GetActiveOgreCamera();
    if (!camera)
        return false;
    Ogre::Vector3 posCamera = camera->getDerivedPosition();

    if (IsTopOrBelowWaterPlane(float3(posCamera.x, posCamera.y, posCamera.z)))
    {
        float d = GetDistanceToWaterPlane(float3(posCamera.x, posCamera.y, posCamera.z));
        if (d < 0 && depth.Get() >= fabs(d))
            return true;
    }

    return false;
}
예제 #5
0
	void LightningManager::update(const Ogre::Real& timeSinceLastFrame)
	{
		if (!mCreated)
		{
			return;
		}

		if (mEnabled)
		{
			mRemainingTime -= timeSinceLastFrame;

			if (mRemainingTime <= 0)
			{
				mRemainingTime = Ogre::Math::RangeRandom(0, 2*mAverageLightningApparitionTime);

				// Select a random camera to place the lightning
				if (!mVClouds->_getCamerasData().empty())
				{
					Ogre::Camera* c = mVClouds->_getCamerasData().at(mVClouds->_getCamerasData().size()*0.999).camera;

					Ogre::Real prob = Ogre::Math::RangeRandom(0,1);
					
					// Cloud-to-ground
					if (prob < 0.5)
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(0,-1,0), 
							// Ray length
							mVClouds->getGeometrySettings().Height.x + 0.1*mVClouds->getGeometrySettings().Height.y);
					}
					// Cloud-to-cloud
					else if (prob < 0.7)
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(Ogre::Math::RangeRandom(-1,1),Ogre::Math::RangeRandom(-0.1,0.1),Ogre::Math::RangeRandom(-1,1)).normalisedCopy(), 
							// Ray length
							Ogre::Math::RangeRandom(0.5,1.5f)*0.2*mVClouds->getGeometrySettings().Height.y);
					}
					// Cloud-to-ground + cloud-to-cloud
					else
					{
						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(0,-1,0), 
							// Ray length
							mVClouds->getGeometrySettings().Height.x + 0.1*mVClouds->getGeometrySettings().Height.y);

						addLightning(
							// Ray position
							Ogre::Vector3(c->getDerivedPosition().x + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5), mVClouds->getGeometrySettings().Height.x + 0.2*mVClouds->getGeometrySettings().Height.y, c->getDerivedPosition().z + Ogre::Math::RangeRandom(-c->getFarClipDistance()*0.5,c->getFarClipDistance()*0.5)/Ogre::Math::RangeRandom(1,5)), 
							// Ray direction
							Ogre::Vector3(Ogre::Math::RangeRandom(-1,1),Ogre::Math::RangeRandom(-0.1,0.1),Ogre::Math::RangeRandom(-1,1)).normalisedCopy(), 
							// Ray length
							Ogre::Math::RangeRandom(0.5,1.5f)*0.2*mVClouds->getGeometrySettings().Height.y);
					}

					updateMaterial();
				}
			}
		}

		for(std::vector<Lightning*>::iterator it = mLightnings.begin(); it != mLightnings.end();)
		{
			if ((*it)->isFinished())
			{
				Ogre::SceneNode* sn = (*it)->getSceneNode();

				delete (*it);
				it = mLightnings.erase(it);

				// Remove the associated scene node
				for(std::vector<Ogre::SceneNode*>::iterator it2 = mSceneNodes.begin(); it2 != mSceneNodes.end(); it2++)
				{
					if ((*it2) == sn)
					{
						sn->getParentSceneNode()->removeAndDestroyChild(sn);
						mSceneNodes.erase(it2);
						break;
					}
				}
			}
			else
			{
				(*it)->update(timeSinceLastFrame);
				it++;
			}
		}
	}
예제 #6
0
void EC_OgreEnvironment::UpdateVisualEffects(f64 frametime)
{
    if (renderer_.expired())
        return;
    RendererPtr renderer = renderer_.lock();
    Ogre::Camera *camera = renderer->GetCurrentCamera();
    Ogre::Viewport *viewport = renderer->GetViewport();
    Ogre::SceneManager *sceneManager = renderer->GetSceneManager();
        
#ifdef CAELUM
    // Set sunlight attenuation using diffuse multiplier.
    // Seems to be working ok, but feel free to fix if you find better logic and/or values.
    Ogre::ColourValue diffuseMultiplier(sunColorMultiplier_, sunColorMultiplier_, sunColorMultiplier_, 1);
    caelumSystem_->getSun()->setDiffuseMultiplier(diffuseMultiplier);

    Ogre::Light* sun = caelumSystem_->getSun()->getMainLight();
    Ogre::Light* moon = caelumSystem_->getMoon()->getMainLight();

    float sunDirZaxis = caelumSystem_->getSun()->getMainLight()->getDirection().z;
    if (sunDirZaxis > 0)
    {
        sunColorMultiplier_ -= 0.005f;
        if (sunColorMultiplier_ <= 0.05f)
            sunColorMultiplier_ = 0.05f;
    }
    else if(sunDirZaxis < 0)
    {
        sunColorMultiplier_ += 0.010f;
        if (sunColorMultiplier_ >= MAX_SUNLIGHT_MULTIPLIER)
            sunColorMultiplier_ = MAX_SUNLIGHT_MULTIPLIER;
    }
    
    if ( !fog_color_override_)
        fogColor_ = caelumSystem_->getGroundFog()->getColour();
#endif

#ifdef CAELUM
    // Update Caelum system.
    caelumSystem_->notifyCameraChanged(camera);
    caelumSystem_->updateSubcomponents(frametime);

    // Disable specular from the sun & moon for now, because it easily leads to too strong results
    sun->setSpecularColour(0.0f, 0.0f, 0.0f);
    moon->setSpecularColour(0.0f, 0.0f, 0.0f);
#endif

#ifdef HYDRAX
    
    // Update Hydrax system.
    hydraxSystem_->update(frametime);
    sunPos = camera->getPosition();
    sunPos -= caelumSystem_->getSun()->getLightDirection() * 80000;
    hydraxSystem_->setSunPosition(sunPos);


#endif

    Ogre::Entity* water = 0;
    
    cameraFarClip_ = renderer->GetViewDistance();
    
    if ( sceneManager->hasEntity("WaterEntity") )
        water = sceneManager->getEntity("WaterEntity");
              
    if (!water)
    {
        // No water entity, set fog value.
        Real fogStart = fogStart_;
        Real fogEnd = fogEnd_;
        ClampFog(fogStart, fogEnd, cameraFarClip_);
        
        sceneManager->setFog(Ogre::FOG_LINEAR, fogColor_, 0.001, fogStart, fogEnd);
        viewport->setBackgroundColour(fogColor_);
        camera->setFarClipDistance(cameraFarClip_);
    }
    else 
    {
        if(camera->getDerivedPosition().z >= water->getParentNode()->getPosition().z)
        {        
            // We're above the water.
            Real fogStart = fogStart_;
            Real fogEnd = fogEnd_;
            ClampFog(fogStart, fogEnd, cameraFarClip_);
        
#ifdef CAELUM
            caelumSystem_->forceSubcomponentVisibilityFlags(caelumComponents_);
#endif
            sceneManager->setFog(Ogre::FOG_LINEAR, fogColor_, 0.001, fogStart, fogEnd);
            viewport->setBackgroundColour(fogColor_);
            camera->setFarClipDistance(cameraFarClip_);
            cameraUnderWater_ = false;
        }
        else
        {
            // We're below the water.
            Real fogStart = waterFogStart_;
            Real fogEnd = waterFogEnd_;
            Real farClip = waterFogEnd_ + 10.f;
            if (farClip > cameraFarClip_)
                farClip = cameraFarClip_;            
            ClampFog(fogStart, fogEnd, farClip);            
#ifdef CAELUM
            // Hide the Caelum subsystems.
            caelumSystem_->forceSubcomponentVisibilityFlags(Caelum::CaelumSystem::CAELUM_COMPONENTS_NONE);
#endif
            sceneManager->setFog(Ogre::FOG_LINEAR, fogColor_ * waterFogColor_, 0.001, fogStart, fogEnd);
            viewport->setBackgroundColour(fogColor_ * waterFogColor_);
            camera->setFarClipDistance(farClip);
            cameraUnderWater_ = true;
        }
    }

#ifdef CAELUM 
    // If sun color and direction are controlled by user then their value are needed to override here. 
    // internally caelum calculates new values for those so they are needed to set again in each update loop.

    if ( override_flags_.testFlag(None) )
        return;

    if ( override_flags_.testFlag(AmbientLight))
    {   
        // Override ambient light.
        sceneManager->setAmbientLight(userAmbientLight_);
    }

    if ( override_flags_.testFlag(SunDirection) )
    {
        // Override sun direction.
        if ( sun != 0 )
            sun->setDirection(userSunDirection_);
    }

    if ( override_flags_.testFlag(SunColor) )
    {
        // Override sun color. 
        if ( sun != 0 )
            sun->setDiffuseColour(userSunColor_);
    }
#endif 

}
예제 #7
0
void OgreInfo::diagnose(std::ostream& outputStream)
{
	Ogre::SceneManagerEnumerator::SceneManagerIterator sceneManagerI = Ogre::Root::getSingleton().getSceneManagerIterator();
	while (sceneManagerI.hasMoreElements()) {
		Ogre::SceneManager* sceneManager = sceneManagerI.getNext();
		outputStream << "Scenemanager(" << sceneManager->getTypeName() << ") " << sceneManager->getName() << std::endl;
		outputStream << " Number of scene nodes: " << countNodes(sceneManager->getRootSceneNode()) << std::endl;
		outputStream << " Movable objects:" << std::endl;
		unsigned int movableObjectCounter = 0;
		Ogre::Root::MovableObjectFactoryIterator movableObjectFactoryI = Ogre::Root::getSingleton().getMovableObjectFactoryIterator();
		while (movableObjectFactoryI.hasMoreElements()) {
			Ogre::MovableObjectFactory* factory = movableObjectFactoryI.getNext();
			std::string type(factory->getType());
			{
				Ogre::SceneManager::MovableObjectIterator I = sceneManager->getMovableObjectIterator(type);
				while (I.hasMoreElements()) {
					movableObjectCounter++;
					Ogre::MovableObject* movable = I.getNext();
					if (movable->getMovableType() == "Light") {
						Ogre::Light* light = static_cast<Ogre::Light*> (movable);
						outputStream << "  * Light " << light->getName() << "(" << (light->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
						outputStream << "   Pos: " << light->getDerivedPosition() << std::endl;
						outputStream << "   Direction: " << light->getDerivedDirection() << std::endl;

					} else {
						std::stringstream ssPosAndOrientation;
						if (movable->getParentSceneNode() && movable->isInScene()) {
							ssPosAndOrientation << " pos: " << movable->getParentSceneNode()->getPosition() << " orientation: " << movable->getParentSceneNode()->getOrientation();
						}
						outputStream << "  * " << type << " " << movable->getName() << "(" << (movable->isInScene() ? "in scene" : "not in scene") << ")" << ssPosAndOrientation.str() << std::endl;
						//					outputStream << "  Pos: " << light->getDerivedPosition() << std::endl;
						//					outputStream << "  Direction: " << light->getDerivedDirection() << std::endl;
					}
				}
			}
		}

		outputStream << " Number of movable objects: " << movableObjectCounter << std::endl;

		outputStream << " Cameras:" << std::endl;
		{
			Ogre::SceneManager::CameraIterator I = sceneManager->getCameraIterator();
			while (I.hasMoreElements()) {
				Ogre::Camera* camera = I.getNext();
				outputStream << "  Camera " << camera->getName() << "(" << (camera->isInScene() ? "in scene" : "not in scene") << ")" << std::endl;
				outputStream << "  Pos: " << camera->getDerivedPosition() << std::endl;
				outputStream << "  Direction: " << camera->getDerivedDirection() << std::endl;
				outputStream << "  Clip distances: " << camera->getNearClipDistance() << " - " << camera->getFarClipDistance() << std::endl;
			}
		}

	}

	size_t resourceMemoryUsage = 0;
	outputStream << "Resource Managers:" << std::endl;
	Ogre::ResourceGroupManager::ResourceManagerIterator I = Ogre::ResourceGroupManager::getSingleton().getResourceManagerIterator();
	while (I.hasMoreElements()) {
		std::string name = I.peekNextKey();
		Ogre::ResourceManager* manager = I.getNext();
		outputStream << " Resource Manager: " << name << std::endl;
		if (manager->getMemoryBudget() == std::numeric_limits<size_t>::max()) {
			outputStream << "  Memory budget: not set" << std::endl;
		} else {
			outputStream << "  Memory budget: " << manager->getMemoryBudget() << " bytes" << std::endl;
		}
		outputStream << "  Memory usage:  " << manager->getMemoryUsage() << " bytes" << std::endl;
		resourceMemoryUsage += manager->getMemoryUsage();

		Ogre::ResourceManager::ResourceMapIterator resourceI = manager->getResourceIterator();
		if (resourceI.hasMoreElements()) {
			outputStream << "  Resources: " << std::endl;
			int resourceCount = 0;
			int loadedResourceCount = 0;
			while (resourceI.hasMoreElements()) {
				Ogre::ResourcePtr resource = resourceI.getNext();
				if (resource->isLoaded()) {
					std::string reloadable = resource->isReloadable() ? " reloadable" : "";
					outputStream << "   " << resource->getName() << " ( " << resource->getSize() << " bytes)" << reloadable;
					Ogre::Texture* texture = dynamic_cast<Ogre::Texture*>(resource.get());
					if (texture) {
						outputStream << texture->getWidth() << "x" << texture->getHeight() << " ";
					}
					outputStream << std::endl;
					loadedResourceCount++;
				}
				resourceCount++;
			}
			outputStream << "  Total number of resources: " << resourceCount << std::endl;
			outputStream << "  Number of loaded resources: " << loadedResourceCount << std::endl;
		}
	}

	outputStream << "Total memory usage for all resource manager: " << resourceMemoryUsage << " bytes" << std::endl;

	outputStream << std::flush;
}
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();
}