Changeset 6924 for code/branches/hudelements/src/modules/overlays/hud
- Timestamp:
- May 18, 2010, 5:34:48 PM (15 years ago)
- Location:
- code/branches/hudelements/src/modules/overlays/hud
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hudelements/src/modules/overlays/hud/HUDNavigation.cc
r6923 r6924 28 28 29 29 #include "HUDNavigation.h" 30 #include <utility> 31 32 #include <string> 30 33 31 #include <OgreCamera.h> 32 #include <OgreFontManager.h> 34 33 #include <OgreOverlayManager.h> 35 34 #include <OgreTextAreaOverlayElement.h> 36 35 #include <OgrePanelOverlayElement.h> 36 37 37 #include "util/Math.h" 38 38 #include "util/Convert.h" … … 50 50 namespace orxonox 51 51 { 52 CreateFactory(HUDNavigation);53 54 HUDNavigation::HUDNavigation(BaseObject* creator)52 CreateFactory(HUDNavigation); 53 54 HUDNavigation::HUDNavigation(BaseObject* creator) 55 55 : OrxonoxOverlay(creator) 56 { 57 RegisterObject(HUDNavigation); 58 59 setFont("Monofur"); 60 setTextSize(0.05f); 61 setNavMarkerSize(0.05f); 62 63 64 65 // // create nav text 66 // navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 67 // .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 68 // 69 // // create nav marker 70 // navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 71 // .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 72 // navMarker_->setMaterialName("Orxonox/NavArrows"); 73 74 /* 75 // create aim marker 76 aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 77 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString())); 78 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 79 this->wasOutOfView_ = true; // Ensure the material is changed right the first time.. 80 81 82 */ 83 /* 84 background_->addChild(navMarker_);*/ 85 // background_->addChild(aimMarker_); 86 // background_->addChild(navText_); 87 88 // hide at first 89 // this->setVisible(false); 90 91 92 93 // setAimMarkerSize(0.04f); 94 95 } 96 97 HUDNavigation::~HUDNavigation() 98 { 99 if (this->isInitialized()) 100 { 101 for (activeObjectListType::iterator it = activeObjectList_.begin(); it != activeObjectList_.end();) 102 removeObject((it++)->first); 103 } 104 } 105 106 void HUDNavigation::XMLPort(Element& xmlElement, XMLPort::Mode mode) 107 { 108 SUPER(HUDNavigation, XMLPort, xmlElement, mode); 109 110 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode); 111 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode); 112 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 113 // XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 114 } 115 116 void HUDNavigation::setFont(const std::string& font) 117 { 118 fontName_ = font; 119 if (!activeObjectList_.empty()) 120 { 121 for (tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable) 122 { 123 if (tempRadarViewable->second.text_ && !fontName_.empty()) 124 tempRadarViewable->second.text_->setFontName(fontName_); 125 } 126 } 127 } 128 129 const std::string& HUDNavigation::getFont() const 130 { 131 return fontName_; 132 } 133 134 void HUDNavigation::setTextSize(float size) 135 { 136 textSize_ = size; 137 if (!activeObjectList_.empty()) 138 { 139 for (tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable) 140 { 141 if (tempRadarViewable->second.text_ && size >= 0.0f) 142 tempRadarViewable->second.text_->setCharHeight(size); 143 } 144 } 145 } 146 147 float HUDNavigation::getTextSize() const 148 { 149 return textSize_; 150 } 151 152 void HUDNavigation::tick(float dt) 153 { 154 SUPER(HUDNavigation, tick, dt); 155 156 // updateActiveObjectList(activeObjectList_); 157 158 // Get radar 159 // Radar* radar = this->getOwner()->getScene()->getRadar(); 160 // 161 // if (!radar->getFocus()) 162 // { 163 // this->overlay_->hide(); 164 // return; 165 // } 166 // else 167 // { 168 // this->overlay_->show(); 169 // } 170 171 // set text 172 // int dist = static_cast<int>(getDist2Focus()); 173 // navText_->setCaption(multi_cast<std::string>(dist)); 174 // float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f; 175 176 if (!activeObjectList_.empty()) 177 { 178 for (tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable) 179 { 180 181 182 //get Distance to HumanController and save it in the TextAreaOverlayElement. 183 int dist = (int)(tempRadarViewable->first->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length(); 184 tempRadarViewable->second.text_->setCaption(multi_cast<std::string>(dist)); 185 float textLength = multi_cast<std::string>(dist).size() * tempRadarViewable->second.text_->getCharHeight() * 0.3f; 186 187 188 189 orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera(); 190 if (!cam) 191 return; 192 const Matrix4& transform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 193 // transform to screen coordinates 194 Vector3 pos = transform * tempRadarViewable->first->getRVWorldPosition(); 195 196 197 198 56 { 57 RegisterObject(HUDNavigation); 58 59 // Set default values 60 setFont("Monofur"); 61 setTextSize(0.05f); 62 setNavMarkerSize(0.05f); 63 } 64 65 HUDNavigation::~HUDNavigation() 66 { 67 if (this->isInitialized()) 68 { 69 for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end();) 70 removeObject((it++)->first); 71 } 72 } 73 74 void HUDNavigation::XMLPort(Element& xmlElement, XMLPort::Mode mode) 75 { 76 SUPER(HUDNavigation, XMLPort, xmlElement, mode); 77 78 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode); 79 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode); 80 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 81 } 82 83 void HUDNavigation::setFont(const std::string& font) 84 { 85 const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); 86 if (fontPtr.isNull()) 87 { 88 COUT(2) << "Warning: HUDNavigation: Font '" << font << "' not found" << std::endl; 89 return; 90 } 91 fontName_ = font; 92 for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it) 93 { 94 if (it->second.text_ != NULL) 95 it->second.text_->setFontName(fontName_); 96 } 97 } 98 99 const std::string& HUDNavigation::getFont() const 100 { 101 return fontName_; 102 } 103 104 void HUDNavigation::setTextSize(float size) 105 { 106 if (size <= 0.0f) 107 { 108 COUT(2) << "Warning: HUDNavigation: Negative font size not allowed" << std::endl; 109 return; 110 } 111 textSize_ = size; 112 for (ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it) 113 { 114 if (it->second.text_) 115 it->second.text_->setCharHeight(size); 116 } 117 } 118 119 float HUDNavigation::getTextSize() const 120 { 121 return textSize_; 122 } 123 124 void HUDNavigation::tick(float dt) 125 { 126 SUPER(HUDNavigation, tick, dt); 127 128 Camera* cam = CameraManager::getInstance().getActiveCamera(); 129 if (cam == NULL) 130 return; 131 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 132 133 for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it) 134 { 135 // Get Distance to HumanController and save it in the TextAreaOverlayElement. 136 int dist = (int)((it->first->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length() + 0.5f); 137 it->second.text_->setCaption(multi_cast<std::string>(dist)); 138 float textLength = multi_cast<std::string>(dist).size() * it->second.text_->getCharHeight() * 0.3f; 139 140 // Transform to screen coordinates 141 Vector3 pos = camTransform * it->first->getRVWorldPosition(); 142 143 bool outOfView = true; 199 144 if (pos.z > 1.0) 200 145 { 201 146 // z > 1.0 means that the object is behind the camera 202 tempRadarViewable->second.outOfView_= true;147 outOfView = true; 203 148 // we have to switch all coordinates (if you don't know why, 204 149 // try linear algebra lectures, because I can't explain..) … … 207 152 } 208 153 else 209 tempRadarViewable->second.outOfView_= pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;210 211 if ( tempRadarViewable->second.outOfView_)154 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 155 156 if (outOfView) 212 157 { 213 // object is not in view214 // aimMarker_->hide(); 215 216 if (! tempRadarViewable->second.wasOutOfView_)158 // Object is not in view 159 160 // Change material only if outOfView changed 161 if (!it->second.wasOutOfView_) 217 162 { 218 tempRadarViewable->second.panel_->setMaterialName("Orxonox/NavArrows");219 tempRadarViewable->second.wasOutOfView_ = true;163 it->second.panel_->setMaterialName("Orxonox/NavArrows"); 164 it->second.wasOutOfView_ = true; 220 165 } 221 166 222 223 167 // Switch between top, bottom, left and right position of the arrow at the screen border 224 168 if (pos.x < pos.y) 225 169 { 226 170 if (pos.y > -pos.x) 227 171 { 228 // up172 // Top 229 173 float position = pos.x / pos.y + 1.0f; 230 tempRadarViewable->second.panel_->setPosition((position - tempRadarViewable->second.panel_->getWidth()) * 0.5f, 0.0f);231 tempRadarViewable->second.panel_->setUV(0.5f, 0.0f, 1.0f, 0.5f);232 tempRadarViewable->second.text_->setLeft((position - textLength) * 0.5f);233 tempRadarViewable->second.text_->setTop(tempRadarViewable->second.panel_->getHeight());174 it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 0.0f); 175 it->second.panel_->setUV(0.5f, 0.0f, 1.0f, 0.5f); 176 it->second.text_->setLeft((position - textLength) * 0.5f); 177 it->second.text_->setTop(it->second.panel_->getHeight()); 234 178 } 235 179 else 236 180 { 237 // left181 // Left 238 182 float position = pos.y / pos.x + 1.0f; 239 tempRadarViewable->second.panel_->setPosition(0.0f, (position - tempRadarViewable->second.panel_->getWidth()) * 0.5f);240 tempRadarViewable->second.panel_->setUV(0.0f, 0.0f, 0.5f, 0.5f);241 tempRadarViewable->second.text_->setLeft(tempRadarViewable->second.panel_->getWidth() + 0.01f);242 tempRadarViewable->second.text_->setTop((position - tempRadarViewable->second.text_->getCharHeight()) * 0.5f);183 it->second.panel_->setPosition(0.0f, (position - it->second.panel_->getWidth()) * 0.5f); 184 it->second.panel_->setUV(0.0f, 0.0f, 0.5f, 0.5f); 185 it->second.text_->setLeft(it->second.panel_->getWidth() + 0.01f); 186 it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f); 243 187 } 244 188 } … … 248 192 if (pos.y < -pos.x) 249 193 { 250 // down194 // Bottom 251 195 float position = -pos.x / pos.y + 1.0f; 252 tempRadarViewable->second.panel_->setPosition((position - tempRadarViewable->second.panel_->getWidth()) * 0.5f, 1.0f - tempRadarViewable->second.panel_->getHeight());253 tempRadarViewable->second.panel_->setUV(0.0f, 0.5f, 0.5f, 1.0f);254 tempRadarViewable->second.text_->setLeft((position - textLength) * 0.5f);255 tempRadarViewable->second.text_->setTop(1.0f - tempRadarViewable->second.panel_->getHeight() - tempRadarViewable->second.text_->getCharHeight());196 it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 1.0f - it->second.panel_->getHeight()); 197 it->second.panel_->setUV(0.0f, 0.5f, 0.5f, 1.0f); 198 it->second.text_->setLeft((position - textLength) * 0.5f); 199 it->second.text_->setTop(1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight()); 256 200 } 257 201 else 258 202 { 259 // right203 // Right 260 204 float position = -pos.y / pos.x + 1.0f; 261 tempRadarViewable->second.panel_->setPosition(1.0f - tempRadarViewable->second.panel_->getWidth(), (position - tempRadarViewable->second.panel_->getHeight()) * 0.5f);262 tempRadarViewable->second.panel_->setUV(0.5f, 0.5f, 1.0f, 1.0f);263 tempRadarViewable->second.text_->setLeft(1.0f - tempRadarViewable->second.panel_->getWidth() - textLength - 0.01f);264 tempRadarViewable->second.text_->setTop((position - tempRadarViewable->second.text_->getCharHeight()) * 0.5f);205 it->second.panel_->setPosition(1.0f - it->second.panel_->getWidth(), (position - it->second.panel_->getHeight()) * 0.5f); 206 it->second.panel_->setUV(0.5f, 0.5f, 1.0f, 1.0f); 207 it->second.text_->setLeft(1.0f - it->second.panel_->getWidth() - textLength - 0.01f); 208 it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f); 265 209 } 266 210 } … … 268 212 else 269 213 { 270 271 272 // object is in view 273 /* 274 Vector3 aimpos = transform * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 275 Projectile::getSpeed(), Radar::getInstance().getFocus()->getRVWorldPosition(), Radar::getInstance().getFocus()->getRVOrientedVelocity()); 276 */ 277 if (tempRadarViewable->second.wasOutOfView_) 214 // Object is in view 215 216 // Change material only if outOfView changed 217 if (it->second.wasOutOfView_) 278 218 { 279 tempRadarViewable->second.panel_->setMaterialName("Orxonox/NavTDC");280 tempRadarViewable->second.wasOutOfView_ = false;219 it->second.panel_->setMaterialName("Orxonox/NavTDC"); 220 it->second.wasOutOfView_ = false; 281 221 } 282 222 283 // object is in view 284 tempRadarViewable->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 285 tempRadarViewable->second.panel_->setLeft((pos.x + 1.0f - tempRadarViewable->second.panel_->getWidth()) * 0.5f); 286 tempRadarViewable->second.panel_->setTop((-pos.y + 1.0f - tempRadarViewable->second.panel_->getHeight()) * 0.5f); 287 288 289 // aimMarker_->show(); 290 // aimMarker_->setLeft((aimpos.x + 1.0f - aimMarker_->getWidth()) * 0.5f); 291 // aimMarker_->setTop((-aimpos.y + 1.0f - aimMarker_->getHeight()) * 0.5f); 292 // 293 tempRadarViewable->second.text_->setLeft((pos.x + 1.0f + tempRadarViewable->second.panel_->getWidth()) * 0.5f); 294 tempRadarViewable->second.text_->setTop((-pos.y + 1.0f + tempRadarViewable->second.panel_->getHeight()) * 0.5f); 223 // Position marker 224 it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 225 it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f); 226 it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f); 227 228 // Position text 229 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); 230 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 295 231 } 296 232 297 tempRadarViewable->second.panel_->show(); 298 tempRadarViewable->second.text_->show(); 299 // tempRadarViewable->second.text_->hide(); 300 } 301 302 } 303 233 // Make sure the overlays are shown 234 it->second.panel_->show(); 235 it->second.text_->show(); 236 } 237 } 238 239 240 /** Overridden method of OrxonoxOverlay. 241 @details 242 Usually the entire overlay scales with scale(). 243 Here we obviously have to adjust this. 244 */ 245 void HUDNavigation::sizeChanged() 246 { 247 // Use size to compensate for aspect ratio if enabled. 248 float xScale = this->getActualSize().x; 249 float yScale = this->getActualSize().y; 250 251 for (ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it) 252 { 253 if (it->second.panel_ != NULL) 254 it->second.panel_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); 255 if (it->second.text_ != NULL) 256 it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale); 257 } 258 } 259 260 void HUDNavigation::addObject(RadarViewable* object) 261 { 262 if (object == NULL) 263 return; 264 265 // Don't display our own ship 266 if (object == dynamic_cast<RadarViewable*>(this->getOwner())) 267 return; 268 269 // Object hasn't been added yet (we know that) 270 assert(this->activeObjectList_.find(object) == this->activeObjectList_.end()); 271 272 // Scales used for dimensions and text size 273 float xScale = this->getActualSize().x; 274 float yScale = this->getActualSize().y; 275 276 // Create everything needed to display the object on the radar and add it to the map 277 278 // Create arrow/marker 279 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 280 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 281 panel->setMaterialName("Orxonox/NavArrows"); 282 panel->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); 283 284 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 285 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 286 text->setFontName(this->fontName_); 287 text->setCharHeight(text->getCharHeight() * yScale); 288 289 ObjectInfo tempStruct = {panel, text, true}; 290 activeObjectList_[object] = tempStruct; 291 292 this->background_->addChild(panel); 293 this->background_->addChild(text); 294 } 295 296 void HUDNavigation::removeObject(RadarViewable* viewable) 297 { 298 ObjectMap::iterator it = activeObjectList_.find(viewable); 299 300 if (activeObjectList_.find(viewable) != activeObjectList_.end()) 301 { 302 // Detach overlays 303 this->background_->removeChild(it->second.panel_->getName()); 304 this->background_->removeChild(it->second.text_->getName()); 305 // Properly destroy the overlay elements (do not use delete!) 306 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 307 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 308 // Remove from the list 309 activeObjectList_.erase(viewable); 310 } 311 else 312 COUT(2) << "Warning, HUDNavigation: Attempting to remove non-existent object" << std::endl; 313 } 314 315 void HUDNavigation::changedOwner() 316 { 317 // TODO: Delete old objects? 318 const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects(); 319 for (std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it) 320 { 321 if (!(*it)->isHumanShip_) 322 this->addObject(*it); 323 } 324 } 304 325 } 305 306 307 // float HUDNavigation::getDist2Focus() const {308 //309 // Radar* radar = this->getOwner()->getScene()->getRadar();310 // if (radar->getFocus() && HumanController::getLocalControllerEntityAsPawn())311 // return (radar->getFocus()->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length();312 // else313 // return 0;314 // }315 316 /**317 @brief Overridden method of OrxonoxOverlay. Usually the entire overlay318 scales with scale(). Here we obviously have to adjust this.319 */320 void HUDNavigation::sizeChanged()321 {322 // use size to compensate for aspect ratio if enabled.323 float xScale = this->getActualSize().x;324 float yScale = this->getActualSize().y;325 326 if (!activeObjectList_.empty())327 {328 for (tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable)329 {330 331 if (tempRadarViewable->second.panel_)332 tempRadarViewable->second.panel_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale);333 // if (this->aimMarker_)334 // aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale);335 if (tempRadarViewable->second.text_)336 tempRadarViewable->second.text_->setCharHeight(tempRadarViewable->second.text_->getCharHeight() * yScale);337 }338 }339 }340 341 342 void HUDNavigation::addObject(RadarViewable* object)343 {344 if (object == dynamic_cast<RadarViewable*>(this->getOwner()))345 return;346 347 assert(object);348 349 // Make sure the object hasn't been added yet350 assert( this->activeObjectList_.find(object) == this->activeObjectList_.end() );351 352 // Create everything needed to display the object on the radar and add it to the map353 354 // create nav marker355 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()356 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));357 358 panel->setMaterialName("Orxonox/NavArrows");359 360 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()361 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));362 363 364 float xScale = this->getActualSize().x;365 float yScale = this->getActualSize().y;366 367 panel->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale);368 text->setFontName(this->fontName_);369 text->setCharHeight(text->getCharHeight() * yScale);370 371 objectStruct tempStruct = {panel, text, true};372 activeObjectList_[object] = tempStruct;373 374 this->background_->addChild(panel);375 this->background_->addChild(text);376 377 // background_->addChild(activeObjectList_[object].first);378 // background_->addChild(activeObjectList_[object].second);379 380 }381 382 void HUDNavigation::removeObject(RadarViewable* viewable)383 {384 activeObjectListType::iterator it = activeObjectList_.find(viewable);385 386 if (activeObjectList_.find(viewable) != activeObjectList_.end())387 {388 // Remove overlays from Ogre389 this->background_->removeChild(it->second.panel_->getName());390 this->background_->removeChild(it->second.text_->getName());391 // correctly destroy the overlay elements392 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);393 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);394 395 activeObjectList_.erase(viewable);396 }397 398 }399 400 void HUDNavigation::changedOwner()401 {402 respawnObjectSetType respawnObjectSet = this->getOwner()->getScene()->getRadar()->getRadarObjects();403 respawnObjectSetType::iterator respawnObjectSetIt_;404 for (respawnObjectSetIt_ = respawnObjectSet.begin(); respawnObjectSetIt_ != respawnObjectSet.end(); ++respawnObjectSetIt_)405 {406 if (!(*respawnObjectSetIt_)->isHumanShip_)407 this->addObject(*respawnObjectSetIt_);408 }409 410 }411 412 413 414 // void updateActiveObjectList(map activeObjectList_){}415 //416 // void HUDNavigation::objectChanged(RadarViewable* viewable){}417 //418 //419 // float HUDNavigation::getRadarSensitivity(){}420 // void HUDNavigation::radarTick(float dt){}421 422 423 }424 425 -
code/branches/hudelements/src/modules/overlays/hud/HUDNavigation.h
r6917 r6924 30 30 #define _HUDNavigation_H__ 31 31 32 #include <utility> 32 #include "overlays/OverlaysPrereqs.h" 33 33 34 #include <map> 34 #include "overlays/OverlaysPrereqs.h" 35 #include "interfaces/RadarViewable.h" 35 #include <string> 36 36 37 #include "interfaces/RadarListener.h"38 37 #include "util/OgreForwardRefs.h" 39 38 #include "tools/interfaces/Tickable.h" 39 #include "interfaces/RadarListener.h" 40 40 #include "overlays/OrxonoxOverlay.h" 41 42 #include <vector>43 41 44 42 namespace orxonox 45 43 { 46 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener47 {48 public:49 HUDNavigation(BaseObject* creator);50 virtual ~HUDNavigation();44 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener 45 { 46 public: 47 HUDNavigation(BaseObject* creator); 48 virtual ~HUDNavigation(); 51 49 52 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 53 virtual void tick(float dt); 54 virtual void addObject(RadarViewable* object); 50 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 51 virtual void tick(float dt); 55 52 56 virtual void removeObject(RadarViewable* viewable); 57 virtual void objectChanged(RadarViewable* viewable) {} 58 inline float getRadarSensitivity() const {return 1.0f;} 59 inline void radarTick(float dt) {} 60 virtual void changedOwner(); 53 virtual void addObject(RadarViewable* object); 54 virtual void removeObject(RadarViewable* viewable); 55 virtual void objectChanged(RadarViewable* viewable) {} 61 56 57 virtual void changedOwner(); 58 virtual void sizeChanged(); 59 virtual void angleChanged() { } 60 virtual void positionChanged() { } 61 virtual void radarTick(float dt) {} 62 62 63 private: 63 inline float getRadarSensitivity() const 64 { return 1.0f; } 64 65 66 private: 67 struct ObjectInfo 68 { 69 Ogre::PanelOverlayElement* panel_; 70 Ogre::TextAreaOverlayElement* text_; 71 bool outOfView_; 72 bool wasOutOfView_; 73 }; 65 74 75 // XMLPort accessors 76 void setNavMarkerSize(float size) 77 { navMarkerSize_ = size; this->sizeChanged(); } 78 float getNavMarkerSize() const 79 { return navMarkerSize_; } 66 80 67 void sizeChanged(); 68 void angleChanged() { } 69 void positionChanged() { } 81 void setTextSize(float size); 82 float getTextSize() const; 70 83 71 // void updateActiveObjectList(map activeObjectList_); 84 void setFont(const std::string& font); 85 const std::string& getFont() const; 72 86 87 typedef std::map<RadarViewable*, ObjectInfo > ObjectMap; 88 ObjectMap activeObjectList_; 73 89 74 75 // XMLPort accessors 76 void setNavMarkerSize(float size) { 77 navMarkerSize_ = size; 78 this->sizeChanged(); 79 } 80 float getNavMarkerSize() const { 81 return navMarkerSize_; 82 } 83 84 /* 85 void setAimMarkerSize(float size) { this->aimMarkerSize_ = size; this->sizeChanged(); } 86 float getAimMarkerSize() const { return this->aimMarkerSize_; } 87 */ 88 89 void setTextSize(float size); 90 float getTextSize() const; 91 92 void setFont(const std::string& font); 93 const std::string& getFont() const; 94 95 void updateMarker(); 96 void updateFocus(); 97 // float getDist2Focus() const; 98 void getSingleton(); 99 100 101 void updateActiveObjectMap(); 102 103 Ogre::PanelOverlayElement* navMarker_; //!< the panel used to show the arrow and the target marker 104 float navMarkerSize_; //!< One paramter size of the navigation marker 105 /* 106 Ogre::PanelOverlayElement* aimMarker_; //!< Panel used to show the aim Marker 107 float aimMarkerSize_; //!< One paramter size of the aim marker 108 */ 109 Ogre::TextAreaOverlayElement* navText_; //!< Text overlay to display the target distance 110 111 112 struct objectStruct{ 113 114 Ogre::PanelOverlayElement* panel_; 115 Ogre::TextAreaOverlayElement* text_; 116 bool outOfView_; 117 bool wasOutOfView_; 118 90 float navMarkerSize_; 91 std::string fontName_; 92 float textSize_; 119 93 }; 120 121 typedef std::map<RadarViewable*, objectStruct > activeObjectListType;122 activeObjectListType activeObjectList_;123 activeObjectListType::iterator tempRadarViewable;124 125 typedef std::set<RadarViewable*> respawnObjectSetType;126 127 128 129 std::string fontName_;130 float textSize_;131 132 };133 134 94 } 135 95
Note: See TracChangeset
for help on using the changeset viewer.