Changeset 1614 for code/branches/hud/src/orxonox/overlays/hud/HUDRadar.cc
- Timestamp:
- Jun 21, 2008, 2:35:24 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.cc
r1613 r1614 22 22 * Author: 23 23 * Yuning Chai 24 * Felix Schulthess 24 25 * Co-authors: 25 * Felix Schulthess26 * Reto Grieder 26 27 * 27 28 */ … … 30 31 #include "HUDRadar.h" 31 32 32 #include <assert.h>33 33 #include <OgreOverlayManager.h> 34 #include <Ogre MaterialManager.h>34 #include <OgrePanelOverlayElement.h> 35 35 36 #include "util/Math.h" 36 37 #include "core/ConsoleCommand.h" 37 38 #include "objects/SpaceShip.h" 38 39 #include "objects/WorldEntity.h" 39 40 #include "tools/TextureGenerator.h" 40 #include "Radar Viewable.h"41 #include "Radar.h" 41 42 42 43 namespace orxonox 43 44 { 44 45 CreateFactory(HUDRadar); 45 CreateFactory(RadarShape);46 46 47 47 using namespace Ogre; 48 48 49 49 HUDRadar::HUDRadar() 50 : background_(0) 51 , marker_(0) 52 , sensitivity_(1.0f) 50 : marker_(0) 53 51 { 54 52 RegisterObject(HUDRadar); … … 59 57 if (this->isInitialized()) 60 58 { 61 /*if (this->background_) 62 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 63 while (this->radarDots_.size() > 0) 59 if (this->marker_) 60 OverlayManager::getSingleton().destroyOverlayElement(this->marker_); 61 for (std::vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin(); 62 it != this->radarDots_.end(); ++it) 64 63 { 65 OverlayManager::getSingleton().destroyOverlayElement(this->radarDots_[this->radarDots_.size() - 1]); 66 this->radarDots_.pop_back(); 67 }*/ 64 OverlayManager::getSingleton().destroyOverlayElement(*it); 65 } 68 66 } 69 67 } … … 90 88 if (mode == XMLPort::LoadObject) 91 89 { 92 background_ = (Ogre::PanelOverlayElement*)Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background");93 background_->setMaterialName("Orxonox/Radar");94 overlay_->add2D(background_);95 96 90 marker_ = (Ogre::PanelOverlayElement*)Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Marker"); 97 91 marker_->setMaterialName("Orxonox/RadarMarker"); … … 100 94 } 101 95 } 102 103 /*void HUDRadar::addShape(RadarShape* shape)104 {105 this->shapes_[shape->getIndex()] = shape;106 }107 108 RadarShape* HUDRadar::getShape(unsigned int index) const109 {110 if (index < this->shapes_.size())111 {112 std::map<unsigned int, RadarShape*>::const_iterator it = shapes_.begin();113 for (unsigned int i = 0; i != index; ++it, ++i)114 ;115 return (*it).second;116 }117 else118 return 0;119 }*/120 96 121 97 void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked) … … 131 107 } 132 108 133 /*static int counter = 0;134 if (++counter < 1120 && counter > 120)135 {136 // we have to create a new entry137 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>(138 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr()));139 // get right material140 panel->setMaterialName("Orxonox/RadarSquare");141 panel->setDimensions(0.03, 0.03);142 panel->setPosition((1.0 + (rand() & 0xFF) / 256.0 - 0.001) * 0.5, (1.0 - (rand() & 0xFF) / 256.0 - 0.001) * 0.5);143 panel->show();144 this->overlay_->add2D(panel);145 this->overlay_->show();146 }*/147 148 109 // try to find a panel already created 149 110 Ogre::PanelOverlayElement* panel; 150 std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object);151 if (it == this->radarDots_.end())111 //std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object); 112 if (itRadarDots_ == this->radarDots_.end()) 152 113 { 153 114 // we have to create a new entry 154 115 panel = static_cast<Ogre::PanelOverlayElement*>( 155 116 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr())); 156 radarDots_ [object] = panel;117 radarDots_.push_back(panel); 157 118 // get right material 158 119 panel->setMaterialName(TextureGenerator::getMaterialName( 159 120 shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour())); 160 121 this->overlay_->add2D(panel); 122 this->itRadarDots_ = this->radarDots_.end(); 161 123 } 162 124 else 163 panel = (*it).second; 125 { 126 panel = *itRadarDots_; 127 ++itRadarDots_; 128 std::string materialName = TextureGenerator::getMaterialName( 129 shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour()); 130 if (materialName != panel->getMaterialName()) 131 panel->setMaterialName(materialName); 132 } 164 133 165 134 // set size to fit distance... … … 177 146 { 178 147 this->marker_->show(); 179 this->marker_->setDimensions(size * 1. 2, size * 1.2);180 this->marker_->setPosition((1.0 + coord.x - size * 1. 2) * 0.5, (1.0 - coord.y - size * 1.2) * 0.5);148 this->marker_->setDimensions(size * 1.5, size * 1.5); 149 this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5); 181 150 } 182 151 } … … 184 153 void HUDRadar::radarTick(float dt) 185 154 { 155 this->itRadarDots_ = this->radarDots_.begin(); 156 this->marker_->hide(); 186 157 } 187 188 /*void HUDRadar::tick(float dt)189 {190 // iterate through all RadarObjects191 unsigned int i = 0;192 for (Iterator<RadarViewable> it = ObjectList<RadarViewable>::start(); it; ++it, ++i)193 {194 if ((*it)->isVisibleOnRadar())195 {196 }197 }198 }*/199 200 /*void HUDRadar::listObjects()201 {202 COUT(3) << "List of RadarObjects:\n";203 // iterate through all Radar Objects204 unsigned int i = 0;205 for (Iterator<RadarViewable> it = ObjectList<RadarViewable>::start(); it; ++it, ++i)206 {207 COUT(3) << i++ << ": " << (*it)->getWorldEntity()->getWorldPosition() << std::endl;208 }209 }*/210 158 }
Note: See TracChangeset
for help on using the changeset viewer.