Changeset 7163 for code/trunk/src/modules/overlays/hud
- Timestamp:
- Aug 11, 2010, 8:55:13 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 8 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/overlays/hud/CMakeLists.txt
r5781 r7163 13 13 UnderAttackHealthBar.cc 14 14 TeamBaseMatchScore.cc 15 GametypeStaticMessage.cc 16 GametypeFadingMessage.cc 15 17 ) -
code/trunk/src/modules/overlays/hud/GametypeStatus.cc
r5781 r7163 30 30 31 31 #include "util/Convert.h" 32 #include "core/ConsoleCommand.h" 32 33 #include "core/CoreIncludes.h" 33 34 #include "infos/GametypeInfo.h" … … 39 40 { 40 41 CreateFactory(GametypeStatus); 42 43 /*static*/ bool GametypeStatus::noCaption_s = false; 44 SetConsoleCommand(GametypeStatus, setGametypeStatus, true); 41 45 42 46 GametypeStatus::GametypeStatus(BaseObject* creator) : OverlayText(creator) … … 59 63 const GametypeInfo* gtinfo = this->owner_->getGametypeInfo(); 60 64 ControllableEntity* ce = this->owner_->getControllableEntity(); 65 66 if(GametypeStatus::noCaption_s) // No captions are displayed. 67 { 68 this->setCaption(""); 69 return; 70 } 61 71 62 72 if (!gtinfo->hasStarted() && !gtinfo->isStartCountdownRunning()) … … 88 98 this->owner_ = orxonox_cast<PlayerInfo*>(this->getOwner()); 89 99 } 100 101 /** 102 @brief 103 Sets whether the gametype status is displayed. 104 @param bValue 105 If true captions are displayed, if false, not. 106 */ 107 /*static*/ void GametypeStatus::setGametypeStatus(bool bValue) 108 { 109 GametypeStatus::noCaption_s = !bValue; 110 } 111 90 112 } -
code/trunk/src/modules/overlays/hud/GametypeStatus.h
r5781 r7163 46 46 virtual void changedOwner(); 47 47 48 static void setGametypeStatus(bool bValue); //!< Toggles whether the gametype status is displayed. 49 48 50 private: 49 51 PlayerInfo* owner_; 52 static bool noCaption_s; 53 50 54 }; 51 55 } -
code/trunk/src/modules/overlays/hud/HUDNavigation.cc
r6502 r7163 29 29 #include "HUDNavigation.h" 30 30 31 #include <string>32 31 #include <OgreCamera.h> 32 #include <OgreFontManager.h> 33 33 #include <OgreOverlayManager.h> 34 34 #include <OgreTextAreaOverlayElement.h> … … 45 45 #include "controllers/HumanController.h" 46 46 #include "worldentities/pawns/Pawn.h" 47 #include "worldentities/WorldEntity.h" 48 #include "core/ConfigValueIncludes.h" 49 #include "tools/TextureGenerator.h" 50 // #include <boost/bind/bind_template.hpp> 51 47 52 48 53 namespace orxonox 49 54 { 50 CreateFactory(HUDNavigation); 51 52 HUDNavigation::HUDNavigation(BaseObject* creator) 53 : OrxonoxOverlay(creator) 54 { 55 RegisterObject(HUDNavigation); 56 57 // create nav text 58 navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 59 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 60 61 // create nav marker 62 navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 63 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 64 navMarker_->setMaterialName("Orxonox/NavArrows"); 65 66 /* 67 // create aim marker 68 aimMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 69 .createOverlayElement("Panel", "HUDNavigation_aimMarker_" + getUniqueNumberString())); 70 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 71 this->wasOutOfView_ = true; // Ensure the material is changed right the first time.. 72 73 setFont("Monofur"); 74 setTextSize(0.05f); 75 setNavMarkerSize(0.05f); 76 setAimMarkerSize(0.04f); 77 */ 78 79 background_->addChild(navMarker_); 80 // background_->addChild(aimMarker_); 81 background_->addChild(navText_); 82 83 // hide at first 84 this->setVisible(false); 85 } 86 87 HUDNavigation::~HUDNavigation() 88 { 89 if (this->isInitialized()) 55 bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b ) 56 { 57 return a.second<b.second; 58 59 } 60 61 void HUDNavigation::setConfigValues() 62 { 63 SetConfigValue(markerLimit_, 3); 64 } 65 66 CreateFactory ( HUDNavigation ); 67 68 HUDNavigation::HUDNavigation ( BaseObject* creator ) 69 : OrxonoxOverlay ( creator ) 70 { 71 RegisterObject ( HUDNavigation ); 72 this->setConfigValues(); 73 74 // Set default values 75 setFont ( "Monofur" ); 76 setTextSize ( 0.05f ); 77 setNavMarkerSize ( 0.05f ); 78 } 79 80 HUDNavigation::~HUDNavigation() 81 { 82 if ( this->isInitialized() ) 83 { 84 for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ) 85 removeObject ( ( it++ )->first ); 86 87 } 88 89 sortedObjectList_.clear(); 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 } 100 101 void HUDNavigation::setFont ( const std::string& font ) 102 { 103 const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName ( font ); 104 if ( fontPtr.isNull() ) 105 { 106 COUT ( 2 ) << "Warning: HUDNavigation: Font '" << font << "' not found" << std::endl; 107 return; 108 } 109 fontName_ = font; 110 for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it ) 111 { 112 if ( it->second.text_ != NULL ) 113 it->second.text_->setFontName ( fontName_ ); 114 } 115 } 116 117 const std::string& HUDNavigation::getFont() const 118 { 119 return fontName_; 120 } 121 122 void HUDNavigation::setTextSize ( float size ) 123 { 124 if ( size <= 0.0f ) 125 { 126 COUT ( 2 ) << "Warning: HUDNavigation: Negative font size not allowed" << std::endl; 127 return; 128 } 129 textSize_ = size; 130 for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it ) 131 { 132 if ( it->second.text_ ) 133 it->second.text_->setCharHeight ( size ); 134 } 135 } 136 137 float HUDNavigation::getTextSize() const 138 { 139 return textSize_; 140 } 141 142 143 144 void HUDNavigation::tick ( float dt ) 145 { 146 SUPER ( HUDNavigation, tick, dt ); 147 148 Camera* cam = CameraManager::getInstance().getActiveCamera(); 149 if ( cam == NULL ) 150 return; 151 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 152 153 154 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt ) 155 { 156 listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f ); 157 } 158 159 sortedObjectList_.sort ( compareDistance ); 160 161 unsigned int markerCount_ = 0; 162 163 // for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it) 164 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt ) 165 { 166 ObjectMap::iterator it = activeObjectList_.find ( listIt->first ); 167 168 if ( markerCount_ < markerLimit_ ) 90 169 { 91 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_); 92 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->navText_); 93 // Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 94 } 95 } 96 97 void HUDNavigation::XMLPort(Element& xmlElement, XMLPort::Mode mode) 98 { 99 SUPER(HUDNavigation, XMLPort, xmlElement, mode); 100 101 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlElement, mode); 102 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlElement, mode); 103 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 104 // XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 105 } 106 107 void HUDNavigation::setFont(const std::string& font) 108 { 109 if (this->navText_ && !font.empty()) 110 this->navText_->setFontName(font); 111 } 112 113 const std::string& HUDNavigation::getFont() const 114 { 115 if (this->navText_) 116 return this->navText_->getFontName(); 117 else 118 return BLANKSTRING; 119 } 120 121 void HUDNavigation::setTextSize(float size) 122 { 123 if (this->navText_ && size >= 0.0f) 124 this->navText_->setCharHeight(size); 125 } 126 127 float HUDNavigation::getTextSize() const 128 { 129 if (this->navText_) 130 return this->navText_->getCharHeight(); 131 else 132 return 0.0f; 133 } 134 135 void HUDNavigation::tick(float dt) 136 { 137 SUPER(HUDNavigation, tick, dt); 138 139 // Get radar 140 Radar* radar = this->getOwner()->getScene()->getRadar(); 141 142 if (!radar->getFocus()) 143 { 144 this->overlay_->hide(); 145 return; 146 } 147 else 148 { 149 this->overlay_->show(); 150 } 151 152 // set text 153 int dist = static_cast<int>(getDist2Focus()); 154 navText_->setCaption(multi_cast<std::string>(dist)); 155 float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f; 156 157 orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera(); 158 if (!cam) 159 return; 160 const Matrix4& transform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 161 // transform to screen coordinates 162 Vector3 pos = transform * radar->getFocus()->getRVWorldPosition(); 163 164 bool outOfView; 165 if (pos.z > 1.0) 166 { 167 // z > 1.0 means that the object is behind the camera 168 outOfView = true; 169 // we have to switch all coordinates (if you don't know why, 170 // try linear algebra lectures, because I can't explain..) 171 pos.x = -pos.x; 172 pos.y = -pos.y; 173 } 174 else 175 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 176 177 if (outOfView) 178 { 179 // object is not in view 180 // aimMarker_->hide(); 181 182 if (!wasOutOfView_) 170 171 172 // Get Distance to HumanController and save it in the TextAreaOverlayElement. 173 int dist = listIt->second; 174 it->second.text_->setCaption ( multi_cast<std::string> ( dist ) ); 175 float textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f; 176 177 // Transform to screen coordinates 178 Vector3 pos = camTransform * it->first->getRVWorldPosition(); 179 180 bool outOfView = true; 181 if ( pos.z > 1.0 ) 183 182 { 184 navMarker_->setMaterialName("Orxonox/NavArrows"); 185 wasOutOfView_ = true; 183 // z > 1.0 means that the object is behind the camera 184 outOfView = true; 185 // we have to switch all coordinates (if you don't know why, 186 // try linear algebra lectures, because I can't explain..) 187 pos.x = -pos.x; 188 pos.y = -pos.y; 186 189 } 187 188 if (pos.x < pos.y) 190 else 191 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 192 // Get Distance to HumanController and save it in the TextAreaOverlayElement. 193 it->second.text_->setCaption ( multi_cast<std::string> ( dist ) ); 194 195 if ( outOfView ) 189 196 { 190 if (pos.y > -pos.x) 197 // Object is not in view 198 199 // Change material only if outOfView changed 200 if ( !it->second.wasOutOfView_ ) 191 201 { 192 // up 193 float position = pos.x / pos.y + 1.0f; 194 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 0.0f); 195 navMarker_->setUV(0.5f, 0.0f, 1.0f, 0.5f); 196 navText_->setLeft((position - textLength) * 0.5f); 197 navText_->setTop(navMarker_->getHeight()); 202 it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "arrows.tga", it->first->getRadarObjectColour()) ); 203 it->second.wasOutOfView_ = true; 198 204 } 205 206 // Switch between top, bottom, left and right position of the arrow at the screen border 207 if ( pos.x < pos.y ) 208 { 209 if ( pos.y > -pos.x ) 210 { 211 // Top 212 float position = pos.x / pos.y + 1.0f; 213 it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 0.0f ); 214 it->second.panel_->setUV ( 0.5f, 0.0f, 1.0f, 0.5f ); 215 it->second.text_->setLeft ( ( position - textLength ) * 0.5f ); 216 it->second.text_->setTop ( it->second.panel_->getHeight() ); 217 } 218 else 219 { 220 // Left 221 float position = pos.y / pos.x + 1.0f; 222 it->second.panel_->setPosition ( 0.0f, ( position - it->second.panel_->getWidth() ) * 0.5f ); 223 it->second.panel_->setUV ( 0.0f, 0.0f, 0.5f, 0.5f ); 224 it->second.text_->setLeft ( it->second.panel_->getWidth() + 0.01f ); 225 it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f ); 226 } 227 } 228 199 229 else 200 230 { 201 // left 202 float position = pos.y / pos.x + 1.0f; 203 navMarker_->setPosition(0.0f, (position - navMarker_->getWidth()) * 0.5f); 204 navMarker_->setUV(0.0f, 0.0f, 0.5f, 0.5f); 205 navText_->setLeft(navMarker_->getWidth() + 0.01f); 206 navText_->setTop((position - navText_->getCharHeight()) * 0.5f); 231 232 if ( pos.y < -pos.x ) 233 { 234 // Bottom 235 float position = -pos.x / pos.y + 1.0f; 236 it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 1.0f - it->second.panel_->getHeight() ); 237 it->second.panel_->setUV ( 0.0f, 0.5f, 0.5f, 1.0f ); 238 it->second.text_->setLeft ( ( position - textLength ) * 0.5f ); 239 it->second.text_->setTop ( 1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight() ); 240 } 241 else 242 { 243 // Right 244 float position = -pos.y / pos.x + 1.0f; 245 it->second.panel_->setPosition ( 1.0f - it->second.panel_->getWidth(), ( position - it->second.panel_->getHeight() ) * 0.5f ); 246 it->second.panel_->setUV ( 0.5f, 0.5f, 1.0f, 1.0f ); 247 it->second.text_->setLeft ( 1.0f - it->second.panel_->getWidth() - textLength - 0.01f ); 248 it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f ); 249 } 207 250 } 208 251 } 209 252 else 210 253 { 211 if (pos.y < -pos.x) 254 // Object is in view 255 256 // Change material only if outOfView changed 257 if ( it->second.wasOutOfView_ ) 212 258 { 213 // down 214 float position = -pos.x / pos.y + 1.0f; 215 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight()); 216 navMarker_->setUV(0.0f, 0.5f, 0.5f, 1.0f); 217 navText_->setLeft((position - textLength) * 0.5f); 218 navText_->setTop(1.0f - navMarker_->getHeight() - navText_->getCharHeight()); 259 //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" ); 260 it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.tga", it->first->getRadarObjectColour()) ); 261 it->second.wasOutOfView_ = false; 219 262 } 220 else 221 {222 // right223 float position = -pos.y / pos.x + 1.0f;224 navMarker_->setPosition(1.0f - navMarker_->getWidth(), (position - navMarker_->getHeight()) * 0.5f);225 navMarker_->setUV(0.5f, 0.5f, 1.0f, 1.0f); 226 navText_->setLeft(1.0f - navMarker_->getWidth() - textLength - 0.01f);227 navText_->setTop((position - navText_->getCharHeight()) * 0.5f);228 }263 264 // Position marker 265 it->second.panel_->setUV ( 0.0f, 0.0f, 1.0f, 1.0f ); 266 it->second.panel_->setLeft ( ( pos.x + 1.0f - it->second.panel_->getWidth() ) * 0.5f ); 267 it->second.panel_->setTop ( ( -pos.y + 1.0f - it->second.panel_->getHeight() ) * 0.5f ); 268 269 // Position text 270 it->second.text_->setLeft ( ( pos.x + 1.0f + it->second.panel_->getWidth() ) * 0.5f ); 271 it->second.text_->setTop ( ( -pos.y + 1.0f + it->second.panel_->getHeight() ) * 0.5f ); 229 272 } 273 274 // Make sure the overlays are shown 275 it->second.panel_->show(); 276 it->second.text_->show(); 230 277 } 231 278 else 232 279 { 233 // object is in view 234 /* 235 Vector3 aimpos = transform * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 236 Projectile::getSpeed(), Radar::getInstance().getFocus()->getRVWorldPosition(), Radar::getInstance().getFocus()->getRVOrientedVelocity()); 280 it->second.panel_->hide(); 281 it->second.text_->hide(); 282 } 283 284 } 285 } 286 287 288 /** Overridden method of OrxonoxOverlay. 289 @details 290 Usually the entire overlay scales with scale(). 291 Here we obviously have to adjust this. 237 292 */ 238 if (wasOutOfView_) 239 { 240 navMarker_->setMaterialName("Orxonox/NavTDC"); 241 wasOutOfView_ = false; 242 } 243 244 // object is in view 245 navMarker_->setUV(0.0f, 0.0f, 1.0f, 1.0f); 246 navMarker_->setLeft((pos.x + 1.0f - navMarker_->getWidth()) * 0.5f); 247 navMarker_->setTop((-pos.y + 1.0f - navMarker_->getHeight()) * 0.5f); 248 249 /* 250 aimMarker_->show(); 251 aimMarker_->setLeft((aimpos.x + 1.0f - aimMarker_->getWidth()) * 0.5f); 252 aimMarker_->setTop((-aimpos.y + 1.0f - aimMarker_->getHeight()) * 0.5f); 253 */ 254 navText_->setLeft((pos.x + 1.0f + navMarker_->getWidth()) * 0.5f); 255 navText_->setTop((-pos.y + 1.0f + navMarker_->getHeight()) * 0.5f); 293 void HUDNavigation::sizeChanged() 294 { 295 // Use size to compensate for aspect ratio if enabled. 296 float xScale = this->getActualSize().x; 297 float yScale = this->getActualSize().y; 298 299 for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it ) 300 { 301 if ( it->second.panel_ != NULL ) 302 it->second.panel_->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale ); 303 if ( it->second.text_ != NULL ) 304 it->second.text_->setCharHeight ( it->second.text_->getCharHeight() * yScale ); 305 } 306 } 307 308 void HUDNavigation::addObject ( RadarViewable* object ) 309 { 310 if( showObject(object)==false ) 311 return; 312 313 if ( activeObjectList_.size() >= markerLimit_ ) 314 if ( object == NULL ) 315 return; 316 317 // Object hasn't been added yet (we know that) 318 assert ( this->activeObjectList_.find ( object ) == this->activeObjectList_.end() ); 319 320 // Scales used for dimensions and text size 321 float xScale = this->getActualSize().x; 322 float yScale = this->getActualSize().y; 323 324 // Create everything needed to display the object on the radar and add it to the map 325 326 // Create arrow/marker 327 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*> ( Ogre::OverlayManager::getSingleton() 328 .createOverlayElement ( "Panel", "HUDNavigation_navMarker_" + getUniqueNumberString() ) ); 329 // panel->setMaterialName ( "Orxonox/NavTDC" ); 330 panel->setMaterialName( TextureGenerator::getMaterialName( "tdc.tga", object->getRadarObjectColour()) ); 331 panel->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale ); 332 // panel->setColour( object->getRadarObjectColour() ); 333 334 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*> ( Ogre::OverlayManager::getSingleton() 335 .createOverlayElement ( "TextArea", "HUDNavigation_navText_" + getUniqueNumberString() ) ); 336 text->setFontName ( this->fontName_ ); 337 text->setCharHeight ( text->getCharHeight() * yScale ); 338 text->setColour( object->getRadarObjectColour() ); 339 340 panel->hide(); 341 text->hide(); 342 343 ObjectInfo tempStruct = {panel, text, false}; 344 activeObjectList_[object] = tempStruct; 345 346 this->background_->addChild ( panel ); 347 this->background_->addChild ( text ); 348 349 sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) ); 350 351 352 } 353 354 void HUDNavigation::removeObject ( RadarViewable* viewable ) 355 { 356 ObjectMap::iterator it = activeObjectList_.find ( viewable ); 357 358 if ( activeObjectList_.find ( viewable ) != activeObjectList_.end() ) 359 { 360 // Detach overlays 361 this->background_->removeChild ( it->second.panel_->getName() ); 362 this->background_->removeChild ( it->second.text_->getName() ); 363 // Properly destroy the overlay elements (do not use delete!) 364 Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.panel_ ); 365 Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.text_ ); 366 // Remove from the list 367 activeObjectList_.erase ( viewable ); 368 369 370 } 371 372 for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt ) 373 { 374 if ( (listIt->first) == viewable ) 375 { 376 sortedObjectList_.erase ( listIt ); 377 break; 256 378 } 257 } 258 259 float HUDNavigation::getDist2Focus() const 260 { 261 Radar* radar = this->getOwner()->getScene()->getRadar(); 262 if (radar->getFocus() && HumanController::getLocalControllerEntityAsPawn()) 263 return (radar->getFocus()->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length(); 264 else 265 return 0; 266 } 267 268 /** 269 @brief Overridden method of OrxonoxOverlay. Usually the entire overlay 270 scales with scale(). Here we obviously have to adjust this. 271 */ 272 void HUDNavigation::sizeChanged() 273 { 274 // use size to compensate for aspect ratio if enabled. 275 float xScale = this->getActualSize().x; 276 float yScale = this->getActualSize().y; 277 if (this->navMarker_) 278 navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); 279 /* 280 if (this->aimMarker_) 281 aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale); 282 */ 283 if (this->navText_) 284 navText_->setCharHeight(navText_->getCharHeight() * yScale); 285 } 286 } 379 380 } 381 382 } 383 384 void HUDNavigation::objectChanged(RadarViewable* viewable) 385 { 386 // TODO: niceification neccessary ;) 387 removeObject(viewable); 388 addObject(viewable); 389 } 390 391 392 bool HUDNavigation::showObject(RadarViewable* rv) 393 { 394 if ( rv == dynamic_cast<RadarViewable*> ( this->getOwner() ) ) 395 return false; 396 assert( rv->getWorldEntity() ); 397 if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false ) 398 return false; 399 return true; 400 } 401 402 void HUDNavigation::changedOwner() 403 { 404 405 const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects(); 406 for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it ) 407 { 408 if ( ! ( *it )->isHumanShip_ ) 409 this->addObject ( *it ); 410 } 411 } 412 } -
code/trunk/src/modules/overlays/hud/HUDNavigation.h
r6417 r7163 32 32 #include "overlays/OverlaysPrereqs.h" 33 33 34 #include <map> 35 #include <string> 36 37 34 38 #include "util/OgreForwardRefs.h" 35 39 #include "tools/interfaces/Tickable.h" 40 #include "interfaces/RadarListener.h" 36 41 #include "overlays/OrxonoxOverlay.h" 37 42 38 43 namespace orxonox 39 44 { 40 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable 45 class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener 46 { 47 public: 48 HUDNavigation ( BaseObject* creator ); 49 virtual ~HUDNavigation(); 50 51 void setConfigValues(); 52 53 virtual void XMLPort ( Element& xmlElement, XMLPort::Mode mode ); 54 virtual void tick ( float dt ); 55 56 virtual void addObject ( RadarViewable* object ); 57 virtual void removeObject ( RadarViewable* viewable ); 58 virtual void objectChanged ( RadarViewable* viewable ); 59 60 virtual void changedOwner(); 61 virtual void sizeChanged(); 62 virtual void angleChanged() { } 63 virtual void positionChanged() { } 64 virtual void radarTick ( float dt ) {} 65 66 inline float getRadarSensitivity() const 67 { return 1.0f; } 68 69 private: 70 struct ObjectInfo 41 71 { 42 public: 43 HUDNavigation(BaseObject* creator); 44 virtual ~HUDNavigation(); 72 Ogre::PanelOverlayElement* panel_; 73 Ogre::TextAreaOverlayElement* text_; 74 bool outOfView_; 75 bool wasOutOfView_; 45 76 46 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 47 virtual void tick(float dt); 77 }; 48 78 49 private: 50 void sizeChanged(); 51 void angleChanged() { } 52 void positionChanged() { } 79 bool showObject( RadarViewable* rv ); 53 80 54 // XMLPort accessors 55 void setNavMarkerSize(float size) { this->navMarkerSize_ = size; this->sizeChanged(); } 56 float getNavMarkerSize() const { return this->navMarkerSize_; } 81 // XMLPort accessors 82 void setNavMarkerSize ( float size ) 83 { navMarkerSize_ = size; this->sizeChanged(); } 84 float getNavMarkerSize() const 85 { return navMarkerSize_; } 57 86 58 /* 59 void setAimMarkerSize(float size) { this->aimMarkerSize_ = size; this->sizeChanged(); } 60 float getAimMarkerSize() const { return this->aimMarkerSize_; } 61 */ 87 void setTextSize ( float size ); 88 float getTextSize() const; 62 89 63 void setTextSize(float size);64 float getTextSize() const;90 void setFont ( const std::string& font ); 91 const std::string& getFont() const; 65 92 66 void setFont(const std::string& font);67 const std::string& getFont() const;93 typedef std::map<RadarViewable*, ObjectInfo > ObjectMap; 94 ObjectMap activeObjectList_; 68 95 69 void updateMarker(); 70 void updateFocus(); 71 float getDist2Focus() const; 96 typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList; 97 sortedList sortedObjectList_; 72 98 73 Ogre::PanelOverlayElement* navMarker_; //!< the panel used to show the arrow and the target marker 74 float navMarkerSize_; //!< One paramter size of the navigation marker75 /* 76 Ogre::PanelOverlayElement* aimMarker_; //!< Panel used to show the aim Marker77 float aimMarkerSize_; //!< One paramter size of the aim marker 78 */ 79 Ogre::TextAreaOverlayElement* navText_; //!< Text overlay to display the target distance 80 bool wasOutOfView_; //!< Performance booster variable: setMaterial is not cheap 81 99 100 float navMarkerSize_; 101 std::string fontName_; 102 float textSize_; 103 104 unsigned int markerLimit_;; //TODO: is it possible to set this over the console and/or the IG-Setting 105 106 107 }; 82 108 } 83 109 -
code/trunk/src/modules/overlays/hud/HUDRadar.cc
r6502 r7163 40 40 #include "worldentities/WorldEntity.h" 41 41 #include "worldentities/pawns/Pawn.h" 42 #include "Scene.h" 43 #include "Radar.h" 42 44 43 45 namespace orxonox … … 72 74 { 73 75 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->marker_); 74 for (std:: vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin();75 it != this->radar Dots_.end(); ++it)76 for (std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it = this->radarObjects_.begin(); 77 it != this->radarObjects_.end(); ++it) 76 78 { 77 Ogre::OverlayManager::getSingleton().destroyOverlayElement( *it);79 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second); 78 80 } 79 81 } … … 89 91 } 90 92 91 void HUDRadar:: displayObject(RadarViewable* object, bool bIsMarked)93 void HUDRadar::addObject(RadarViewable* object) 92 94 { 93 if (object == static_cast<RadarViewable*>(this->owner_))95 if (object == dynamic_cast<RadarViewable*>(this->owner_)) 94 96 return; 95 97 96 const WorldEntity* wePointer = object->getWorldEntity(); 98 // Make sure the object hasn't been added yet 99 assert( this->radarObjects_.find(object) == this->radarObjects_.end() ); 97 100 98 // Just to be sure that we actually have a WorldEntity. 99 // We could do a dynamic_cast, but that would be a lot slower. 100 if (!wePointer || !this->owner_) 101 // Create everything needed to display the object on the radar and add it to the map 102 Ogre::PanelOverlayElement* panel; 103 panel = static_cast<Ogre::PanelOverlayElement*>( 104 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 105 this->overlay_->add2D(panel); 106 // get right material 107 panel->setMaterialName(TextureGenerator::getMaterialName( 108 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 109 this->radarObjects_[object] = panel; 110 } 111 112 void HUDRadar::removeObject(RadarViewable* object) 113 { 114 // If object was added at all then remove it 115 std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it; 116 it = this->radarObjects_.find( object ); 117 if( it != this->radarObjects_.end() ) 101 118 { 102 if (!wePointer) 103 CCOUT(2) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 104 if (!this->owner_) 105 CCOUT(2) << "No owner defined" << std::endl; 119 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second); 120 this->radarObjects_.erase(it); 121 } 122 } 123 124 void HUDRadar::objectChanged( RadarViewable* rv ) 125 { 126 if (rv == dynamic_cast<RadarViewable*>(this->owner_)) 106 127 return; 107 } 128 assert( this->radarObjects_.find(rv) != this->radarObjects_.end() ); 129 Ogre::PanelOverlayElement* panel = this->radarObjects_[rv]; 130 panel->setMaterialName(TextureGenerator::getMaterialName( 131 shapeMaterials_[rv->getRadarObjectShape()], rv->getRadarObjectColour())); 132 } 108 133 109 // try to find a panel already created 110 Ogre::PanelOverlayElement* panel; 111 //std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object); 112 if (itRadarDots_ == this->radarDots_.end()) 113 { 114 // we have to create a new entry 115 panel = static_cast<Ogre::PanelOverlayElement*>( 116 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 117 radarDots_.push_back(panel); 118 // get right material 119 panel->setMaterialName(TextureGenerator::getMaterialName( 120 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 121 this->overlay_->add2D(panel); 122 this->itRadarDots_ = this->radarDots_.end(); 123 } 124 else 125 { 126 panel = *itRadarDots_; 127 ++itRadarDots_; 128 const std::string& materialName = TextureGenerator::getMaterialName( 129 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()); 130 if (materialName != panel->getMaterialName()) 131 panel->setMaterialName(materialName); 132 } 133 panel->show(); 134 135 // set size to fit distance... 136 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 137 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 138 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); 139 panel->setDimensions(size, size); 140 141 // calc position on radar... 142 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 143 coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture 144 panel->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f); 145 146 if (bIsMarked) 147 { 148 this->marker_->show(); 149 this->marker_->setDimensions(size * 1.5f, size * 1.5f); 150 this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f); 151 } 134 void HUDRadar::gatherObjects() 135 { 136 const std::set<RadarViewable*>& objectSet = this->getCreator()->getScene()->getRadar()->getRadarObjects(); 137 std::set<RadarViewable*>::const_iterator it; 138 for( it=objectSet.begin(); it!=objectSet.end(); ++it ) 139 this->addObject(*it); 152 140 } 153 141 154 142 void HUDRadar::radarTick(float dt) 155 143 { 156 for (itRadarDots_ = radarDots_.begin(); itRadarDots_ != radarDots_.end(); ++itRadarDots_) 157 (*itRadarDots_)->hide(); 158 this->itRadarDots_ = this->radarDots_.begin(); 159 this->marker_->hide(); 144 // Make sure the owner of the radar was defined 145 if( !this->owner_ ) 146 { 147 CCOUT(0) << "No owner defined" << std::endl; 148 assert(0); 149 } 150 151 this->marker_->hide(); // in case that no object is in focus 152 // get the focus object 153 Radar* radar = this->getOwner()->getScene()->getRadar(); 154 const RadarViewable* focusObject = radar->getFocus(); 155 156 // update the distances for all objects 157 std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it; 158 for( it = this->radarObjects_.begin(); it != this->radarObjects_.end(); ++it ) 159 { 160 // Make sure the object really is a WorldEntity 161 const WorldEntity* wePointer = it->first->getWorldEntity(); 162 if( !wePointer ) 163 { 164 CCOUT(0) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 165 assert(0); 166 } 167 bool isFocus = (it->first == focusObject); 168 // set size to fit distance... 169 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 170 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 171 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); 172 it->second->setDimensions(size, size); 173 174 // calc position on radar... 175 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 176 coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture 177 it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f); 178 it->second->show(); 179 180 // if this object is in focus, then set the focus marker 181 if (isFocus) 182 { 183 this->marker_->setDimensions(size * 1.5f, size * 1.5f); 184 this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f); 185 this->marker_->show(); 186 } 187 } 160 188 } 161 189 162 190 void HUDRadar::changedOwner() 163 191 { 164 192 SUPER(HUDRadar, changedOwner); 165 193 166 this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); 167 } 194 this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); 195 assert(this->radarObjects_.size()==0); 196 this->gatherObjects(); 168 197 } 198 } -
code/trunk/src/modules/overlays/hud/HUDRadar.h
r5781 r7163 65 65 66 66 // RadarListener interface 67 void displayObject(RadarViewable* viewable, bool bIsMarked); 67 virtual void addObject(RadarViewable* viewable); 68 virtual void removeObject(RadarViewable* viewable); 69 virtual void objectChanged( RadarViewable* rv ); 68 70 void radarTick(float dt); 71 72 void gatherObjects(); 69 73 70 74 std::map<RadarViewable::Shape, std::string> shapeMaterials_; 71 75 72 std::vector<Ogre::PanelOverlayElement*> radarDots_; 73 std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_; 76 // std::vector<Ogre::PanelOverlayElement*> radarDots_; 77 // std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_; 78 std::map<RadarViewable*, Ogre::PanelOverlayElement*> radarObjects_; 74 79 Ogre::PanelOverlayElement* marker_; 75 80
Note: See TracChangeset
for help on using the changeset viewer.