Changeset 9421 for code/branches/spaceNavigation
- Timestamp:
- Oct 29, 2012, 4:22:11 PM (12 years ago)
- Location:
- code/branches/spaceNavigation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceNavigation/data/overlays/HUD.oxo
r9400 r9421 65 65 aimMarkerSize = 0.04 66 66 /> 67 68 <HUDAimAssistant69 name = "AimAssistant"70 correctAspect = true71 pointerSize = 0.0372 />73 67 74 68 <HUDRadar -
code/branches/spaceNavigation/src/modules/overlays/hud/CMakeLists.txt
r9400 r9421 1 1 ADD_SOURCE_FILES(OVERLAYS_SRC_FILES 2 HUDAimAssistant.cc3 2 HUDBar.cc 4 3 HUDNavigation.cc -
code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc
r9400 r9421 55 55 namespace orxonox 56 56 { 57 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b) 57 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, 58 std::pair<RadarViewable*, unsigned int> b) 58 59 { 59 60 return a.second < b.second; 60 61 } 61 62 62 CreateFactory ( HUDNavigation ); 63 63 64 HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator) 65 { 66 RegisterObject(HUDNavigation); 67 this->setConfigValues(); 64 HUDNavigation::HUDNavigation(BaseObject* creator) : 65 OrxonoxOverlay(creator) 66 { 67 RegisterObject(HUDNavigation) 68 ; this->setConfigValues(); 68 69 69 70 // Set default values … … 72 73 this->setNavMarkerSize(0.05f); 73 74 this->setDetectionLimit(10000.0f); 75 this->currentMunitionSpeed_ = 2500.0f; 76 77 Pawn* ship = orxonox_cast<Pawn*>(this->getOwner()); 78 if(ship != NULL) 79 this->ship_ = ship; 74 80 } 75 81 … … 79 85 { 80 86 for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();) 81 87 removeObject((it++)->first); 82 88 } 83 89 this->sortedObjectList_.clear(); … … 94 100 SUPER(HUDNavigation, XMLPort, xmlelement, mode); 95 101 96 XMLPortParam(HUDNavigation, "font", setFont, getFont,xmlelement, mode);97 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize,xmlelement, mode);98 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize,xmlelement, mode);102 XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode); 103 XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode); 104 XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode); 99 105 XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode); 100 106 } … … 112 118 { 113 119 if (it->second.text_ != NULL) 114 120 it->second.text_->setFontName(this->fontName_); 115 121 } 116 122 } … … 132 138 { 133 139 if (it->second.text_) 134 140 it->second.text_->setCharHeight(size); 135 141 } 136 142 } … … 144 150 { 145 151 if (dist < 600) 146 152 dist = 600; 147 153 return this->getActualSize().x * 900 * this->navMarkerSize_ / dist; 148 154 } … … 151 157 { 152 158 if (dist < 600) 153 159 dist = 600; 154 160 return this->getActualSize().y * 900 * this->navMarkerSize_ / dist; 155 161 } … … 158 164 { 159 165 SUPER(HUDNavigation, tick, dt); 160 161 orxout() << "hello world" << std::endl;162 166 163 167 Camera* cam = CameraManager::getInstance().getActiveCamera(); 164 168 if (cam == NULL) 165 169 return; 166 170 const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); 167 171 168 169 172 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt) 170 173 listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f); 171 174 172 175 this->sortedObjectList_.sort(compareDistance); … … 180 183 closeEnough = listIt->second < this->detectionLimit_; 181 184 // display radarviewables on HUD if the marker limit and max-distance is not exceeded 182 if (markerCount < this->markerLimit_ && (closeEnough || 185 if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0)) 183 186 { 184 187 // Get Distance to HumanController and save it in the TextAreaOverlayElement. … … 213 216 } 214 217 else 215 218 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 216 219 217 220 if (outOfView) … … 224 227 it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour())); 225 228 it->second.wasOutOfView_ = true; 229 it->second.target_->hide(); 226 230 } 227 231 … … 294 298 it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f); 295 299 300 // TODO : Target marker 301 Vector3* targetPos = this->toAimPosition(it->first); 302 Vector3 screenPos = camTransform * *targetPos; 303 // Check if the target marker is in view too 304 if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0 305 || screenPos.y < -1.0 || screenPos.y > 1.0) 306 { 307 it->second.target_->hide(); 308 } 309 else 310 { 311 it->second.target_->show(); 312 it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f); 313 it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f); 314 } 315 316 orxout() << targetPos->x << endl; 317 delete targetPos; 318 296 319 // Position text 297 320 it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f); … … 304 327 } 305 328 else // do not display on HUD 329 306 330 { 307 331 it->second.panel_->hide(); 308 332 it->second.text_->hide(); 333 it->second.target_->hide(); // TODO : 309 334 } 310 335 } … … 312 337 313 338 /** Overridden method of OrxonoxOverlay. 314 @details315 316 317 */339 @details 340 Usually the entire overlay scales with scale(). 341 Here we obviously have to adjust this. 342 */ 318 343 void HUDNavigation::sizeChanged() 319 344 { … … 328 353 if (it->second.text_ != NULL) 329 354 it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale); 355 if (it->second.target_ != NULL) 356 it->second.target_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale); 357 // TODO : targetMarkerSize_ ??? 330 358 } 331 359 } … … 334 362 { 335 363 if (showObject(object) == false) 336 364 return; 337 365 338 366 if (this->activeObjectList_.size() >= this->markerLimit_) 339 340 367 if (object == NULL) 368 return; 341 369 342 370 // Object hasn't been added yet (we know that) … … 351 379 // Create arrow/marker 352 380 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton() 353 381 .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString())); 354 382 //panel->setMaterialName("Orxonox/NavTDC"); 355 383 panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour())); … … 357 385 //panel->setColour(object->getRadarObjectColour()); 358 386 387 // Create target marker 388 Ogre::PanelOverlayElement* target = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton() 389 .createOverlayElement("Panel", "HUDNavigation_targetMarker_" + getUniqueNumberString())); 390 target->setMaterialName(TextureGenerator::getMaterialName("target.png" /* TODO : create the target picture */, object->getRadarObjectColour())); 391 target->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale); 392 393 // Create text 359 394 Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton() 360 395 .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString())); 361 396 text->setFontName(this->fontName_); 362 397 text->setCharHeight(text->getCharHeight() * yScale); … … 364 399 365 400 panel->hide(); 401 target->hide(); 366 402 text->hide(); 367 403 368 ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */}; 404 ObjectInfo tempStruct = 405 { panel, target, text, false /*, TODO: initialize wasOutOfView_ */}; 369 406 this->activeObjectList_[object] = tempStruct; 370 407 371 408 this->background_->addChild(panel); 409 this->background_->addChild(target); 372 410 this->background_->addChild(text); 373 411 … … 383 421 // Detach overlays 384 422 this->background_->removeChild(it->second.panel_->getName()); 423 this->background_->removeChild(it->second.target_->getName()); 385 424 this->background_->removeChild(it->second.text_->getName()); 386 425 // Properly destroy the overlay elements (do not use delete!) 387 426 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_); 427 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_); 388 428 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); 389 429 // Remove from the list … … 411 451 { 412 452 if (rv == orxonox_cast<RadarViewable*>(this->getOwner())) 413 453 return false; 414 454 assert(rv->getWorldEntity()); 415 455 if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false) 416 456 return false; 417 457 return true; 418 458 } … … 424 464 { 425 465 if (!(*it)->isHumanShip_) 426 this->addObject(*it); 427 } 466 this->addObject(*it); 467 } 468 } 469 470 Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const 471 { 472 Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition(); 473 Vector3 targetPosition = target->getRVWorldPosition(); 474 Vector3 targetSpeed = target->getRVOrientedVelocity(); 475 476 // munSpeed*time = lengthBetween(wePosition, targetPosition + targetSpeed*time) 477 // from this we extract: 478 float a = pow(targetSpeed.length(),2) - pow(this->currentMunitionSpeed_,2); 479 float b = 2*((targetPosition.x - wePosition.x)*targetSpeed.x 480 +(targetPosition.y - wePosition.y)*targetSpeed.y 481 +(targetPosition.z - wePosition.z)*targetSpeed.z); 482 float c = pow((targetPosition-wePosition).length(),2); 483 484 // calculate smallest time solution, in case it exists 485 if(pow(b,2) - 4*a*c < 0) 486 return NULL; 487 float time = (-b - sqrt(pow(b,2) - 4*a*c))/(2*a); 488 if(time < 0) 489 time = (-b + sqrt(pow(b,2) - 4*a*c))/(2*a); 490 if(time < 0) 491 return NULL; 492 Vector3* result = new Vector3(targetPosition + targetSpeed * time); 493 return result; 428 494 } 429 495 } -
code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.h
r9348 r9421 75 75 { 76 76 Ogre::PanelOverlayElement* panel_; 77 Ogre::PanelOverlayElement* target_; 77 78 Ogre::TextAreaOverlayElement* text_; 78 79 bool outOfView_; … … 104 105 float getArrowSizeY(int dist) const; 105 106 107 Vector3* toAimPosition(RadarViewable* target) const; 108 106 109 std::map<RadarViewable*, ObjectInfo> activeObjectList_; 107 110 std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_; … … 112 115 bool showDistance_; 113 116 117 static const float LIGHTNING_GUN_SPEED_ = 700.0f; 118 static const float HSW01_SPEED_ = 2500.0f; 119 120 float currentMunitionSpeed_; 121 122 Pawn* ship_; 123 114 124 unsigned int markerLimit_; 115 125 float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
Note: See TracChangeset
for help on using the changeset viewer.