Changeset 9498 for code/branches
- Timestamp:
- Dec 10, 2012, 3:06:52 PM (12 years ago)
- Location:
- code/branches/presentationHS12
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationHS12
- Property svn:mergeinfo changed
/code/branches/spaceNavigation (added) merged: 9381,9400,9421,9429,9434-9435,9443-9444,9450,9457,9468,9471-9472,9484,9486,9495-9496
- Property svn:mergeinfo changed
-
code/branches/presentationHS12/data/defaultConfig/keybindings.ini
r9016 r9498 55 55 KeyLeftBracket= 56 56 KeyLeftControl=mouseLook 57 KeyLeftShif t=57 KeyLeftShif 58 58 KeyLeftWindows= 59 59 KeyLessThan= … … 141 141 KeyWebSearch= 142 142 KeyWebStop= 143 KeyX= 143 KeyX="selectClosest" 144 144 KeyY= 145 145 KeyYen= 146 KeyZ= 146 KeyZ="selectNext" 147 147 148 148 [MouseButtons] -
code/branches/presentationHS12/data/overlays/HUD.oxo
r7679 r9498 52 52 value = 0 53 53 > 54 <BarColou r position = 0.7 colour = "0.2,0.7,0.2" />54 <BarColounar position = 0.7 colour = "0.2,0.7,0.2" /> 55 55 <BarColour position = 0.4 colour = "0.7,0.5,0.2" /> 56 56 <BarColour position = 0.1 colour = "0.7,0.2,0.2" /> … … 63 63 textSize = 0.05 64 64 navMarkerSize = 0.03 65 aimMarkerSize = 0.0 465 aimMarkerSize = 0.02 66 66 /> 67 67 -
code/branches/presentationHS12/data/overlays/HUDTemplates3.oxo
r9016 r9498 105 105 textsize = 0.05 106 106 navMarkerSize = 0.03 107 aimMarkerSize = 0.0 4107 aimMarkerSize = 0.02 108 108 /> 109 109 -
code/branches/presentationHS12/src/modules/overlays/OverlaysPrereqs.h
r9348 r9498 91 91 class HUDBoostBar; 92 92 class HUDTimer; 93 class HUDAimAssistant; 93 94 class KillMessage; 94 95 class LastManStandingInfos; -
code/branches/presentationHS12/src/modules/overlays/hud/HUDNavigation.cc
r9348 r9498 37 37 #include <OgrePanelOverlayElement.h> 38 38 39 #include <typeinfo> 40 39 41 #include "util/Math.h" 40 42 #include "util/Convert.h" 43 #include "core/command/ConsoleCommand.h" 41 44 #include "core/CoreIncludes.h" 42 45 #include "core/XMLPort.h" … … 55 58 namespace orxonox 56 59 { 57 bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b) 60 61 SetConsoleCommand("HUDNavigation","selectClosest", &HUDNavigation::selectClosestTarget).addShortcut().keybindMode(KeybindMode::OnPress); 62 SetConsoleCommand("HUDNavigation","selectNext", &HUDNavigation::selectNextTarget).addShortcut().keybindMode(KeybindMode::OnPress); 63 64 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, 65 std::pair<RadarViewable*, unsigned int> b) 58 66 { 59 67 return a.second < b.second; 60 68 } 61 62 69 CreateFactory ( HUDNavigation ); 63 70 64 HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator) 65 { 66 RegisterObject(HUDNavigation); 67 this->setConfigValues(); 71 HUDNavigation* HUDNavigation::localHUD_s = 0; 72 73 HUDNavigation::HUDNavigation(BaseObject* creator) : 74 OrxonoxOverlay(creator) 75 { 76 RegisterObject(HUDNavigation) 77 ; this->setConfigValues(); 68 78 69 79 // Set default values 70 80 this->setFont("Monofur"); 71 81 this->setTextSize(0.05f); 72 this->setNavMarkerSize(0.05f); 82 this->setNavMarkerSize(0.03f); 83 this->setAimMarkerSize(0.02f); 84 73 85 this->setDetectionLimit(10000.0f); 86 this->currentMunitionSpeed_ = 2500.0f; 87 88 this->closestTarget_ = true; 89 this->nextTarget_ = false; 90 HUDNavigation::localHUD_s = this; 74 91 } 75 92 … … 79 96 { 80 97 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();) 81 98 removeObject((it++)->first); 82 99 } 83 100 this->sortedObjectList_.clear(); … … 94 111 SUPER(HUDNavigation, XMLPort, xmlelement, mode); 95 112 96 XMLPortParam(HUDNavigation, "font", setFont, getFont,xmlelement, mode);97 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize,xmlelement, mode);98 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize,xmlelement, mode);113 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode); 114 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode); 115 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode); 99 116 XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode); 117 XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode); 100 118 } 101 119 … … 112 130 { 113 131 if (it->second.text_ != NULL) 114 132 it->second.text_->setFontName(this->fontName_); 115 133 } 116 134 } … … 132 150 { 133 151 if (it->second.text_) 134 152 it->second.text_->setCharHeight(size); 135 153 } 136 154 } … … 144 162 { 145 163 if (dist < 600) 146 164 dist = 600; 147 165 return this->getActualSize().x * 900 * this->navMarkerSize_ / dist; 148 166 } … … 151 169 { 152 170 if (dist < 600) 153 171 dist = 600; 154 172 return this->getActualSize().y * 900 * this->navMarkerSize_ / dist; 155 173 } … … 161 179 Camera* cam = CameraManager::getInstance().getActiveCamera(); 162 180 if (cam == NULL) 163 181 return; 164 182 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 165 183 166 167 184 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 168 185 listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f); 169 186 170 187 this->sortedObjectList_.sort(compareDistance); … … 172 189 unsigned int markerCount = 0; 173 190 bool closeEnough = false; // only display objects that are close enough to be relevant for the player 191 192 // if the selected object doesn't exist any more or is now out of range select the closest object 193 std::map<RadarViewable*, ObjectInfo>::iterator selectedActiveObject = this->activeObjectList_.find(this->selectedTarget_); 194 if(selectedActiveObject == this->activeObjectList_.end()) 195 { 196 this->closestTarget_ = true; 197 } 198 else if(this->detectionLimit_ < (this->selectedTarget_->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f) 199 { 200 this->closestTarget_ = true; 201 selectedActiveObject->second.selected_ = false; 202 } 203 204 bool nextHasToBeSelected = false; 174 205 175 206 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) … … 178 209 closeEnough = listIt->second < this->detectionLimit_; 179 210 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 180 if (markerCount < this->markerLimit_ && (closeEnough || 211 if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0)) 181 212 { 182 213 // Get Distance to HumanController and save it in the TextAreaOverlayElement. … … 196 227 textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f; 197 228 } 229 230 // select the object that aim-assistant indicates 231 if(this->closestTarget_) 232 // select the closest object 233 { 234 if(listIt == this->sortedObjectList_.begin()) 235 { 236 it->second.selected_ = true; 237 this->selectedTarget_ = it->first; 238 } 239 else if(it->second.selected_) 240 { 241 it->second.selected_ = false; 242 } 243 244 } 245 else if(this->nextTarget_) 246 // select the next object in sortedObjectList 247 { 248 if(nextHasToBeSelected){ 249 it->second.selected_ = true; 250 this->selectedTarget_ = it->first; 251 nextHasToBeSelected = false; 252 } 253 else if(it->second.selected_) 254 { 255 nextHasToBeSelected = true; 256 it->second.selected_ = false; 257 258 // check if there's a next object 259 listIt++; 260 if(listIt != this->sortedObjectList_.end()) 261 { 262 // and if the marker limit and max-distance are not exceeded for it 263 if (markerCount + 1 >= this->markerLimit_ || 264 (listIt->second > this->detectionLimit_ && detectionLimit_ >= 0)) 265 { 266 // otherwise select the closest object 267 this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true; 268 this->selectedTarget_ = it->first; 269 nextHasToBeSelected = false; 270 } 271 } 272 listIt--; 273 } 274 } 275 198 276 199 277 // Transform to screen coordinates … … 222 300 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 223 301 it->second.wasOutOfView_ = true; 302 it->second.target_->hide(); 224 303 } 225 304 … … 284 363 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour())); 285 364 it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y); 365 it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y); 286 366 it->second.wasOutOfView_ = false; 287 367 } … … 295 375 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); 296 376 it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f); 297 } 298 299 // Make sure the overlays are shown 300 it->second.panel_->show(); 301 it->second.text_->show(); 377 378 // Make sure the overlays are shown 379 it->second.panel_->show(); 380 it->second.text_->show(); 381 382 // Target marker 383 const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity()); 384 /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/ 385 if(!it->second.selected_ 386 || it->first->getRVVelocity().squaredLength() == 0 387 || pawn == NULL 388 /* TODO : improve getTeam in such a way that it works 389 * || humanPawn == NULL 390 * || pawn->getTeam() == humanPawn->getTeam()*/) 391 { 392 // don't show marker for not selected enemies nor if the selected doesn't move 393 it->second.target_->hide(); 394 } 395 else // object is selected and moves 396 { 397 // get the aim position 398 Vector3* targetPos = this->toAimPosition(it->first); 399 // Transform to screen coordinates 400 Vector3 screenPos = camTransform * (*targetPos); 401 // Check if the target marker is in view too 402 if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0 403 || screenPos.y < -1.0 || screenPos.y > 1.0) 404 { 405 it->second.target_->hide(); 406 } 407 else 408 { 409 it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f); 410 it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f); 411 it->second.target_->show(); 412 } 413 delete targetPos; 414 } 415 416 } 302 417 } 303 418 else // do not display on HUD 419 304 420 { 305 421 it->second.panel_->hide(); 306 422 it->second.text_->hide(); 423 it->second.target_->hide(); 307 424 } 308 425 } 426 427 this->closestTarget_ = false; 428 this->nextTarget_ = false; 309 429 } 310 430 311 431 /** Overridden method of OrxonoxOverlay. 312 @details313 314 315 */432 @details 433 Usually the entire overlay scales with scale(). 434 Here we obviously have to adjust this. 435 */ 316 436 void HUDNavigation::sizeChanged() 317 437 { … … 326 446 if (it->second.text_ != NULL) 327 447 it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale); 448 if (it->second.target_ != NULL) 449 it->second.target_->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale); 328 450 } 329 451 } … … 332 454 { 333 455 if (showObject(object) == false) 334 456 return; 335 457 336 458 if (this->activeObjectList_.size() >= this->markerLimit_) 337 338 459 if (object == NULL) 460 return; 339 461 340 462 // Object hasn't been added yet (we know that) … … 349 471 // Create arrow/marker 350 472 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton() 351 473 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 352 474 //panel->setMaterialName("Orxonox/NavTDC"); 353 475 panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour())); … … 355 477 //panel->setColour(object->getRadarObjectColour()); 356 478 479 // Create target marker 480 Ogre::PanelOverlayElement* target = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 481 .createOverlayElement("Panel", "HUDNavigation_targetMarker_" + getUniqueNumberString())); 482 target->setMaterialName(TextureGenerator::getMaterialName("target.png", object->getRadarObjectColour())); 483 target->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale); 484 485 // Create text 357 486 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() 358 487 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 359 488 text->setFontName(this->fontName_); 360 489 text->setCharHeight(text->getCharHeight() * yScale); … … 362 491 363 492 panel->hide(); 493 target->hide(); 364 494 text->hide(); 365 495 366 ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */}; 496 ObjectInfo tempStruct = 497 { panel, target, text, false, false, false}; 367 498 this->activeObjectList_[object] = tempStruct; 368 499 369 500 this->background_->addChild(panel); 501 this->background_->addChild(target); 370 502 this->background_->addChild(text); 371 503 … … 381 513 // Detach overlays 382 514 this->background_->removeChild(it->second.panel_->getName()); 515 this->background_->removeChild(it->second.target_->getName()); 383 516 this->background_->removeChild(it->second.text_->getName()); 384 517 // Properly destroy the overlay elements (do not use delete!) 385 518 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 519 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_); 386 520 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 387 521 // Remove from the list … … 409 543 { 410 544 if (rv == orxonox_cast<RadarViewable*>(this->getOwner())) 411 545 return false; 412 546 assert(rv->getWorldEntity()); 413 547 if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false) 414 548 return false; 415 549 return true; 416 550 } … … 422 556 { 423 557 if (!(*it)->isHumanShip_) 424 this->addObject(*it); 558 this->addObject(*it); 559 } 560 } 561 562 Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const 563 { 564 Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition(); 565 Vector3 targetPosition = target->getRVWorldPosition(); 566 Vector3 targetSpeed = target->getRVVelocity(); 567 Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target 568 569 float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_); 570 float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_)); 571 572 Vector3* result = new Vector3(targetPosition + targetSpeed * time1); 573 return result; 574 } 575 576 void HUDNavigation::selectClosestTarget() 577 { 578 if(HUDNavigation::localHUD_s) 579 { 580 HUDNavigation::localHUD_s->closestTarget_ = true; 581 } 582 } 583 584 void HUDNavigation::selectNextTarget() 585 { 586 if(HUDNavigation::localHUD_s) 587 { 588 HUDNavigation::localHUD_s->nextTarget_ = true; 425 589 } 426 590 } -
code/branches/presentationHS12/src/modules/overlays/hud/HUDNavigation.h
r9348 r9498 71 71 { return this->markerLimit_; } 72 72 73 static void selectClosestTarget(); 74 static void selectNextTarget(); 75 73 76 private: 74 77 struct ObjectInfo 75 78 { 76 79 Ogre::PanelOverlayElement* panel_; 80 Ogre::PanelOverlayElement* target_; 77 81 Ogre::TextAreaOverlayElement* text_; 78 82 bool outOfView_; 79 83 bool wasOutOfView_; 84 bool selected_; 80 85 }; 81 86 … … 85 90 inline void setNavMarkerSize(float size) 86 91 { 87 navMarkerSize_ = size;92 this->navMarkerSize_ = size; 88 93 this->sizeChanged(); 89 94 } 90 95 inline float getNavMarkerSize() const 91 96 { return navMarkerSize_; } 97 inline void setAimMarkerSize(float size) 98 { 99 this->aimMarkerSize_ = size; 100 this->sizeChanged(); 101 } 102 inline float getAimMarkerSize() const 103 { return aimMarkerSize_; } 92 104 inline void setDetectionLimit(float limit) 93 105 { this->detectionLimit_ = limit; } … … 104 116 float getArrowSizeY(int dist) const; 105 117 118 Vector3* toAimPosition(RadarViewable* target) const; 119 106 120 std::map<RadarViewable*, ObjectInfo> activeObjectList_; 107 121 std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_; 108 122 109 123 float navMarkerSize_; 124 float aimMarkerSize_; 110 125 std::string fontName_; 111 126 float textSize_; 112 127 bool showDistance_; 128 129 RadarViewable* selectedTarget_; 130 131 bool closestTarget_; 132 bool nextTarget_; 133 134 static HUDNavigation* localHUD_s; //!< This is used as a filter. Only the local HUD should be influenced by the static Console Command functions. 135 136 137 float currentMunitionSpeed_; 113 138 114 139 unsigned int markerLimit_; -
code/branches/presentationHS12/src/orxonox/interfaces/RadarViewable.cc
r9257 r9498 102 102 } 103 103 104 Vector3 RadarViewable::getRVVelocity() const 105 { 106 const WorldEntity* object = this->getWorldEntity(); 107 validate(object); 108 return object->getVelocity(); 109 } 110 104 111 void RadarViewable::validate(const WorldEntity* object) const 105 112 { -
code/branches/presentationHS12/src/orxonox/interfaces/RadarViewable.h
r9348 r9498 113 113 const Vector3& getRVWorldPosition() const; 114 114 Vector3 getRVOrientedVelocity() const; 115 Vector3 getRVVelocity() const; 115 116 116 117 inline void setRadarObjectShape(Shape shape)
Note: See TracChangeset
for help on using the changeset viewer.