Changeset 9468 for code/branches/spaceNavigation/src
- Timestamp:
- Nov 26, 2012, 4:06:46 PM (12 years ago)
- Location:
- code/branches/spaceNavigation/src/modules/overlays/hud
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.cc
r9457 r9468 41 41 #include "util/Math.h" 42 42 #include "util/Convert.h" 43 #include "core/command/ConsoleCommand.h" 43 44 #include "core/CoreIncludes.h" 44 45 #include "core/XMLPort.h" … … 57 58 namespace orxonox 58 59 { 60 61 SetConsoleCommand("selectClosest", &HUDNavigation::selectClosestTarget); 62 SetConsoleCommand("selectNext", &HUDNavigation::selectNextTarget); 63 59 64 static bool compareDistance(std::pair<RadarViewable*, unsigned int> a, 60 65 std::pair<RadarViewable*, unsigned int> b) … … 79 84 this->currentMunitionSpeed_ = 2500.0f; 80 85 81 /*Pawn* ship = orxonox_cast<Pawn*>(this->getOwner()); 82 if(ship != NULL) 83 this->ship_ = ship;*/ 86 this->closestTarget_ = true; 87 this->nextTarget_ = false; 84 88 } 85 89 … … 183 187 bool closeEnough = false; // only display objects that are close enough to be relevant for the player 184 188 189 bool nextHasToBeSelected = false; 185 190 186 191 for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt) … … 208 213 } 209 214 210 // TODO : closest object is selected 211 if(listIt == this->sortedObjectList_.begin()) 215 216 // Selected object 217 if(this->closestTarget_) { 218 // select the closest object as target 219 if(listIt == this->sortedObjectList_.begin()) 220 { 221 it->second.selected_ = true; 222 } else { 223 it->second.selected_ = false; 224 } 225 closestTarget_ = false; 226 orxout() << "Closest object selected" << std::endl; 227 } 228 else if(this->nextTarget_) 212 229 { 213 it->second.selected_ = true; 214 } else { 215 it->second.selected_ = false; 216 } 230 // select the next closest object 231 if(nextHasToBeSelected){ 232 it->second.selected_ = true; 233 nextHasToBeSelected = false; 234 this->nextTarget_ = false; 235 } 236 else if(it->second.selected_) 237 { 238 nextHasToBeSelected = true; 239 it->second.selected_ = false; 240 } 241 else if(markerCount + 1 >= markerLimit_) 242 { 243 // this object is the last one that is marked, then select the closest 244 this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true; 245 nextHasToBeSelected = false; 246 } 247 } 248 217 249 218 250 // Transform to screen coordinates … … 323 355 // Target marker 324 356 const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity()); 325 Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn(); 326 // TODO : find another solution! 327 orxout() << "My team: " << humanPawn->getTeam() << std::endl; 328 orxout() << "Targets team: " << pawn->getTeam() << std::endl; 357 /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/ 329 358 if(!it->second.selected_ 330 359 || it->first->getRVVelocity().squaredLength() == 0 331 360 || pawn == NULL 332 || humanPawn == NULL333 /*|| pawn->getTeam() == humanPawn->getTeam()*/)361 /*|| humanPawn == NULL 362 || pawn->getTeam() == humanPawn->getTeam()*/) 334 363 { 335 364 // don't show marker for not selected enemies nor if the selected doesn't move … … 509 538 float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_)); 510 539 511 // munSpeed*time = lengthBetween(wePosition, targetPosition + targetSpeed*time) 512 // from this we extract: 513 float a = targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_; 514 float b = 2*((targetPosition.x - wePosition.x)*targetSpeed.x 515 +(targetPosition.y - wePosition.y)*targetSpeed.y 516 +(targetPosition.z - wePosition.z)*targetSpeed.z); 517 float c = (wePosition-targetPosition).squaredLength(); 518 519 // calculate smallest time solution, in case it exists 520 float det = b * b - 4 * a * c; 521 if(det < 0) 522 return NULL; 523 float time = (-b - sqrt(det))/(2*a); 524 if(time < 0) 525 time = (-b + sqrt(det))/(2*a); 526 if(time < 0) 527 return NULL; 528 Vector3* result = new Vector3(targetPosition + targetSpeed * time); 540 Vector3* result = new Vector3(targetPosition + targetSpeed * time1); 529 541 return result; 530 542 } 543 544 void HUDNavigation::selectClosestTarget() 545 { 546 this->closestTarget_ = true; 547 orxout() << "selectClosestTarget" << std::endl; 548 } 549 550 void HUDNavigation::selectNextTarget() 551 { 552 this->nextTarget_ = true; 553 orxout() << "selectNextTarget" << std::endl; 554 } 531 555 } -
code/branches/spaceNavigation/src/modules/overlays/hud/HUDNavigation.h
r9443 r9468 71 71 { return this->markerLimit_; } 72 72 73 void selectClosestTarget(); 74 void selectNextTarget(); 75 73 76 private: 74 77 struct ObjectInfo … … 124 127 bool showDistance_; 125 128 129 bool closestTarget_; 130 bool nextTarget_; 131 126 132 static const float LIGHTNING_GUN_SPEED_ = 700.0f; 127 133 static const float HSW01_SPEED_ = 2500.0f; 128 134 129 135 float currentMunitionSpeed_; 130 131 Pawn* ship_;132 136 133 137 unsigned int markerLimit_;
Note: See TracChangeset
for help on using the changeset viewer.