minimap.cpp

Go to the documentation of this file.
00001 /*
00002  * minimap.cpp
00003  *
00004  *  Created on: Jan 20, 2013
00005  *      Author: sushil
00006  */
00007 
00008 
00009 
00010 #include <minimap.h>
00011 #include <GraphicsInteractionManager.h>
00012 #include <OgreHardwarePixelBuffer.h>
00013 #include <OgreRectangle2D.h>
00014 
00015 
00016 OgreGFX::Minimap::Minimap(GraphicsInteractionManager *gim): DEFAULT_MINIMAP_UPDATE_PERIOD(0.2) {
00017         gfx = gim;
00018         init();
00019 
00020 }
00021 
00022 OgreGFX::Minimap::~Minimap(void){
00023 
00024 }
00025 //I have done something similar. Just use the member function setVisibilityMask and setVisibilityFlag in the respective
00026 //Viewport & ManualObject & Viewport.
00027 //
00028 //By default, all Movableobject (for which ManualObjectpb derives from) are displayed on all viewports because both have the
00029 //flag 0xFFFFFFFF so when they are AND together, it results into true. So to have ManualObject B & C not shown in viewport A,
00030 //simply set ViewportA visibility mask to 0xFFFFFF00, ManualObject A to 0xF00, ManualObject B to 0xF0, ManualObject C to 0xF.
00031 //Viewport B should be set to 0xFFFF0F0, and C is 0xFFFFF00F.
00032 //
00033 //You can actually 'save more mask' by translating to binary number and set the appropriate mask there, but if you don't
00034 //need a lot of visbility category, the hexadecimal example above is much more 'readable'.
00035 
00036 
00037 void OgreGFX::Minimap::init(void) {
00038 
00039         rttt = Ogre::TextureManager::getSingleton().createManual("MinimapTex",
00040                         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
00041                         Ogre::TEX_TYPE_2D, gfx->mWindow->getWidth(), gfx->mWindow->getHeight(), 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET);
00042         renderTexture = rttt->getBuffer()->getRenderTarget();
00043 
00044         minimapCamera = gfx->mSceneMgr->createCamera("MinimapCamera");
00045         minimapCamera->setNearClipDistance(5);
00046         minimapCamera->setAspectRatio((double)gfx->mWindow->getViewport(0)->getActualWidth()/(double)gfx->mWindow->getViewport(0)->getActualHeight());
00047         Ogre::Vector3 cpos = gfx->mCamera->getPosition();
00048         minimapCamera->setPosition(0, 10000, 0);
00049 
00050         minimapCamera->pitch(Ogre::Radian(-1.5708));;
00051         renderTexture->addViewport(minimapCamera);
00052         renderTexture->getViewport(0)->setClearEveryFrame(true);
00053         renderTexture->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black);
00054         renderTexture->getViewport(0)->setOverlaysEnabled(false);
00055         renderTexture->getViewport(0)->setVisibilityMask(OgreGFX::MINIMAP_CAMERA_MASK);
00056         renderTexture->setAutoUpdated(false);
00057 
00058         minimap = new Ogre::Rectangle2D(true);
00059         minimap->setCorners(-1.0, -0.6, -0.5, -1.0);
00060 
00061         minimap->setBoundingBox(Ogre::AxisAlignedBox(-100000.0f * Ogre::Vector3::UNIT_SCALE, 100000.0f * Ogre::Vector3::UNIT_SCALE));
00062         minimapSceneNode = gfx->mSceneMgr->getRootSceneNode()->createChildSceneNode("MinimapSceneNode");
00063         minimapSceneNode->attachObject(minimap);
00064 
00065         renderMaterial = Ogre::MaterialManager::getSingleton().create("MinimapMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00066         renderMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
00067         renderMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("MinimapTex");
00068 
00069         minimap->setMaterial("MinimapMaterial");
00070 
00071         renderTexture->addListener(this);
00072         gfx->mRoot->addFrameListener(this);
00073         renderTexture->update();
00074         updatePeriod = DEFAULT_MINIMAP_UPDATE_PERIOD;
00075 
00076 }
00077 
00078 bool OgreGFX::Minimap::frameRenderingQueued(const Ogre::FrameEvent& evt){
00079         updatePeriod -= evt.timeSinceLastFrame;
00080         if(updatePeriod < 0){
00081                 renderTexture->update();
00082                 updatePeriod = DEFAULT_MINIMAP_UPDATE_PERIOD;
00083         }
00084         Ogre::Vector3 cpos = gfx->mCamera->getPosition();
00085         minimapCamera->setPosition(cpos.x, 10000, cpos.z);
00086 
00087 
00088         return true;
00089 }
00090 
00091 
00092 
00093 //make minimap invisible
00094 void OgreGFX::Minimap::preRenderTargetUpdate(const Ogre::RenderTargetEvent& evt){
00095         minimap->setVisible(false);
00096 
00097 
00098 }
00099 // snap view from minimapCamera without the minimap being visible!
00100 
00101 void OgreGFX::Minimap::postRenderTargetUpdate(const Ogre::RenderTargetEvent& evt){
00102         minimap->setVisible(true);
00103 }
00104 //Then make minimap visible

Generated on Fri Dec 13 14:54:17 2013 for FastECSLent by  doxygen 1.5.4