Changeset 1613 for code/branches/hud/src/orxonox/Radar.cc
- Timestamp:
- Jun 20, 2008, 12:05:12 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/Radar.cc
r1609 r1613 34 34 #include "OrxonoxStableHeaders.h" 35 35 #include "Radar.h" 36 #include <float.h> 36 37 #include "objects/WorldEntity.h" 37 #include "overlays/hud/RadarViewable.h" 38 38 #include "objects/SpaceShip.h" 39 39 #include "core/CoreIncludes.h" 40 40 //#include "core/ConfigValueIncludes.h" … … 47 47 } 48 48 49 SetConsoleCommand(Radar, cycleNavigationFocus, true).setAccessLevel(AccessLevel::User); 50 SetConsoleCommand(Radar, releaseNavigationFocus, true).setAccessLevel(AccessLevel::User); 49 51 50 52 Radar* Radar::instance_s = 0; 51 53 52 54 Radar::Radar() 55 : focus_(0) 56 , objectTypeCounter_(0) 53 57 { 54 58 assert(instance_s == 0); 55 59 instance_s = this; 60 61 // TODO: make this mapping configurable. Maybe there's a possibility with self configured 62 // configValues.. 63 this->objectTypes_["Asteroid"] = RadarViewable::Dot; 64 this->objectTypes_["SpaceShip"] = RadarViewable::Square; 65 this->objectTypes_["AsdfQwerty"] = RadarViewable::Triangle; 66 67 /*WorldEntity* object; 68 object = new WorldEntity(); 69 object->setPosition(2000.0, 0.0, 0.0); 70 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 71 object = new WorldEntity(); 72 object->setPosition(0.0, 2000.0, 0.0); 73 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 74 object = new WorldEntity(); 75 object->setPosition(0.0, 0.0, 2000.0); 76 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 77 object = new WorldEntity(); 78 object->setPosition(10000.0,16000.0,0.0); 79 addRadarObject(object);*/ 80 56 81 } 57 82 … … 61 86 } 62 87 63 Radar& Radar::getInstance() 88 /*void Radar::unregisterObject(RadarViewable* object) 89 { 90 if (this->focus_ == object) 91 this->focus_ = 0; 92 // TODO: check for focus 93 }*/ 94 95 const RadarViewable* Radar::getFocus() 96 { 97 return *(this->itFocus_); 98 } 99 100 RadarViewable::Shape Radar::addObjectDescription(const std::string name) 101 { 102 std::map<std::string, RadarViewable::Shape>::iterator it = this->objectTypes_.find(name); 103 if (it == this->objectTypes_.end()) 104 return this->objectTypes_[name] = RadarViewable::Square; // default, configure!! 105 else 106 return this->objectTypes_[name]; 107 } 108 109 110 void Radar::tick(float dt) 111 { 112 if (this->focus_ != *(this->itFocus_)) 113 { 114 // focus object was deleted, release focus 115 this->focus_ = 0; 116 this->itFocus_ = 0; 117 } 118 119 for (Iterator<RadarListener> itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 120 { 121 for (Iterator<RadarViewable> itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement) 122 { 123 if ((*itElement) != SpaceShip::getLocalShip() && (*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage()) 124 (*itListener)->displayObject(*itElement, *itElement == this->focus_); 125 } 126 127 (*itListener)->radarTick(dt); 128 129 if (this->focus_ == 0) 130 (*itListener)->hideMarker(); 131 } 132 } 133 134 void Radar::cycleFocus() 135 { 136 if (*(ObjectList<RadarViewable>::begin()) == 0) 137 { 138 // list is empty 139 this->itFocus_ = 0; 140 this->focus_ = 0; 141 } 142 else 143 { 144 Vector3 localPosition = SpaceShip::getLocalShip()->getPosition(); 145 Vector3 targetPosition = localPosition; 146 if (*(this->itFocus_)) 147 targetPosition = this->itFocus_->getWorldPosition(); 148 149 // find the closed object further away than targetPosition 150 float currentDistance = localPosition.squaredDistance(targetPosition); 151 float nextDistance = FLT_MAX; 152 float minimumDistance = FLT_MAX; 153 Iterator<RadarViewable> itFallback = 0; 154 155 for (Iterator<RadarViewable> it = ObjectList<RadarViewable>::begin(); it; ++it) 156 { 157 if (*it == SpaceShip::getLocalShip()) 158 continue; 159 160 float targetDistance = localPosition.squaredDistance((*it)->getWorldPosition()); 161 if (targetDistance > currentDistance && targetDistance < nextDistance) 162 { 163 this->itFocus_ = it; 164 nextDistance = targetDistance; 165 } 166 if (targetDistance < minimumDistance) 167 { 168 itFallback = it; 169 minimumDistance = targetDistance; 170 } 171 } 172 173 if (nextDistance == FLT_MAX) 174 { 175 // we already had the furthest object 176 this->itFocus_ = itFallback; 177 this->focus_ = *itFallback; 178 } 179 else 180 { 181 this->focus_ = *(this->itFocus_); 182 } 183 } 184 } 185 186 void Radar::releaseFocus() 187 { 188 this->itFocus_ = 0; 189 this->focus_ = 0; 190 } 191 192 193 /*static*/ Radar& Radar::getInstance() 64 194 { 65 195 assert(instance_s); … … 67 197 } 68 198 69 void Radar::unregisterObject(RadarViewable* object) 70 { 71 // TODO: check for focus 72 } 73 74 void Radar::tick(float dt) 75 { 76 for (Iterator<RadarListener> itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 77 { 78 for (Iterator<RadarViewable> itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement) 79 { 80 if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectVisibility()) 81 (*itListener)->displayObject(*itElement); 82 } 83 } 199 /*static*/ void Radar::cycleNavigationFocus() 200 { 201 // avoid using getInstance because of the assert(). 202 // User might call this fuction even if HUDNavigation doesn't exist. 203 if (instance_s) 204 instance_s->cycleFocus(); 205 } 206 207 /*static*/ void Radar::releaseNavigationFocus() 208 { 209 // avoid using getInstance because of the assert(). 210 // User might call this fuction even if HUDNavigation doesn't exist. 211 if (instance_s) 212 instance_s->releaseFocus(); 84 213 } 85 214 }
Note: See TracChangeset
for help on using the changeset viewer.