Changeset 1580 for code/trunk
- Timestamp:
- Jun 9, 2008, 11:05:18 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/hud
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/HUD.cc
r1575 r1580 247 247 if ((*it)->getObject() == object) 248 248 { 249 if (this->nav_) 250 if (this->nav_->getFocus() == (*it)) 251 this->nav_->releaseFocus(); 249 if (this->nav_ && this->nav_->getFocus() == (*it)) 250 this->nav_->releaseFocus(); 252 251 253 252 delete (*it); -
code/trunk/src/orxonox/hud/Navigation.cc
r1568 r1580 48 48 using namespace Ogre; 49 49 50 Navigation::Navigation(OverlayContainer* container){ 50 Navigation::Navigation(OverlayContainer* container) 51 { 51 52 container_ = container; 52 53 focus_ = NULL; … … 54 55 } 55 56 56 Navigation::Navigation(OverlayContainer* container, RadarObject* focus){57 container_ = container;58 focus_ = focus;59 init();60 }61 62 57 Navigation::~Navigation() 63 58 { … … 67 62 } 68 63 69 void Navigation::init(){ 64 void Navigation::init() 65 { 70 66 // create nav text 71 67 navText_ = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("TextArea", "navText")); … … 95 91 } 96 92 97 void Navigation::update(){ 93 void Navigation::update() 94 { 98 95 if (!focus_) 99 96 return; … … 102 99 } 103 100 104 void Navigation::updateMarker(){ 101 void Navigation::updateMarker() 102 { 105 103 int windowW = GraphicsEngine::getSingleton().getWindowWidth(); 106 104 int windowH = GraphicsEngine::getSingleton().getWindowHeight(); … … 134 132 bool isAbove = currentOrth.dotProduct(focus_->getPosition() - navCamPos)>0; 135 133 bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1); 134 136 135 // if object is behind us, it is out of view anyway: 137 if(!outOfView && radius > Ogre::Math::PI / 2) outOfView = true; 138 139 if(outOfView){ 136 if (!outOfView && radius > Ogre::Math::PI / 2) 137 outOfView = true; 138 139 if (outOfView) 140 { 140 141 // object is not in view 141 142 navMarker_->setMaterialName("Orxonox/NavArrows"); … … 147 148 float phiNav = atan((float) xFromCenter / (float) yFromCenter); 148 149 149 if(isAbove && isRight){ 150 if (isAbove && isRight) 151 { 150 152 // top right quadrant 151 if(-phiNav<phiUpperCorner){ 153 if (-phiNav < phiUpperCorner) 154 { 152 155 //COUT(3) << "arrow up\n"; 153 156 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); … … 156 159 navText_->setTop(navMarker_->getHeight()); 157 160 } 158 else { 161 else 162 { 159 163 //COUT(3) << "arrow right\n"; 160 164 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); … … 164 168 } 165 169 } 166 if(!isAbove && isRight){ 170 if (!isAbove && isRight) 171 { 167 172 // bottom right quadrant 168 if(phiNav<phiUpperCorner) { 173 if (phiNav < phiUpperCorner) 174 { 169 175 //COUT(3) << "arrow down\n"; 170 176 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); … … 173 179 navText_->setTop(navMarker_->getTop()-navMarker_->getHeight()); 174 180 } 175 else { 181 else 182 { 176 183 //COUT(3) << "arrow right\n"; 177 184 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); … … 181 188 } 182 189 } 183 if(isAbove && !isRight){ 190 if (isAbove && !isRight) 191 { 184 192 // top left quadrant 185 if(phiNav<phiUpperCorner){ 193 if (phiNav<phiUpperCorner) 194 { 186 195 //COUT(3) << "arrow up\n"; 187 196 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); … … 190 199 navText_->setTop(navMarker_->getHeight()); 191 200 } 192 else { 201 else 202 { 193 203 //COUT(3) << "arrow left\n"; 194 204 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); … … 198 208 } 199 209 } 200 if(!isAbove && !isRight){ 210 if (!isAbove && !isRight) 211 { 201 212 // bottom left quadrant 202 if(phiNav>-phiUpperCorner) { 213 if (phiNav>-phiUpperCorner) 214 { 203 215 //COUT(3) << "arrow down\n"; 204 216 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); … … 207 219 navText_->setTop(navMarker_->getTop()-navMarker_->getHeight()); 208 220 } 209 else { 221 else 222 { 210 223 //COUT(3) << "arrow left\n"; 211 224 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); … … 216 229 } 217 230 } 218 else{ 231 else 232 { 219 233 // object is in view 220 234 navMarker_->setMaterialName("Orxonox/NavTDC"); … … 230 244 } 231 245 232 void Navigation::cycleFocus(){ 233 if(focus_ == NULL){ 246 void Navigation::cycleFocus() 247 { 248 if (!focus_) 249 { 234 250 // Get closest object 235 251 float distance = (unsigned int) -1; … … 255 271 HUD::getSingleton().getRadarObjects().insert(HUD::getSingleton().getRadarObjects().begin(), focus_); 256 272 it_ = HUD::getSingleton().getRadarObjects().begin(); 257 ++it_;258 259 }260 else{273 } 274 } 275 else if (it_ != HUD::getSingleton().getRadarObjects().end()) 276 { 261 277 focus_->resetMaterial(); 262 if(it_ != HUD::getSingleton().getRadarObjects().end()){ 278 ++it_; 279 if (it_ != HUD::getSingleton().getRadarObjects().end()) 263 280 focus_ = *it_; 264 ++it_; 265 } 266 else focus_ = NULL; 281 else 282 focus_ = 0; 283 } 284 else 285 { 286 focus_ = 0; 267 287 } 268 288 updateFocus(); 269 289 } 270 290 271 void Navigation::updateFocus(){ 272 if(focus_ == NULL){ 291 void Navigation::updateFocus() 292 { 293 if (focus_) 294 { 295 navMarker_->show(); 296 navText_->show(); 297 focus_->setColour(ColourValue::White); 298 } 299 else 300 { 273 301 navMarker_->hide(); 274 302 aimMarker_->hide(); 275 303 navText_->hide(); 276 304 } 277 else{278 navMarker_->show();279 navText_->show();280 focus_->setColour(ColourValue::White);281 }282 305 } 283 306 … … 285 308 { 286 309 this->focus_ = 0; 287 this->it_ = HUD::getSingleton().getRadarObjects().end();288 310 this->updateFocus(); 289 311 } 290 312 291 float Navigation::getDist2Focus() const { 292 if(focus_ == NULL) return(0.0); 293 return((focus_->getPosition()-SpaceShip::getLocalShip()->getPosition()).length()); 313 float Navigation::getDist2Focus() const 314 { 315 if (focus_) 316 return (focus_->getPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 317 else 318 return 0; 294 319 } 295 320 } -
code/trunk/src/orxonox/hud/Navigation.h
r1568 r1580 42 42 public: 43 43 Navigation(Ogre::OverlayContainer* container); 44 Navigation(Ogre::OverlayContainer* container, RadarObject* focus);45 44 ~Navigation(); 46 45
Note: See TracChangeset
for help on using the changeset viewer.