Changeset 6865 for code/branches/hudelements/src/modules/overlays/hud
- Timestamp:
- May 10, 2010, 11:02:12 AM (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
r6849 r6865 28 28 29 29 #include "HUDNavigation.h" 30 #include <utility> 30 31 31 32 #include <string> … … 54 55 { 55 56 RegisterObject(HUDNavigation); 56 57 // create nav text58 navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()59 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));60 61 // create nav marker62 navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()63 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));64 navMarker_->setMaterialName("Orxonox/NavArrows");57 58 // // create nav text 59 // navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 60 // .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 61 // 62 // // create nav marker 63 // navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 64 // .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 65 // navMarker_->setMaterialName("Orxonox/NavArrows"); 65 66 66 67 /* … … 76 77 setAimMarkerSize(0.04f); 77 78 */ 78 79 background_->addChild(navMarker_); 79 /* 80 background_->addChild(navMarker_);*/ 80 81 // background_->addChild(aimMarker_); 81 background_->addChild(navText_);82 // background_->addChild(navText_); 82 83 83 84 // hide at first 84 this->setVisible(false);85 // this->setVisible(false); 85 86 86 87 … … 138 139 { 139 140 SUPER(HUDNavigation, tick, dt); 141 142 // updateActiveObjectList(activeObjectList_); 140 143 141 144 // Get radar 142 Radar* radar = this->getOwner()->getScene()->getRadar();143 144 if (!radar->getFocus())145 {146 this->overlay_->hide();147 return;148 }149 else150 {151 this->overlay_->show();152 }145 // Radar* radar = this->getOwner()->getScene()->getRadar(); 146 // 147 // if (!radar->getFocus()) 148 // { 149 // this->overlay_->hide(); 150 // return; 151 // } 152 // else 153 // { 154 // this->overlay_->show(); 155 // } 153 156 154 157 // set text 155 int dist = static_cast<int>(getDist2Focus()); 156 navText_->setCaption(multi_cast<std::string>(dist)); 157 float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f; 158 159 orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera(); 158 // int dist = static_cast<int>(getDist2Focus()); 159 // navText_->setCaption(multi_cast<std::string>(dist)); 160 // float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f; 161 162 if(!activeObjectList_.empty()) { 163 for(tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable) 164 { 165 166 //get Distance to HumanController and save it in the TextAreaOverlayElement. 167 int dist = (int)(tempRadarViewable->first->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length(); 168 tempRadarViewable->second.second->setCaption(multi_cast<std::string>(dist)); 169 float textLength = multi_cast<std::string>(dist).size() * tempRadarViewable->second.second->getCharHeight() * 0.3f; 170 171 orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera(); 160 172 if (!cam) 161 173 return; 162 174 const Matrix4& transform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 163 175 // transform to screen coordinates 164 Vector3 pos = transform * radar->getFocus()->getRVWorldPosition();176 Vector3 pos = transform * tempRadarViewable->first->getRVWorldPosition(); 165 177 166 178 bool outOfView; … … 184 196 if (!wasOutOfView_) 185 197 { 186 navMarker_->setMaterialName("Orxonox/NavArrows");198 tempRadarViewable->second.first->setMaterialName("Orxonox/NavArrows"); 187 199 wasOutOfView_ = true; 188 200 } … … 194 206 // up 195 207 float position = pos.x / pos.y + 1.0f; 196 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 0.0f);197 navMarker_->setUV(0.5f, 0.0f, 1.0f, 0.5f);198 navText_->setLeft((position - textLength) * 0.5f);199 navText_->setTop(navMarker_->getHeight());208 tempRadarViewable->second.first->setPosition((position - tempRadarViewable->second.first->getWidth()) * 0.5f, 0.0f); 209 tempRadarViewable->second.first->setUV(0.5f, 0.0f, 1.0f, 0.5f); 210 tempRadarViewable->second.second->setLeft((position - textLength) * 0.5f); 211 tempRadarViewable->second.second->setTop(tempRadarViewable->second.first->getHeight()); 200 212 } 201 213 else … … 203 215 // left 204 216 float position = pos.y / pos.x + 1.0f; 205 navMarker_->setPosition(0.0f, (position - navMarker_->getWidth()) * 0.5f);206 navMarker_->setUV(0.0f, 0.0f, 0.5f, 0.5f);207 navText_->setLeft(navMarker_->getWidth() + 0.01f);208 navText_->setTop((position - navText_->getCharHeight()) * 0.5f);217 tempRadarViewable->second.first->setPosition(0.0f, (position - tempRadarViewable->second.first->getWidth()) * 0.5f); 218 tempRadarViewable->second.first->setUV(0.0f, 0.0f, 0.5f, 0.5f); 219 tempRadarViewable->second.second->setLeft(tempRadarViewable->second.first->getWidth() + 0.01f); 220 tempRadarViewable->second.second->setTop((position - tempRadarViewable->second.second->getCharHeight()) * 0.5f); 209 221 } 210 222 } … … 215 227 // down 216 228 float position = -pos.x / pos.y + 1.0f; 217 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight());218 navMarker_->setUV(0.0f, 0.5f, 0.5f, 1.0f);219 navText_->setLeft((position - textLength) * 0.5f);220 navText_->setTop(1.0f - navMarker_->getHeight() - navText_->getCharHeight());229 tempRadarViewable->second.first->setPosition((position - tempRadarViewable->second.first->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight()); 230 tempRadarViewable->second.first->setUV(0.0f, 0.5f, 0.5f, 1.0f); 231 tempRadarViewable->second.second->setLeft((position - textLength) * 0.5f); 232 tempRadarViewable->second.second->setTop(1.0f - tempRadarViewable->second.first->getHeight() - tempRadarViewable->second.second->getCharHeight()); 221 233 } 222 234 else … … 224 236 // right 225 237 float position = -pos.y / pos.x + 1.0f; 226 navMarker_->setPosition(1.0f - navMarker_->getWidth(), (position - navMarker_->getHeight()) * 0.5f);227 navMarker_->setUV(0.5f, 0.5f, 1.0f, 1.0f);228 navText_->setLeft(1.0f - navMarker_->getWidth() - textLength - 0.01f);229 navText_->setTop((position - navText_->getCharHeight()) * 0.5f);238 tempRadarViewable->second.first->setPosition(1.0f - tempRadarViewable->second.first->getWidth(), (position - tempRadarViewable->second.first->getHeight()) * 0.5f); 239 tempRadarViewable->second.first->setUV(0.5f, 0.5f, 1.0f, 1.0f); 240 tempRadarViewable->second.second->setLeft(1.0f - tempRadarViewable->second.first->getWidth() - textLength - 0.01f); 241 tempRadarViewable->second.second->setTop((position - tempRadarViewable->second.second->getCharHeight()) * 0.5f); 230 242 } 231 243 } … … 233 245 else 234 246 { 247 248 235 249 // object is in view 236 250 /* … … 240 254 if (wasOutOfView_) 241 255 { 242 navMarker_->setMaterialName("Orxonox/NavTDC");256 tempRadarViewable->second.first->setMaterialName("Orxonox/NavTDC"); 243 257 wasOutOfView_ = false; 244 258 } 245 259 246 260 // object is in view 247 navMarker_->setUV(0.0f, 0.0f, 1.0f, 1.0f);248 navMarker_->setLeft((pos.x + 1.0f - navMarker_->getWidth()) * 0.5f);249 navMarker_->setTop((-pos.y + 1.0f - navMarker_->getHeight()) * 0.5f);261 tempRadarViewable->second.first->setUV(0.0f, 0.0f, 1.0f, 1.0f); 262 tempRadarViewable->second.first->setLeft((pos.x + 1.0f - tempRadarViewable->second.first->getWidth()) * 0.5f); 263 tempRadarViewable->second.first->setTop((-pos.y + 1.0f - tempRadarViewable->second.first->getHeight()) * 0.5f); 250 264 251 265 /* … … 254 268 aimMarker_->setTop((-aimpos.y + 1.0f - aimMarker_->getHeight()) * 0.5f); 255 269 */ 256 navText_->setLeft((pos.x + 1.0f + navMarker_->getWidth()) * 0.5f);257 navText_->setTop((-pos.y + 1.0f + navMarker_->getHeight()) * 0.5f);270 tempRadarViewable->second.second->setLeft((pos.x + 1.0f + tempRadarViewable->second.first->getWidth()) * 0.5f); 271 tempRadarViewable->second.second->setTop((-pos.y + 1.0f + tempRadarViewable->second.first->getHeight()) * 0.5f); 258 272 } 259 } 260 261 float HUDNavigation::getDist2Focus() const 262 { 273 } 274 } 275 } 276 277 278 float HUDNavigation::getDist2Focus() const{ 279 263 280 Radar* radar = this->getOwner()->getScene()->getRadar(); 264 281 if (radar->getFocus() && HumanController::getLocalControllerEntityAsPawn()) … … 272 289 scales with scale(). Here we obviously have to adjust this. 273 290 */ 274 void HUDNavigation::sizeChanged() 275 { 276 // use size to compensate for aspect ratio if enabled. 291 void HUDNavigation::sizeChanged(){ 292 // use size to compensate for aspect ratio if enabled. 277 293 float xScale = this->getActualSize().x; 278 294 float yScale = this->getActualSize().y; 279 295 if (this->navMarker_) 280 296 navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); 281 /* 282 if (this->aimMarker_) 283 aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale); 284 */ 297 // if (this->aimMarker_) 298 // aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale); 285 299 if (this->navText_) 286 300 navText_->setCharHeight(navText_->getCharHeight() * yScale); 287 301 } 288 302 289 void HUDNavigation::addObject(RadarViewable* object)290 {291 if (object == dynamic_cast<RadarViewable*>(this->getOwner()))303 304 void HUDNavigation::addObject(RadarViewable* object){ 305 if (object == dynamic_cast<RadarViewable*>(this->getOwner())) 292 306 return; 293 307 294 308 assert(object); 295 309 … … 307 321 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton() 308 322 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 323 324 int dist = (int)(object->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length(); 325 activeObjectList_[object].second->setCaption(multi_cast<std::string>(dist)); 309 326 310 327 activeObjectList_[object] = std::make_pair (panel, text) ; 311 328 activeObjectList_[object].first->show(); 312 329 activeObjectList_[object].second->show(); 313 } 314 315 void HUDNavigation::removeObject(RadarViewable* viewable){ 316 assert(activeObjectList_.find(viewable)!=activeObjectList_.end()); 330 // background_->addChild(activeObjectList_[object].first); 331 // background_->addChild(activeObjectList_[object].second); 332 } 333 334 void HUDNavigation::removeObject(RadarViewable* viewable){ 335 assert(activeObjectList_.find(viewable)!=activeObjectList_.end()); 317 336 activeObjectList_.erase(viewable); 318 } 337 } 338 339 // void updateActiveObjectList(map activeObjectList_){} 340 // 341 // void HUDNavigation::objectChanged(RadarViewable* viewable){} 342 // 319 343 // 320 // void HUDNavigation::objectChanged(RadarViewable* viewable){}321 344 // float HUDNavigation::getRadarSensitivity(){} 322 345 // void HUDNavigation::radarTick(float dt){} 323 // 324 346 325 347 326 348 } 349 350 -
code/branches/hudelements/src/modules/overlays/hud/HUDNavigation.h
r6849 r6865 39 39 #include "overlays/OrxonoxOverlay.h" 40 40 41 #include <pair>42 41 #include <vector> 43 42 … … 65 64 void positionChanged() { } 66 65 66 // void updateActiveObjectList(map activeObjectList_); 67 67 68 68 69 … … 86 87 float getDist2Focus() const; 87 88 void getSingleton(); 88 void getSingleton(); 89 89 90 90 91 void updateActiveObjectMap(); … … 99 100 bool wasOutOfView_; //!< Performance booster variable: setMaterial is not cheap 100 101 101 std::map<RadarViewable*, std::pair<Ogre::PanelOverlayElement*, Ogre::TextAreaOverlayElement*> > activeObjectList_; 102 typedef std::map<RadarViewable*, std::pair<Ogre::PanelOverlayElement*, Ogre::TextAreaOverlayElement*> > activeObjectListType; 103 activeObjectListType activeObjectList_; 104 activeObjectListType::iterator tempRadarViewable; 102 105 103 106 };
Note: See TracChangeset
for help on using the changeset viewer.