Changeset 2913 for code/branches/map/src/orxonox/overlays
- Timestamp:
- Apr 9, 2009, 4:52:36 PM (16 years ago)
- Location:
- code/branches/map/src/orxonox/overlays/map
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/map/src/orxonox/overlays/map/Map.cc
r2856 r2913 31 31 #include <OgreSceneNode.h> 32 32 #include <OgreEntity.h> 33 #include <OgreNode.h> 34 35 #include <OgreRenderWindow.h> 36 #include <OgreRenderTexture.h> 37 #include <OgreTexture.h> 38 #include <OgreViewport.h> 39 #include <OgreMaterial.h> 40 #include <OgreMaterialManager.h> 41 #include <OgreRoot.h> 42 #include <OgreHardwarePixelBuffer.h> 43 #include "objects/worldentities/ControllableEntity.h" 44 #include "objects/worldentities/CameraPosition.h" 45 33 46 #include <OgreOverlay.h> 34 47 #include <OgreOverlayElement.h> … … 39 52 #include "core/ConsoleCommand.h" 40 53 #include "objects/Scene.h" 54 #include "objects/RadarViewable.h" 41 55 42 56 namespace orxonox … … 52 66 ObjectList<Scene>::iterator it = ObjectList<Scene>::begin(); 53 67 this->sManager_ = it->getSceneManager(); 54 55 this->sNode_ = new Ogre::SceneNode(sManager_); 56 oManager_ = Ogre::OverlayManager::getSingletonPtr(); 57 overlay_ = oManager_->create("Map"); 68 69 this->mapSceneM_ = Ogre::Root::getSingletonPtr()->createSceneManager( Ogre::ST_GENERIC,"MapScene" ); 70 rootNode_ = mapSceneM_->getRootSceneNode(); 71 72 //this->sNode_ = new Ogre::SceneNode(sManager_); 73 //oManager_ = Ogre::OverlayManager::getSingletonPtr(); 74 //overlay_ = oManager_->create("Map"); 58 75 //overlay_ is member of OrxonoxOverlay 59 76 77 //Not Showing the map as default 78 //this->isVisible_=false; 79 //overlay_->hide(); 80 81 82 //TestEntity 83 //Ogre::Entity * ent = mapSceneM_->createEntity("ent", "drone.mesh"); 84 85 //rootNode_->attachObject( ent ); 86 /*sNode_->setPosition(0,0,-50); 87 overlay_->add3D(sNode_); 88 */ 89 90 91 92 93 94 // Alter the camera aspect ratio to match the viewport 95 //mCamera->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight())); 96 mReflectCam_ = mapSceneM_->createCamera("ReflectCam"); 97 mReflectCam_->setPosition(200,170, -160); 98 mReflectCam_->lookAt(0,0,0); 99 mReflectCam_->setAspectRatio(1); 100 101 std::string camMat_id = "RttMat"; 102 Ogre::MaterialPtr material = this->createRenderCamera(mReflectCam_, camMat_id); 103 /* 104 Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual("RttTex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); 105 106 Ogre::RenderTexture *renderTexture = rttTex->getBuffer()->getRenderTarget(); 107 108 renderTexture->addViewport(mReflectCam_); 109 renderTexture->getViewport(0)->setClearEveryFrame(true); 110 renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black); 111 renderTexture->getViewport(0)->setOverlaysEnabled(false); 112 113 Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create("RttMat", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 114 Ogre::Technique *technique = material->createTechnique(); 115 technique->createPass(); 116 material->getTechnique(0)->getPass(0)->setLightingEnabled(false); 117 material->getTechnique(0)->getPass(0)->createTextureUnitState("RttTex"); 118 */ 119 120 121 // create overlay 122 /* 123 Ogre::Overlay* pOverlay = Ogre::OverlayManager::getSingleton().create("Overlay1"); 124 125 // Create a panel with RenderToTexture texture 126 Ogre::OverlayContainer* m_pOverlayPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel","OverlayPanelName%d")); 127 m_pOverlayPanel->setMetricsMode(Ogre::GMM_PIXELS); 128 m_pOverlayPanel->setPosition(10, 10); 129 m_pOverlayPanel->setDimensions(500, 300); 130 // Give overlay a texture 131 m_pOverlayPanel->setMaterialName(camMat_id); 132 pOverlay->add2D(m_pOverlayPanel); 133 pOverlay->show(); 134 */ 135 overlay_ = Ogre::OverlayManager::getSingleton().create("MapOverlay"); 136 Ogre::OverlayContainer* m_pOverlayPanel = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel","OverlayPanelName%d")); 137 m_pOverlayPanel->setMetricsMode(Ogre::GMM_PIXELS); 138 m_pOverlayPanel->setPosition(10, 10); 139 m_pOverlayPanel->setDimensions(500, 300); 140 // Give overlay a texture 141 m_pOverlayPanel->setMaterialName(camMat_id); 142 overlay_->add2D(m_pOverlayPanel); 60 143 //Not Showing the map as default 61 144 this->isVisible_=false; 62 145 overlay_->hide(); 63 64 //TestEntity 65 Ogre::Entity * ent = sManager_->createEntity("ent", "drone.mesh"); 66 sNode_->attachObject( ent ); 67 sNode_->setPosition(0,0,-50); 68 overlay_->add3D(sNode_); 69 } 70 146 147 } 148 149 Ogre::MaterialPtr Map::createRenderCamera(Ogre::Camera * cam, std::string matName) 150 { 151 Ogre::TexturePtr rttTex = Ogre::TextureManager::getSingleton().createManual(matName+"_tex", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 512, 512, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET); 152 153 Ogre::RenderTexture *renderTexture = rttTex->getBuffer()->getRenderTarget(); 154 155 renderTexture->addViewport(cam); 156 renderTexture->getViewport(0)->setClearEveryFrame(true); 157 renderTexture->getViewport(0)->setBackgroundColour(ColourValue::Black); 158 renderTexture->getViewport(0)->setOverlaysEnabled(false); 159 160 Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 161 Ogre::Technique *technique = material->createTechnique(); 162 technique->createPass(); 163 material->getTechnique(0)->getPass(0)->setLightingEnabled(false); 164 material->getTechnique(0)->getPass(0)->createTextureUnitState(matName+"_tex"); 165 return material; 166 } 167 168 void Map::updatePositions() 169 { 170 //Ogre::Entity * ent;// = mapSceneM_->createEntity("ent1", "drone.mesh"); 171 int i=0; 172 for(ObjectList<orxonox::RadarViewable>::iterator it = ObjectList<orxonox::RadarViewable>::begin(); 173 it!=ObjectList<orxonox::RadarViewable>::end(); 174 it++) 175 { 176 i++; 177 //COUT(0) << "Radar_Position: " << it->getRVWorldPosition() << std::endl; 178 //Ogre::SceneNode node = it->getMapNode(); 179 //Ogre::Entity ent = it->getMapEntity(); 180 if( !(it->MapNode_) ) 181 { 182 it->MapNode_ = rootNode_->createChildSceneNode( it->getRVWorldPosition() ); 183 //it->MapNode_->translate( it->getRVOrientedVelocity(), Ogre::TS_WORLD ); 184 } 185 it->MapNode_->setPosition( it->getRVWorldPosition() ); 186 it->MapNode_->translate( it->getRVOrientedVelocity(), (Ogre::Node::TransformSpace)3 ); 187 if( !(it->MapEntity_) ) 188 { 189 it->MapEntity_ = mapSceneM_->createEntity( "MapEnt"+i, "drone.mesh"); 190 it->MapNode_->attachObject( it->MapEntity_ ); 191 } 192 193 194 195 } 196 } 197 71 198 void Map::XMLPort(Element& xmlElement, XMLPort::Mode mode) 72 199 { 73 200 SUPER(Map, XMLPort, xmlElement, mode); 74 } 201 } 202 203 void Map::changedOwner() 204 { 205 //COUT(0) << "shipptr" << this->getOwner()->getReverseCamera() << std::endl; 206 if(this->getOwner()->getReverseCamera()) 207 { 208 //COUT(0) << "foo"; 209 this->getOwner()->getReverseCamera()->attachCamera(this->mReflectCam_); 210 } 211 } 212 75 213 76 214 void Map::toggleVisibility() … … 80 218 this->overlay_->show(); 81 219 this->isVisible_=1; 220 //updatePositions(); 82 221 } 83 222 else … … 98 237 COUT(0) << it->isVisible_ << std::endl; 99 238 it->toggleVisibility(); 239 //it->updatePositions(); 100 240 } 101 241 } … … 103 243 void Map::tick(float dt) 104 244 { 105 sNode_->lookAt(Vector3::NEGATIVE_UNIT_Z, Ogre::Node::TS_WORLD, Vector3::NEGATIVE_UNIT_Z); 245 //sNode_->lookAt(Vector3::NEGATIVE_UNIT_Z, Ogre::Node::TS_WORLD, Vector3::NEGATIVE_UNIT_Z); 246 updatePositions(); 106 247 107 248 } -
code/branches/map/src/orxonox/overlays/map/Map.h
r2856 r2913 28 28 #define _MAP_H__ 29 29 30 30 #include <string> 31 31 #include "OrxonoxPrereqs.h" 32 32 #include <OgrePrerequisites.h> … … 46 46 47 47 48 48 49 namespace orxonox 49 50 { … … 57 58 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 58 59 virtual void tick(float dt); 60 virtual void changedOwner(); 59 61 60 62 static Ogre::MaterialPtr createRenderCamera(Ogre::Camera * cam, std::string matName); 61 63 62 64 static void openMap(); 65 66 static const int maxRange_s=1000; 63 67 64 68 private: // functions 65 69 void toggleVisibility(); 70 void updatePositions(); 66 71 67 72 68 73 private: // variables 69 74 Ogre::SceneManager* sManager_; 70 Ogre::SceneNode* sNode_; 75 Ogre::SceneManager* mapSceneM_; 76 Ogre::SceneNode* rootNode_; 71 77 Ogre::OverlayManager * oManager_; 78 Ogre::Camera* mReflectCam_; 79 80 72 81 73 82 bool isVisible_;
Note: See TracChangeset
for help on using the changeset viewer.