Changeset 9280 for code/branches/presentation2012merge
- Timestamp:
- Jun 5, 2012, 10:29:17 PM (13 years ago)
- Location:
- code/branches/presentation2012merge/src/modules/overlays/hud
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.cc
r9279 r9280 55 55 namespace orxonox 56 56 { 57 bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b ) 58 { 59 return a.second<b.second; 60 61 } 62 63 void HUDNavigation::setConfigValues() 64 { 65 SetConfigValue(markerLimit_, 3); 66 SetConfigValue(showDistance, false); 67 } 68 69 CreateFactory ( HUDNavigation ); 70 71 HUDNavigation::HUDNavigation ( BaseObject* creator ) 72 : OrxonoxOverlay ( creator ) 73 { 74 RegisterObject ( HUDNavigation ); 75 this->setConfigValues(); 76 77 // Set default values 78 this->setFont ( "Monofur" ); 79 this->setTextSize ( 0.05f ); 80 this->setNavMarkerSize ( 0.05f ); 81 this->setDetectionLimit( 10000.0f ); 82 } 83 84 HUDNavigation::~HUDNavigation() 85 { 86 if ( this->isInitialized() ) 87 { 88 for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ) 89 removeObject ( ( it++ )->first ); 90 91 } 92 93 sortedObjectList_.clear(); 94 } 95 96 void HUDNavigation::XMLPort ( Element& xmlelement, XMLPort::Mode mode ) 97 { 98 SUPER ( HUDNavigation, XMLPort, xmlelement, mode ); 99 100 XMLPortParam ( HUDNavigation, "font", setFont, getFont, xmlelement, mode ); 101 XMLPortParam ( HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode ); 102 XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode ); 103 XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode ); 104 } 105 106 void HUDNavigation::setFont ( const std::string& font ) 107 { 108 const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName ( font ); 109 if ( fontPtr.isNull() ) 110 { 111 orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl; 112 return; 113 } 114 fontName_ = font; 115 for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it ) 116 { 117 if ( it->second.text_ != NULL ) 118 it->second.text_->setFontName ( fontName_ ); 119 } 120 } 121 122 const std::string& HUDNavigation::getFont() const 123 { 124 return fontName_; 125 } 126 127 void HUDNavigation::setTextSize ( float size ) 128 { 129 if ( size <= 0.0f ) 130 { 131 orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl; 132 return; 133 } 134 textSize_ = size; 135 for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it ) 136 { 137 if ( it->second.text_ ) 138 it->second.text_->setCharHeight ( size ); 139 } 140 } 141 142 float HUDNavigation::getTextSize() const 143 { 144 return textSize_; 145 } 146 147 float HUDNavigation::getArrowSizeX(int dist) 148 { 149 if (dist < 600) 150 dist = 600; 151 return this->getActualSize().x * 900 * navMarkerSize_ / dist; 152 } 153 154 float HUDNavigation::getArrowSizeY(int dist) 155 { 156 if (dist < 600) 157 dist = 600; 158 return this->getActualSize().y * 900 * navMarkerSize_ / dist; 159 } 160 161 void HUDNavigation::tick ( float dt ) 162 { 163 SUPER ( HUDNavigation, tick, dt ); 164 165 Camera* cam = CameraManager::getInstance().getActiveCamera(); 166 if ( cam == NULL ) 167 return; 168 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 169 170 171 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt ) 172 { 173 listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f ); 174 } 175 176 sortedObjectList_.sort ( compareDistance ); 177 178 unsigned int markerCount_ = 0; 179 bool closeEnough_ = false; //only display objects that are close enough to be relevant for the player 180 181 // for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it) 182 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt ) 183 { 184 ObjectMap::iterator it = activeObjectList_.find ( listIt->first ); 185 closeEnough_ = listIt->second < detectionLimit_ ; 186 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 187 if ( markerCount_ < markerLimit_ && (closeEnough_ || detectionLimit_ < 0) ) 188 { 189 190 191 // Get Distance to HumanController and save it in the TextAreaOverlayElement. 192 int dist = listIt->second; 193 float textLength = 0.0f; 194 195 //display distance next to cursor 196 if (showDistance){ 197 it->second.text_->setCaption ( multi_cast<std::string> ( dist ) ); 198 textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f; 199 } 200 201 //display name next to cursor 202 else{ 203 it->second.text_->setCaption(it->first->getRadarName()); 204 textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f; 205 } 206 207 // Transform to screen coordinates 208 Vector3 pos = camTransform * it->first->getRVWorldPosition(); 209 210 bool outOfView = true; 211 if ( pos.z > 1.0 ) 57 bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b) 58 { 59 return a.second < b.second; 60 } 61 62 CreateFactory ( HUDNavigation ); 63 64 HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator) 65 { 66 RegisterObject(HUDNavigation); 67 this->setConfigValues(); 68 69 // Set default values 70 this->setFont("Monofur"); 71 this->setTextSize(0.05f); 72 this->setNavMarkerSize(0.05f); 73 this->setDetectionLimit(10000.0f); 74 } 75 76 HUDNavigation::~HUDNavigation() 77 { 78 if (this->isInitialized()) 79 { 80 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();) 81 removeObject((it++)->first); 82 } 83 this->sortedObjectList_.clear(); 84 } 85 86 void HUDNavigation::setConfigValues() 87 { 88 SetConfigValue(markerLimit_, 3); 89 SetConfigValue(showDistance_, false); 90 } 91 92 void HUDNavigation::XMLPort(Element& xmlelement, XMLPort::Mode mode) 93 { 94 SUPER(HUDNavigation, XMLPort, xmlelement, mode); 95 96 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode); 97 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode); 98 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode); 99 XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode); 100 } 101 102 void HUDNavigation::setFont(const std::string& font) 103 { 104 const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); 105 if (fontPtr.isNull()) 106 { 107 orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl; 108 return; 109 } 110 this->fontName_ = font; 111 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it) 112 { 113 if (it->second.text_ != NULL) 114 it->second.text_->setFontName(this->fontName_); 115 } 116 } 117 118 const std::string& HUDNavigation::getFont() const 119 { 120 return this->fontName_; 121 } 122 123 void HUDNavigation::setTextSize(float size) 124 { 125 if (size <= 0.0f) 126 { 127 orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl; 128 return; 129 } 130 this->textSize_ = size; 131 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it!=this->activeObjectList_.end(); ++it) 132 { 133 if (it->second.text_) 134 it->second.text_->setCharHeight(size); 135 } 136 } 137 138 float HUDNavigation::getTextSize() const 139 { 140 return this->textSize_; 141 } 142 143 float HUDNavigation::getArrowSizeX(int dist) const 144 { 145 if (dist < 600) 146 dist = 600; 147 return this->getActualSize().x * 900 * this->navMarkerSize_ / dist; 148 } 149 150 float HUDNavigation::getArrowSizeY(int dist) const 151 { 152 if (dist < 600) 153 dist = 600; 154 return this->getActualSize().y * 900 * this->navMarkerSize_ / dist; 155 } 156 157 void HUDNavigation::tick(float dt) 158 { 159 SUPER(HUDNavigation, tick, dt); 160 161 Camera* cam = CameraManager::getInstance().getActiveCamera(); 162 if (cam == NULL) 163 return; 164 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 165 166 167 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 168 listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f); 169 170 this->sortedObjectList_.sort(compareDistance); 171 172 unsigned int markerCount = 0; 173 bool closeEnough = false; // only display objects that are close enough to be relevant for the player 174 175 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) 176 { 177 std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first); 178 closeEnough = listIt->second < this->detectionLimit_; 179 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 180 if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0)) 212 181 { 213 // z > 1.0 means that the object is behind the camera 214 outOfView = true; 215 // we have to switch all coordinates (if you don't know why, 216 // try linear algebra lectures, because I can't explain..) 217 pos.x = -pos.x; 218 pos.y = -pos.y; 219 } 220 else 221 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 222 223 if ( outOfView ) 224 { 225 // Object is not in view 226 227 // Change material only if outOfView changed 228 if ( !it->second.wasOutOfView_ ) 182 // Get Distance to HumanController and save it in the TextAreaOverlayElement. 183 int dist = listIt->second; 184 float textLength = 0.0f; 185 186 if (this->showDistance_) 229 187 { 230 it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "arrows.png", it->first->getRadarObjectColour()) ); 231 it->second.wasOutOfView_ = true; 188 //display distance next to cursor 189 it->second.text_->setCaption(multi_cast<std::string>(dist)); 190 textLength = multi_cast<std::string>(dist).size() * it->second.text_->getCharHeight() * 0.3f; 232 191 } 233 234 //float xDistScale = this->getActualSize().x * 1000.0f * navMarkerSize_ / dist; 235 //float yDistScale = this->getActualSize().y * 1000.0f * navMarkerSize_ / dist; 236 237 // Adjust Arrowsize according to distance 238 it->second.panel_->setDimensions(getArrowSizeX(dist),getArrowSizeY(dist)); 239 240 // Switch between top, bottom, left and right position of the arrow at the screen border 241 if ( pos.x < pos.y ) 192 else 242 193 { 243 if ( pos.y > -pos.x ) 194 //display name next to cursor 195 it->second.text_->setCaption(it->first->getRadarName()); 196 textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f; 197 } 198 199 // Transform to screen coordinates 200 Vector3 pos = camTransform * it->first->getRVWorldPosition(); 201 202 bool outOfView = true; 203 if (pos.z > 1.0) 204 { 205 // z > 1.0 means that the object is behind the camera 206 outOfView = true; 207 // we have to switch all coordinates (if you don't know why, 208 // try linear algebra lectures, because I can't explain..) 209 pos.x = -pos.x; 210 pos.y = -pos.y; 211 } 212 else 213 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 214 215 if (outOfView) 216 { 217 // Object is not in view 218 219 // Change material only if outOfView changed 220 if (!it->second.wasOutOfView_) 244 221 { 245 // Top 246 float position = pos.x / pos.y + 1.0f; 247 it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 0.0f ); 248 it->second.panel_->setUV ( 0.5f, 0.0f, 1.0f, 0.5f ); 249 it->second.text_->setLeft ( ( position - textLength ) * 0.5f ); 250 it->second.text_->setTop ( it->second.panel_->getHeight() ); 222 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 223 it->second.wasOutOfView_ = true; 224 } 225 226 //float xDistScale = this->getActualSize().x * 1000.0f * this->navMarkerSize_ / dist; 227 //float yDistScale = this->getActualSize().y * 1000.0f * this->navMarkerSize_ / dist; 228 229 // Adjust Arrowsize according to distance 230 it->second.panel_->setDimensions(getArrowSizeX(dist), getArrowSizeY(dist)); 231 232 // Switch between top, bottom, left and right position of the arrow at the screen border 233 if (pos.x < pos.y) 234 { 235 if (pos.y > -pos.x) 236 { 237 // Top 238 float position = pos.x / pos.y + 1.0f; 239 it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 0.0f); 240 it->second.panel_->setUV(0.5f, 0.0f, 1.0f, 0.5f); 241 it->second.text_->setLeft((position - textLength) * 0.5f); 242 it->second.text_->setTop(it->second.panel_->getHeight()); 243 } 244 else 245 { 246 // Left 247 float position = pos.y / pos.x + 1.0f; 248 it->second.panel_->setPosition(0.0f, (position - it->second.panel_->getWidth()) * 0.5f); 249 it->second.panel_->setUV(0.0f, 0.0f, 0.5f, 0.5f); 250 it->second.text_->setLeft(it->second.panel_->getWidth() + 0.01f); 251 it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f); 252 } 251 253 } 252 254 else 253 255 { 254 // Left 255 float position = pos.y / pos.x + 1.0f; 256 it->second.panel_->setPosition ( 0.0f, ( position - it->second.panel_->getWidth() ) * 0.5f ); 257 it->second.panel_->setUV ( 0.0f, 0.0f, 0.5f, 0.5f ); 258 it->second.text_->setLeft ( it->second.panel_->getWidth() + 0.01f ); 259 it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f ); 256 if (pos.y < -pos.x) 257 { 258 // Bottom 259 float position = -pos.x / pos.y + 1.0f; 260 it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 1.0f - it->second.panel_->getHeight()); 261 it->second.panel_->setUV(0.0f, 0.5f, 0.5f, 1.0f ); 262 it->second.text_->setLeft((position - textLength) * 0.5f); 263 it->second.text_->setTop(1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight()); 264 } 265 else 266 { 267 // Right 268 float position = -pos.y / pos.x + 1.0f; 269 it->second.panel_->setPosition(1.0f - it->second.panel_->getWidth(), (position - it->second.panel_->getHeight()) * 0.5f); 270 it->second.panel_->setUV(0.5f, 0.5f, 1.0f, 1.0f); 271 it->second.text_->setLeft(1.0f - it->second.panel_->getWidth() - textLength - 0.01f); 272 it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f); 273 } 260 274 } 261 275 } 262 263 276 else 264 277 { 265 266 if ( pos.y < -pos.x ) 278 // Object is in view 279 280 // Change material only if outOfView changed 281 if (it->second.wasOutOfView_) 267 282 { 268 // Bottom 269 float position = -pos.x / pos.y + 1.0f; 270 it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 1.0f - it->second.panel_->getHeight() ); 271 it->second.panel_->setUV ( 0.0f, 0.5f, 0.5f, 1.0f ); 272 it->second.text_->setLeft ( ( position - textLength ) * 0.5f ); 273 it->second.text_->setTop ( 1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight() ); 283 //it->second.panel_->setMaterialName("Orxonox/NavTDC"); 284 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 285 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 286 it->second.wasOutOfView_ = false; 274 287 } 275 else 276 {277 // Right278 float position = -pos.y / pos.x + 1.0f;279 it->second.panel_->setPosition ( 1.0f - it->second.panel_->getWidth(), ( position - it->second.panel_->getHeight() ) * 0.5f);280 it->second.panel_->setUV ( 0.5f, 0.5f, 1.0f, 1.0f ); 281 it->second.text_->setLeft ( 1.0f - it->second.panel_->getWidth() - textLength - 0.01f );282 it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f);283 }288 289 // Position marker 290 it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 291 it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f); 292 it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f); 293 294 // Position text 295 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); 296 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 284 297 } 298 299 // Make sure the overlays are shown 300 it->second.panel_->show(); 301 it->second.text_->show(); 285 302 } 286 else 303 else // do not display on HUD 287 304 { 288 // Object is in view 289 290 // Change material only if outOfView changed 291 if ( it->second.wasOutOfView_ ) 292 { 293 //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" ); 294 it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", it->first->getRadarObjectColour()) ); 295 it->second.panel_->setDimensions ( navMarkerSize_ * this->getActualSize().x, navMarkerSize_ * this->getActualSize().y ); 296 it->second.wasOutOfView_ = false; 297 } 298 299 // Position marker 300 it->second.panel_->setUV ( 0.0f, 0.0f, 1.0f, 1.0f ); 301 it->second.panel_->setLeft ( ( pos.x + 1.0f - it->second.panel_->getWidth() ) * 0.5f ); 302 it->second.panel_->setTop ( ( -pos.y + 1.0f - it->second.panel_->getHeight() ) * 0.5f ); 303 304 // Position text 305 it->second.text_->setLeft ( ( pos.x + 1.0f + it->second.panel_->getWidth() ) * 0.5f ); 306 it->second.text_->setTop ( ( -pos.y + 1.0f + it->second.panel_->getHeight() ) * 0.5f ); 305 it->second.panel_->hide(); 306 it->second.text_->hide(); 307 307 } 308 309 // Make sure the overlays are shown 310 it->second.panel_->show(); 311 it->second.text_->show(); 312 } 313 else // do not display on HUD 314 { 315 it->second.panel_->hide(); 316 it->second.text_->hide(); 317 } 318 308 } 309 } 310 311 /** Overridden method of OrxonoxOverlay. 312 @details 313 Usually the entire overlay scales with scale(). 314 Here we obviously have to adjust this. 315 */ 316 void HUDNavigation::sizeChanged() 317 { 318 // Use size to compensate for aspect ratio if enabled. 319 float xScale = this->getActualSize().x; 320 float yScale = this->getActualSize().y; 321 322 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it) 323 { 324 if (it->second.panel_ != NULL) 325 it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale); 326 if (it->second.text_ != NULL) 327 it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale); 328 } 329 } 330 331 void HUDNavigation::addObject(RadarViewable* object) 332 { 333 if (showObject(object) == false) 334 return; 335 336 if (this->activeObjectList_.size() >= this->markerLimit_) 337 if (object == NULL) 338 return; 339 340 // Object hasn't been added yet (we know that) 341 assert(this->activeObjectList_.find(object) == this->activeObjectList_.end()); 342 343 // Scales used for dimensions and text size 344 float xScale = this->getActualSize().x; 345 float yScale = this->getActualSize().y; 346 347 // Create everything needed to display the object on the radar and add it to the map 348 349 // Create arrow/marker 350 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton() 351 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 352 //panel->setMaterialName("Orxonox/NavTDC"); 353 panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour())); 354 panel->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale); 355 //panel->setColour(object->getRadarObjectColour()); 356 357 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() 358 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 359 text->setFontName(this->fontName_); 360 text->setCharHeight(text->getCharHeight() * yScale); 361 text->setColour(object->getRadarObjectColour()); 362 363 panel->hide(); 364 text->hide(); 365 366 ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */}; 367 this->activeObjectList_[object] = tempStruct; 368 369 this->background_->addChild(panel); 370 this->background_->addChild(text); 371 372 this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0)); 373 } 374 375 void HUDNavigation::removeObject(RadarViewable* viewable) 376 { 377 std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(viewable); 378 379 if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end()) 380 { 381 // Detach overlays 382 this->background_->removeChild(it->second.panel_->getName()); 383 this->background_->removeChild(it->second.text_->getName()); 384 // Properly destroy the overlay elements (do not use delete!) 385 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 386 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 387 // Remove from the list 388 this->activeObjectList_.erase(viewable); 389 } 390 391 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 392 { 393 if ((listIt->first) == viewable) 394 { 395 this->sortedObjectList_.erase(listIt); 396 break; 397 } 398 } 399 } 400 401 void HUDNavigation::objectChanged(RadarViewable* viewable) 402 { 403 // TODO: niceification neccessary ;) 404 removeObject(viewable); 405 addObject(viewable); 406 } 407 408 bool HUDNavigation::showObject(RadarViewable* rv) 409 { 410 if (rv == orxonox_cast<RadarViewable*>(this->getOwner())) 411 return false; 412 assert(rv->getWorldEntity()); 413 if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false) 414 return false; 415 return true; 416 } 417 418 void HUDNavigation::changedOwner() 419 { 420 const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects(); 421 for (std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it) 422 { 423 if (!(*it)->isHumanShip_) 424 this->addObject(*it); 425 } 319 426 } 320 427 } 321 322 323 /** Overridden method of OrxonoxOverlay.324 @details325 Usually the entire overlay scales with scale().326 Here we obviously have to adjust this.327 */328 void HUDNavigation::sizeChanged()329 {330 // Use size to compensate for aspect ratio if enabled.331 float xScale = this->getActualSize().x;332 float yScale = this->getActualSize().y;333 334 for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )335 {336 if ( it->second.panel_ != NULL )337 it->second.panel_->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );338 if ( it->second.text_ != NULL )339 it->second.text_->setCharHeight ( it->second.text_->getCharHeight() * yScale );340 }341 }342 343 void HUDNavigation::addObject ( RadarViewable* object )344 {345 if( showObject(object)==false )346 return;347 348 if ( activeObjectList_.size() >= markerLimit_ )349 if ( object == NULL )350 return;351 352 // Object hasn't been added yet (we know that)353 assert ( this->activeObjectList_.find ( object ) == this->activeObjectList_.end() );354 355 // Scales used for dimensions and text size356 float xScale = this->getActualSize().x;357 float yScale = this->getActualSize().y;358 359 // Create everything needed to display the object on the radar and add it to the map360 361 // Create arrow/marker362 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*> ( Ogre::OverlayManager::getSingleton()363 .createOverlayElement ( "Panel", "HUDNavigation_navMarker_" + getUniqueNumberString() ) );364 // panel->setMaterialName ( "Orxonox/NavTDC" );365 panel->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", object->getRadarObjectColour()) );366 panel->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );367 // panel->setColour( object->getRadarObjectColour() );368 369 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*> ( Ogre::OverlayManager::getSingleton()370 .createOverlayElement ( "TextArea", "HUDNavigation_navText_" + getUniqueNumberString() ) );371 text->setFontName ( this->fontName_ );372 text->setCharHeight ( text->getCharHeight() * yScale );373 text->setColour( object->getRadarObjectColour() );374 375 panel->hide();376 text->hide();377 378 ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};379 activeObjectList_[object] = tempStruct;380 381 this->background_->addChild ( panel );382 this->background_->addChild ( text );383 384 sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) );385 386 387 }388 389 void HUDNavigation::removeObject ( RadarViewable* viewable )390 {391 ObjectMap::iterator it = activeObjectList_.find ( viewable );392 393 if ( activeObjectList_.find ( viewable ) != activeObjectList_.end() )394 {395 // Detach overlays396 this->background_->removeChild ( it->second.panel_->getName() );397 this->background_->removeChild ( it->second.text_->getName() );398 // Properly destroy the overlay elements (do not use delete!)399 Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.panel_ );400 Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.text_ );401 // Remove from the list402 activeObjectList_.erase ( viewable );403 404 405 }406 407 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )408 {409 if ( (listIt->first) == viewable )410 {411 sortedObjectList_.erase ( listIt );412 break;413 }414 415 }416 417 }418 419 void HUDNavigation::objectChanged(RadarViewable* viewable)420 {421 // TODO: niceification neccessary ;)422 removeObject(viewable);423 addObject(viewable);424 }425 426 427 bool HUDNavigation::showObject(RadarViewable* rv)428 {429 if ( rv == orxonox_cast<RadarViewable*> ( this->getOwner() ) )430 return false;431 assert( rv->getWorldEntity() );432 if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )433 return false;434 return true;435 }436 437 void HUDNavigation::changedOwner()438 {439 440 const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();441 for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it )442 {443 if ( ! ( *it )->isHumanShip_ )444 this->addObject ( *it );445 }446 }447 448 } -
code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.h
r9016 r9280 36 36 #include <string> 37 37 38 39 38 #include "util/OgreForwardRefs.h" 40 39 #include "tools/interfaces/Tickable.h" … … 44 43 namespace orxonox 45 44 { 46 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener47 {48 public:49 HUDNavigation ( BaseObject* creator);50 virtual ~HUDNavigation();45 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener 46 { 47 public: 48 HUDNavigation(BaseObject* creator); 49 virtual ~HUDNavigation(); 51 50 52 void setConfigValues();51 void setConfigValues(); 53 52 54 virtual void XMLPort ( Element& xmlelement, XMLPort::Mode mode);55 virtual void tick ( float dt);53 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 54 virtual void tick(float dt); 56 55 57 // RadarListener interface58 virtual void addObject ( RadarViewable* object);59 virtual void removeObject ( RadarViewable* viewable);60 virtual void objectChanged ( RadarViewable* viewable);56 // RadarListener interface 57 virtual void addObject(RadarViewable* object); 58 virtual void removeObject(RadarViewable* viewable); 59 virtual void objectChanged(RadarViewable* viewable); 61 60 62 virtual void changedOwner();63 virtual void sizeChanged();64 virtual void angleChanged() { }65 virtual void positionChanged() { }66 virtual void radarTick ( float dt) {}61 virtual void changedOwner(); 62 virtual void sizeChanged(); 63 virtual void angleChanged() { } 64 virtual void positionChanged() { } 65 virtual void radarTick(float dt) {} 67 66 68 inline float getRadarSensitivity() const69 { return 1.0f; }67 inline float getRadarSensitivity() const 68 { return 1.0f; } 70 69 71 unsigned int getMarkerLimit() { return this->markerLimit_; } 70 inline unsigned int getMarkerLimit() const 71 { return this->markerLimit_; } 72 72 73 private: 74 struct ObjectInfo 75 { 76 Ogre::PanelOverlayElement* panel_; 77 Ogre::TextAreaOverlayElement* text_; 78 bool outOfView_; 79 bool wasOutOfView_; 73 private: 74 struct ObjectInfo 75 { 76 Ogre::PanelOverlayElement* panel_; 77 Ogre::TextAreaOverlayElement* text_; 78 bool outOfView_; 79 bool wasOutOfView_; 80 }; 80 81 82 bool showObject(RadarViewable* rv); 83 84 // XMLPort accessors 85 inline void setNavMarkerSize(float size) 86 { 87 navMarkerSize_ = size; 88 this->sizeChanged(); 89 } 90 inline float getNavMarkerSize() const 91 { return navMarkerSize_; } 92 inline void setDetectionLimit(float limit) 93 { this->detectionLimit_ = limit; } 94 inline float getDetectionLimit() const 95 { return this->detectionLimit_; } 96 97 void setTextSize(float size); 98 float getTextSize() const; 99 100 void setFont(const std::string& font); 101 const std::string& getFont() const; 102 103 float getArrowSizeX(int dist) const; 104 float getArrowSizeY(int dist) const; 105 106 std::map<RadarViewable*, ObjectInfo> activeObjectList_; 107 std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_; 108 109 float navMarkerSize_; 110 std::string fontName_; 111 float textSize_; 112 bool showDistance_; 113 114 unsigned int markerLimit_; 115 float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value. 81 116 }; 82 83 bool showObject( RadarViewable* rv );84 85 // XMLPort accessors86 void setNavMarkerSize ( float size )87 { navMarkerSize_ = size; this->sizeChanged(); }88 float getNavMarkerSize() const89 { return navMarkerSize_; }90 void setDetectionLimit( float limit )91 { this->detectionLimit_ = limit; }92 float getDetectionLimit() const93 { return this->detectionLimit_; }94 95 void setTextSize ( float size );96 float getTextSize() const;97 98 void setFont ( const std::string& font );99 const std::string& getFont() const;100 101 typedef std::map<RadarViewable*, ObjectInfo > ObjectMap;102 ObjectMap activeObjectList_;103 104 typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList;105 sortedList sortedObjectList_;106 107 float getArrowSizeX(int dist);108 float getArrowSizeY(int dist);109 110 float navMarkerSize_;111 std::string fontName_;112 float textSize_;113 bool showDistance;114 115 unsigned int markerLimit_;116 float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.117 118 };119 117 } 120 118
Note: See TracChangeset
for help on using the changeset viewer.