Changeset 1613
- Timestamp:
- Jun 20, 2008, 12:05:12 AM (17 years ago)
- Location:
- code/branches/hud
- Files:
-
- 1 deleted
- 14 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/core/Iterator.h
r1543 r1613 92 92 { 93 93 this->element_ = element; 94 return *this; 94 95 } 95 96 -
code/branches/hud/src/orxonox/CMakeLists.txt
r1609 r1613 4 4 Orxonox.cc 5 5 Radar.cc 6 RadarViewable.cc 6 7 Settings.cc 7 8 … … 18 19 overlays/hud/HUDSpeedBar.cc 19 20 overlays/hud/HUDText.cc 20 overlays/hud/RadarObject.cc 21 overlays/hud/RadarViewable.cc 21 overlays/hud/HUDRadar.cc 22 22 23 23 tolua/tolua_bind.cc -
code/branches/hud/src/orxonox/Orxonox.cc
r1604 r1613 76 76 #include "GraphicsEngine.h" 77 77 #include "Settings.h" 78 #include "Radar.h" 78 79 79 80 // globals for the server or client … … 99 100 , startLevel_(0) 100 101 , hud_(0) 102 , radar_(0) 101 103 //, auMan_(0) 102 104 , timer_(0) … … 126 128 delete this->hud_; 127 129 130 if (this->radar_) 131 delete this->radar_; 132 128 133 Loader::close(); 129 134 //if (this->auMan_) … … 342 347 // Load the HUD 343 348 COUT(3) << "Orxonox: Loading HUD" << std::endl; 344 345 349 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 346 350 Loader::load(hud_); 351 352 // Start the Radar 353 this->radar_ = new Radar(); 347 354 348 355 return true; -
code/branches/hud/src/orxonox/Orxonox.h
r1604 r1613 95 95 Level* startLevel_; //!< current hard coded default level 96 96 Level* hud_; //!< 'level' object fo the HUD 97 Radar* radar_; //!< represents the Radar (not the HUD part) 97 98 //audio::AudioManager* auMan_; //!< audio manager 98 99 Ogre::Timer* timer_; //!< Main loop timer -
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 } -
code/branches/hud/src/orxonox/Radar.h
r1609 r1613 38 38 39 39 #include <string> 40 #include "core/Iterator.h" 40 41 #include "core/OrxonoxClass.h" 41 42 #include "objects/Tickable.h" 43 #include "RadarViewable.h" 42 44 43 45 namespace orxonox 44 46 { 45 class _OrxonoxExport RadarListener : public OrxonoxClass47 class _OrxonoxExport RadarListener : virtual public OrxonoxClass 46 48 { 47 49 public: … … 49 51 virtual ~RadarListener() { } 50 52 51 virtual void displayObject(RadarViewable* viewable) = 0; 53 virtual void displayObject(RadarViewable* viewable, bool bIsMarked) = 0; 54 virtual void hideMarker() = 0; 52 55 virtual float getRadarSensitivity() = 0; 56 virtual void radarTick(float dt) = 0; 53 57 }; 54 58 … … 69 73 ~Radar(); 70 74 71 void unregisterObject(RadarViewable* object);72 73 void tick(float dt);75 //void unregisterObject(RadarViewable* object); 76 const RadarViewable* getFocus(); 77 RadarViewable::Shape addObjectDescription(const std::string name); 74 78 75 79 static Radar& getInstance(); 76 80 static Radar* getInstancePtr() { return instance_s; } 77 81 82 static void cycleNavigationFocus(); 83 static void releaseNavigationFocus(); 84 78 85 private: 79 86 Radar(Radar& instance); 87 void tick(float dt); 88 89 void releaseFocus(); 90 void updateFocus(); 91 void cycleFocus(); 92 93 Iterator<RadarViewable> itFocus_; 94 RadarViewable* focus_; 95 std::map<std::string, RadarViewable::Shape> objectTypes_; 96 int objectTypeCounter_; 80 97 81 98 static Radar* instance_s; -
code/branches/hud/src/orxonox/RadarViewable.cc
r1609 r1613 38 38 */ 39 39 RadarViewable::RadarViewable() 40 : radarObjectVisibility_(1.0f) 40 : radarObjectCamouflage_(0.0f) 41 , radarObjectType_(Dot) 41 42 , radarObject_(0) 43 , radarObjectDescription_("staticObject") 42 44 { 43 45 RegisterRootObject(RadarViewable); 44 46 } 45 47 46 void RadarViewable::unregisterFromRadar() 48 void RadarViewable::setRadarObjectDescription(const std::string& str) 49 { 50 Radar* radar = Radar::getInstancePtr(); 51 if (radar) 52 this->radarObjectType_ = radar->addObjectDescription(str); 53 else 54 { 55 CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; 56 } 57 this->radarObjectDescription_ = str; 58 } 59 60 /*void RadarViewable::unregisterFromRadar() 47 61 { 48 62 Radar* radar = Radar::getInstancePtr(); … … 53 67 CCOUT(2) << "Attempting to unregister an object to the radar, but the radar is non existent." << std::endl; 54 68 } 55 } 69 }*/ 56 70 } -
code/branches/hud/src/orxonox/RadarViewable.h
r1609 r1613 43 43 { 44 44 public: 45 enum Shape 46 { 47 Square, 48 Dot, 49 Triangle 50 }; 51 52 public: 45 53 RadarViewable(); 46 virtual ~RadarViewable() { unregisterFromRadar(); }54 virtual ~RadarViewable() { }//unregisterFromRadar(); } 47 55 48 void unregisterFromRadar(); 49 50 float getRadarObjectVisibility() const { return this->radarObjectVisibility_; } 51 void setRadarObjectVisibility(float visibility) { this->radarObjectVisibility_ = visibility; } 52 53 const std::string& getRadarObjectType() const { return this->radarObjectType_; } 54 void setRadarObjectType(const std::string& type) { this->radarObjectType_ = type; } 56 float getRadarObjectCamouflage() const { return this->radarObjectCamouflage_; } 57 void setRadarObjectCamouflage(float camouflage) { this->radarObjectCamouflage_ = camouflage; } 55 58 56 59 const ColourValue& getRadarObjectColour() const { return this->radarObjectColour_; } 57 60 void setRadarObjectColour(const ColourValue& colour) { this->radarObjectColour_ = colour; } 58 61 62 const std::string& getRadarObjectDescription() const { return this->radarObjectDescription_; } 63 void setRadarObjectDescription(const std::string& str); 64 65 const WorldEntity* getWorldEntity() const { return this->radarObject_; } 66 const Vector3& getWorldPosition() const { validate(); return this->radarObject_->getWorldPosition(); } 67 Vector3 getOrientedVelocity() const 68 { validate(); return this->radarObject_->getOrientation() * this->radarObject_->getVelocity(); } 69 70 Shape getRadarObjectType() const { return this->radarObjectType_; } 71 72 protected: 73 WorldEntity* radarObject_; 74 //void unregisterFromRadar(); 75 59 76 private: 60 float radarObjectVisibility_; 61 WorldEntity* radarObject_; 62 std::string radarObjectType_; 77 void validate() const { if (!this->radarObject_) 78 { COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl; assert(0); } } 79 80 float radarObjectCamouflage_; 81 Shape radarObjectType_; 82 std::string radarObjectDescription_; 63 83 ColourValue radarObjectColour_; 64 84 }; -
code/branches/hud/src/orxonox/objects/SpaceShip.cc
r1604 r1613 42 42 #include "core/Debug.h" 43 43 #include "GraphicsEngine.h" 44 #include "core/input/InputManager.h"44 //#include "core/input/InputManager.h" 45 45 #include "tools/ParticleInterface.h" 46 46 #include "RotatingProjectile.h" … … 49 49 #include "core/ConsoleCommand.h" 50 50 #include "network/Client.h" 51 #include "overlays/hud/HUDRadar.h"52 51 53 52 namespace orxonox … … 133 132 this->health_ = 100; 134 133 134 this->radarObject_ = static_cast<WorldEntity*>(this); 135 135 136 COUT(3) << "Info: SpaceShip was loaded" << std::endl; 136 137 } … … 144 145 if (this->tt2_) 145 146 delete this->tt2_; 146 147 if (setMouseEventCallback_)148 InputManager::removeMouseHandler("SpaceShip");149 150 147 if (this->cam_) 151 148 delete this->cam_; 152 153 if (!this->myShip_)154 HUDRadar::getInstance().removeRadarObject(this);155 149 } 156 150 } … … 161 155 myShip_=true; 162 156 else 163 HUDRadar::getInstance().addRadarObject(this,this->getProjectileColour());157 this->setRadarObjectColour(this->getProjectileColour()); 164 158 } 165 159 if(Model::create()) -
code/branches/hud/src/orxonox/objects/SpaceShip.h
r1558 r1613 36 36 #include "Camera.h" 37 37 #include "Model.h" 38 #include "RadarViewable.h" 38 39 #include "tools/BillboardSet.h" 39 40 40 41 namespace orxonox 41 42 { 42 class _OrxonoxExport SpaceShip : public Model 43 class _OrxonoxExport SpaceShip : public Model, public RadarViewable 43 44 { 44 45 public: -
code/branches/hud/src/orxonox/overlays/hud/HUDNavigation.cc
r1604 r1613 42 42 #include "objects/CameraHandler.h" 43 43 #include "overlays/OverlayGroup.h" 44 #include "RadarObject.h" 45 #include "HUDRadar.h" 44 #include "Radar.h" 46 45 47 46 namespace orxonox … … 49 48 CreateFactory(HUDNavigation); 50 49 51 SetConsoleCommand(HUDNavigation, cycleNavigationFocus, true).setAccessLevel(AccessLevel::User); 52 SetConsoleCommand(HUDNavigation, releaseNavigationFocus, true).setAccessLevel(AccessLevel::User); 53 54 HUDNavigation* HUDNavigation::instance_s = 0; 50 //HUDNavigation* HUDNavigation::instance_s = 0; 55 51 56 52 using namespace Ogre; … … 61 57 , aimMarker_(0) 62 58 , navText_(0) 63 , focus_(0)64 59 { 65 60 RegisterObject(HUDNavigation); 66 61 67 assert(instance_s == 0); // singleton class68 HUDNavigation::instance_s = this; 62 /*assert(instance_s == 0); // singleton class 63 HUDNavigation::instance_s = this;*/ 69 64 } 70 65 … … 83 78 } 84 79 85 HUDNavigation::instance_s = 0;80 //HUDNavigation::instance_s = 0; 86 81 } 87 82 … … 117 112 118 113 overlay_->add2D(container_); 119 overlay_->hide();120 114 } 121 115 … … 181 175 void HUDNavigation::tick(float dt) 182 176 { 183 if (!focus_) 177 if (!Radar::getInstance().getFocus()) 178 { 179 this->overlay_->hide(); 184 180 return; 181 } 182 else 183 { 184 this->overlay_->show(); 185 } 185 186 186 187 // set text 187 int dist = (int) getDist2Focus() /100.0f;188 int dist = (int) getDist2Focus(); 188 189 navText_->setCaption(convertToString(dist)); 189 190 float textLength = convertToString(dist).size() * navText_->getCharHeight() * 0.3; … … 192 193 Matrix4 transformationMatrix = navCam->getProjectionMatrix() * navCam->getViewMatrix(); 193 194 // transform to screen coordinates 194 Vector3 pos = transformationMatrix * focus_->getPosition();195 Vector3 pos = transformationMatrix * Radar::getInstance().getFocus()->getWorldPosition(); 195 196 196 197 bool outOfView; … … 266 267 267 268 Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 268 Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity());269 Projectile::getSpeed(), Radar::getInstance().getFocus()->getWorldPosition(), Radar::getInstance().getFocus()->getOrientedVelocity()); 269 270 270 271 if (wasOutOfView_) … … 288 289 } 289 290 290 void HUDNavigation::cycleFocus()291 {292 if (!focus_)293 {294 // Get closest object295 float distance = (unsigned int) -1;296 Vector3 shipPos = SpaceShip::getLocalShip()->getPosition();297 it_ = HUDRadar::getInstance().getRadarObjects().begin();298 299 for (std::list<RadarObject*>::iterator it = HUDRadar::getInstance().getRadarObjects().begin(); it != HUDRadar::getInstance().getRadarObjects().end(); ++it)300 {301 float newdist = (*it)->getPosition().squaredDistance(shipPos);302 if (newdist < distance)303 {304 distance = newdist;305 it_ = it;306 }307 }308 309 if (it_ != HUDRadar::getInstance().getRadarObjects().end())310 {311 focus_ = *it_;312 313 // move the focused object to the begin of the list, so we will iterate through all other objects when cycling314 HUDRadar::getInstance().getRadarObjects().erase(it_);315 HUDRadar::getInstance().getRadarObjects().insert(HUDRadar::getInstance().getRadarObjects().begin(), focus_);316 it_ = HUDRadar::getInstance().getRadarObjects().begin();317 }318 }319 else if (it_ != HUDRadar::getInstance().getRadarObjects().end())320 {321 focus_->resetMaterial();322 ++it_;323 if (it_ != HUDRadar::getInstance().getRadarObjects().end())324 focus_ = *it_;325 else326 focus_ = 0;327 }328 else329 {330 focus_ = 0;331 }332 updateFocus();333 }334 335 void HUDNavigation::updateFocus()336 {337 if (focus_)338 {339 overlay_->show();340 focus_->setColour(ColourValue::White);341 }342 else343 {344 overlay_->hide();345 }346 }347 348 void HUDNavigation::releaseFocus()349 {350 this->focus_ = 0;351 this->updateFocus();352 }353 354 291 float HUDNavigation::getDist2Focus() const 355 292 { 356 if ( focus_)357 return ( focus_->getPosition() - SpaceShip::getLocalShip()->getPosition()).length();293 if (Radar::getInstance().getFocus()) 294 return (Radar::getInstance().getFocus()->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 358 295 else 359 296 return 0; … … 377 314 } 378 315 379 /*static*/ HUDNavigation& HUDNavigation::getInstance()316 /*static*/ /*HUDNavigation& HUDNavigation::getInstance() 380 317 { 381 318 assert(instance_s); 382 319 return *instance_s; 383 } 384 385 /*static*/ void HUDNavigation::cycleNavigationFocus() 386 { 387 // avoid using getInstance because of the assert(). 388 // User might call this fuction even if HUDNavigation doesn't exist. 389 if (instance_s) 390 instance_s->cycleFocus(); 391 } 392 393 /*static*/ void HUDNavigation::releaseNavigationFocus() 394 { 395 // avoid using getInstance because of the assert(). 396 // User might call this fuction even if HUDNavigation doesn't exist. 397 if (instance_s) 398 instance_s->releaseFocus(); 399 } 320 }*/ 400 321 } -
code/branches/hud/src/orxonox/overlays/hud/HUDNavigation.h
r1604 r1613 50 50 void tick(float dt); 51 51 52 void cycleFocus();52 //void cycleFocus(); 53 53 float getDist2Focus() const; 54 54 55 inline RadarObject* getFocus() const55 /*inline RadarObject* getFocus() const 56 56 { return this->focus_; } 57 void releaseFocus(); 57 void releaseFocus();*/ 58 58 59 static void cycleNavigationFocus();59 /*static void cycleNavigationFocus(); 60 60 static void releaseNavigationFocus(); 61 static HUDNavigation& getInstance(); 61 static HUDNavigation& getInstance();*/ 62 62 63 63 protected: … … 87 87 float aimMarkerSize_; //!< One paramter size of the aim marker 88 88 Ogre::TextAreaOverlayElement* navText_; //!< Text overlay to display the target distance 89 std::list<RadarObject*>::iterator it_;90 RadarObject* focus_; // next pointer of linked list91 89 bool wasOutOfView_; //!< Performance booster variable: setMaterial is not cheap 92 90 93 static HUDNavigation* instance_s;91 //static HUDNavigation* instance_s; 94 92 }; 95 93 } -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.cc
r1609 r1613 37 37 #include "objects/SpaceShip.h" 38 38 #include "objects/WorldEntity.h" 39 #include "tools/TextureGenerator.h" 39 40 #include "RadarViewable.h" 40 41 … … 42 43 { 43 44 CreateFactory(HUDRadar); 44 CreateFactory(RadarColour);45 45 CreateFactory(RadarShape); 46 47 HUDRadar* HUDRadar::instance_s = 0;48 46 49 47 using namespace Ogre; … … 51 49 HUDRadar::HUDRadar() 52 50 : background_(0) 51 , marker_(0) 52 , sensitivity_(1.0f) 53 53 { 54 54 RegisterObject(HUDRadar); 55 56 assert(instance_s == 0);57 instance_s = this;58 55 } 59 56 … … 62 59 if (this->isInitialized()) 63 60 { 64 if (this->background_)61 /*if (this->background_) 65 62 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 66 63 while (this->radarDots_.size() > 0) … … 68 65 OverlayManager::getSingleton().destroyOverlayElement(this->radarDots_[this->radarDots_.size() - 1]); 69 66 this->radarDots_.pop_back(); 70 } 71 } 72 73 instance_s = 0; 67 }*/ 68 } 74 69 } 75 70 … … 78 73 OrxonoxOverlay::XMLPort(xmlElement, mode); 79 74 80 XMLPortObject(HUDRadar, RadarColour, "shapes", addShape, getShape, xmlElement, mode, false, true); 75 if (mode == XMLPort::LoadObject) 76 { 77 this->sensitivity_ = 1.0f; 78 this->halfDotSizeDistance_ = 3000.0f; 79 this->maximumDotSize_ = 0.1; 80 } 81 82 XMLPortParam(HUDRadar, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlElement, mode); 83 XMLPortParam(HUDRadar, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance, xmlElement, mode); 84 XMLPortParam(HUDRadar, "maximumDotSize", setMaximumDotSize, getMaximumDotSize, xmlElement, mode); 85 86 shapeMaterials_[RadarViewable::Dot] = "RadarSquare.tga"; 87 shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga"; 88 shapeMaterials_[RadarViewable::Square] = "RadarSquare.tga"; 81 89 82 90 if (mode == XMLPort::LoadObject) … … 86 94 overlay_->add2D(background_); 87 95 88 // create an array of all possible materials 89 unsigned int iMaterial = 0; 90 for (std::map<unsigned int, RadarShape*>::const_iterator itShape = shapes_.begin(); itShape != shapes_.end(); ++itShape) 91 { 92 Ogre::MaterialPtr originalMaterial = (Ogre::MaterialPtr)(Ogre::MaterialManager::getSingleton().getByName((*itShape).second->getAttribute())); 93 for (std::map<unsigned int, RadarColour*>::const_iterator itColour = colours_.begin(); itColour != colours_.end(); ++itColour) 94 { 95 Ogre::MaterialPtr newMaterial = originalMaterial->clone((*itShape).second->getAttribute() + convertToString(iMaterial++)); 96 newMaterial->getTechnique(0)->getPass(0)->setAmbient((*itColour).second->getAttribute()); 97 materialNames_[(*itShape).first + ((*itColour).first << 8)] = newMaterial->getName(); 98 } 99 } 100 101 /*WorldEntity* object; 102 object = new WorldEntity(); 103 object->setPosition(2000.0, 0.0, 0.0); 104 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 105 object = new WorldEntity(); 106 object->setPosition(0.0, 2000.0, 0.0); 107 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 108 object = new WorldEntity(); 109 object->setPosition(0.0, 0.0, 2000.0); 110 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 111 object = new WorldEntity(); 112 object->setPosition(10000.0,16000.0,0.0); 113 addRadarObject(object);*/ 114 } 115 } 116 117 void HUDRadar::addColour(RadarColour* colour) 118 { 119 this->colours_[colour->getIndex()] = colour; 120 } 121 122 RadarColour* HUDRadar::getColour(unsigned int index) const 123 { 124 if (index < this->colours_.size()) 125 { 126 std::map<unsigned int, RadarColour*>::const_iterator it = colours_.begin(); 127 for (unsigned int i = 0; i != index; ++it, ++i) 128 ; 129 return (*it).second; 130 } 131 else 132 return 0; 133 } 134 135 void HUDRadar::addShape(RadarShape* shape) 96 marker_ = (Ogre::PanelOverlayElement*)Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Marker"); 97 marker_->setMaterialName("Orxonox/RadarMarker"); 98 overlay_->add2D(marker_); 99 marker_->hide(); 100 } 101 } 102 103 /*void HUDRadar::addShape(RadarShape* shape) 136 104 { 137 105 this->shapes_[shape->getIndex()] = shape; … … 149 117 else 150 118 return 0; 151 } 152 153 void HUDRadar::tick(float dt) 119 }*/ 120 121 void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked) 122 { 123 const WorldEntity* wePointer = object->getWorldEntity(); 124 125 // Just to be sure that we actually have a WorldEntity 126 // We could do a dynamic_cast, but that's a lot slower 127 if (!wePointer) 128 { 129 CCOUT(4) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 130 return; 131 } 132 133 /*static int counter = 0; 134 if (++counter < 1120 && counter > 120) 135 { 136 // we have to create a new entry 137 Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( 138 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr())); 139 // get right material 140 panel->setMaterialName("Orxonox/RadarSquare"); 141 panel->setDimensions(0.03, 0.03); 142 panel->setPosition((1.0 + (rand() & 0xFF) / 256.0 - 0.001) * 0.5, (1.0 - (rand() & 0xFF) / 256.0 - 0.001) * 0.5); 143 panel->show(); 144 this->overlay_->add2D(panel); 145 this->overlay_->show(); 146 }*/ 147 148 // try to find a panel already created 149 Ogre::PanelOverlayElement* panel; 150 std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object); 151 if (it == this->radarDots_.end()) 152 { 153 // we have to create a new entry 154 panel = static_cast<Ogre::PanelOverlayElement*>( 155 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberStr())); 156 radarDots_[object] = panel; 157 // get right material 158 panel->setMaterialName(TextureGenerator::getMaterialName( 159 shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour())); 160 this->overlay_->add2D(panel); 161 } 162 else 163 panel = (*it).second; 164 165 // set size to fit distance... 166 float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 167 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 168 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); 169 panel->setDimensions(size, size); 170 171 // calc position on radar... 172 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), wePointer->getWorldPosition()); 173 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 174 panel->setPosition((1.0 + coord.x - size) * 0.5, (1.0 - coord.y - size) * 0.5); 175 176 if (bIsMarked) 177 { 178 this->marker_->show(); 179 this->marker_->setDimensions(size * 1.2, size * 1.2); 180 this->marker_->setPosition((1.0 + coord.x - size * 1.2) * 0.5, (1.0 - coord.y - size * 1.2) * 0.5); 181 } 182 } 183 184 void HUDRadar::radarTick(float dt) 185 { 186 } 187 188 /*void HUDRadar::tick(float dt) 154 189 { 155 190 // iterate through all RadarObjects … … 159 194 if ((*it)->isVisibleOnRadar()) 160 195 { 161 WorldEntity* object = (*it)->getWorldEntity();162 // Just to be sure that we actually have a WorldEntity163 // We could do a dynamic_cast, but that's a lot slower164 assert(object);165 166 // set size to fit distance...167 float size = 1.0/((object->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length());168 size = clamp(size * 100.0f, 0.02f, 0.12f);169 if (i == radarDots_.size())170 {171 // we have to create a new panel172 radarDots_.push_back(static_cast<Ogre::PanelOverlayElement*>(173 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + convertToString(i))));174 }175 radarDots_[i]->setDimensions(size, size);176 177 // calc position on radar...178 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), object->getWorldPosition());179 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture180 radarDots_[i]->setPosition((1.0 + coord.x) * 0.5, (1.0 - coord.y) * 0.5);181 182 // apply the right material183 RadarPoint description = (*it)->getDescription();184 radarDots_[i]->setMaterialName(materialNames_[description.shape_ + (description.colour_ << 8)]);185 196 } 186 197 } 187 } 188 189 void HUDRadar::listObjects()198 }*/ 199 200 /*void HUDRadar::listObjects() 190 201 { 191 202 COUT(3) << "List of RadarObjects:\n"; … … 196 207 COUT(3) << i++ << ": " << (*it)->getWorldEntity()->getWorldPosition() << std::endl; 197 208 } 198 } 199 200 /*static*/ HUDRadar& HUDRadar::getInstance() 201 { 202 assert(instance_s); 203 return *instance_s; 204 } 209 }*/ 205 210 } -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.h
r1609 r1613 92 92 93 93 94 class _OrxonoxExport HUDRadar : public OrxonoxOverlay, public Tickable, public RadarListener94 class _OrxonoxExport HUDRadar : public OrxonoxOverlay, public RadarListener//, public Tickable 95 95 { 96 96 public: … … 100 100 void XMLPort(Element& xmlElement, XMLPort::Mode mode); 101 101 102 void addShape(RadarShape* shape);103 RadarShape* getShape(unsigned int index) const; 102 /*void addShape(RadarShape* shape); 103 RadarShape* getShape(unsigned int index) const;*/ 104 104 105 void tick(float dt); 105 float getRadarSensitivity() const { return this->sensitivity_; } 106 void setRadarSensitivity(float sensitivity) { this->sensitivity_ = sensitivity; } 106 107 107 void listObjects(); 108 float getHalfDotSizeDistance() const { return this->halfDotSizeDistance_; } 109 void setHalfDotSizeDistance(float distance) { this->halfDotSizeDistance_ = distance; } 110 111 float getMaximumDotSize() const { return this->maximumDotSize_; } 112 void setMaximumDotSize(float size) { this->maximumDotSize_ = size; } 113 114 //void tick(float dt); 115 116 //void listObjects(); 108 117 109 118 private: 110 void addColour(RadarColour* colour); 111 RadarColour* getColour(unsigned int index) const; 119 void displayObject(RadarViewable* viewable, bool bIsMarked); 120 void hideMarker() { this->marker_->hide(); } 121 float getRadarSensitivity() { return 1.0f; } 122 void radarTick(float dt); 112 123 113 std::map<unsigned int, std::string> materialNames_; 114 std::map<unsigned int, RadarColour*> colours_; 115 std::map<unsigned int, RadarShape*> shapes_; 124 std::map<RadarViewable::Shape, std::string> shapeMaterials_; 116 125 117 126 Ogre::PanelOverlayElement* background_; 118 127 std::map<RadarViewable*, Ogre::PanelOverlayElement*> radarDots_; 128 Ogre::PanelOverlayElement* marker_; 129 130 float halfDotSizeDistance_; 131 float maximumDotSize_; 132 133 float sensitivity_; 119 134 }; 120 135 } -
code/branches/hud/src/orxonox/tools/TextureGenerator.cc
r1609 r1613 77 77 textureUnitState->setTextureName(textureName); 78 78 textureUnitState->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour); 79 colourMap[colour] = materialName; 80 return colourMap[colour]; 79 return (colourMap[colour] = materialName); 81 80 } 82 81 else -
code/branches/hud/visual_studio/vc8/orxonox.vcproj
r1609 r1613 189 189 </File> 190 190 <File 191 RelativePath="..\..\src\orxonox\RadarViewable.cc" 192 > 193 <FileConfiguration 194 Name="Debug|Win32" 195 > 196 <Tool 197 Name="VCCLCompilerTool" 198 ObjectFile="$(IntDir)\$(InputName)1.obj" 199 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc" 200 /> 201 </FileConfiguration> 202 <FileConfiguration 203 Name="Release|Win32" 204 > 205 <Tool 206 Name="VCCLCompilerTool" 207 ObjectFile="$(IntDir)\$(InputName)1.obj" 208 XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc" 209 /> 210 </FileConfiguration> 211 </File> 212 <File 191 213 RelativePath="..\..\src\orxonox\Settings.cc" 192 214 > … … 484 506 <File 485 507 RelativePath="..\..\src\orxonox\overlays\hud\HUDText.cc" 486 >487 </File>488 <File489 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.cc"490 >491 </File>492 <File493 RelativePath="..\..\src\orxonox\overlays\hud\RadarViewable.cc"494 508 > 495 509 </File> … … 523 537 </File> 524 538 <File 539 RelativePath="..\..\src\orxonox\RadarViewable.h" 540 > 541 </File> 542 <File 525 543 RelativePath="..\..\src\orxonox\Settings.h" 526 544 > … … 698 716 <File 699 717 RelativePath="..\..\src\orxonox\overlays\hud\HUDText.h" 700 >701 </File>702 <File703 RelativePath="..\..\src\orxonox\overlays\hud\OverlayElementFactories.h"704 >705 </File>706 <File707 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.h"708 >709 </File>710 <File711 RelativePath="..\..\src\orxonox\overlays\hud\RadarViewable.h"712 718 > 713 719 </File>
Note: See TracChangeset
for help on using the changeset viewer.