Changeset 1604 for code/branches/hud
- Timestamp:
- Jun 15, 2008, 1:09:07 AM (16 years ago)
- Location:
- code/branches/hud
- Files:
-
- 16 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/src/orxonox/CMakeLists.txt
r1601 r1604 13 13 overlays/hud/HUDFPSText.cc 14 14 overlays/hud/HUDNavigation.cc 15 overlays/hud/HUDRadar.cc 15 16 overlays/hud/HUDRTRText.cc 16 17 overlays/hud/HUDSpeedBar.cc 17 18 overlays/hud/HUDText.cc 18 19 overlays/hud/RadarObject.cc 19 overlays/hud/RadarOverlayElement.cc20 20 21 21 tolua/tolua_bind.cc -
code/branches/hud/src/orxonox/Orxonox.cc
r1601 r1604 95 95 * Create a new instance of Orxonox. Avoid doing any actual work here. 96 96 */ 97 Orxonox::Orxonox() : 98 ogre_(0), 99 //auMan_(0), 100 timer_(0), 97 Orxonox::Orxonox() 98 : ogre_(0) 99 , startLevel_(0) 100 , hud_(0) 101 //, auMan_(0) 102 , timer_(0) 101 103 // turn on frame smoothing by setting a value different from 0 102 frameSmoothingTime_(0.0f),103 //orxonoxHUD_(0) ,104 bAbort_(false),105 timefactor_(1.0f),106 mode_(STANDALONE),107 serverIp_(""),108 serverPort_(NETWORK_PORT)104 , frameSmoothingTime_(0.0f) 105 //orxonoxHUD_(0) 106 , bAbort_(false) 107 , timefactor_(1.0f) 108 , mode_(STANDALONE) 109 , serverIp_("") 110 , serverPort_(NETWORK_PORT) 109 111 { 110 112 } … … 116 118 { 117 119 // keep in mind: the order of deletion is very important! 118 /*if (this->orxonoxHUD_) 119 delete this->orxonoxHUD_;*/ 120 Loader::unload(startLevel_); 121 if (this->startLevel_) 122 delete this->startLevel_; 123 124 Loader::unload(hud_); 125 if (this->hud_) 126 delete this->hud_; 127 120 128 Loader::close(); 121 InputManager::destroy();122 129 //if (this->auMan_) 123 130 // delete this->auMan_; … … 125 132 if (this->timer_) 126 133 delete this->timer_; 134 InputManager::destroy(); 127 135 GraphicsEngine::getSingleton().destroy(); 128 136 … … 335 343 COUT(3) << "Orxonox: Loading HUD" << std::endl; 336 344 337 Level* hud= new Level(Settings::getDataPath() + "overlay/hud.oxo");338 Loader::load(hud );345 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 346 Loader::load(hud_); 339 347 340 348 return true; … … 397 405 bool Orxonox::loadScene() 398 406 { 399 Level* startlevel= new Level("levels/sample.oxw");400 Loader::open(start level);407 startLevel_ = new Level("levels/sample.oxw"); 408 Loader::open(startLevel_); 401 409 402 410 return true; -
code/branches/hud/src/orxonox/Orxonox.h
r1601 r1604 93 93 private: 94 94 GraphicsEngine* ogre_; //!< our dearest graphics engine <3 95 Level* startLevel_; //!< current hard coded default level 96 Level* hud_; //!< 'level' object fo the HUD 95 97 //audio::AudioManager* auMan_; //!< audio manager 96 98 Ogre::Timer* timer_; //!< Main loop timer -
code/branches/hud/src/orxonox/objects/SpaceShip.cc
r1601 r1604 49 49 #include "core/ConsoleCommand.h" 50 50 #include "network/Client.h" 51 #include "overlays/ OverlayGroup.h"51 #include "overlays/hud/HUDRadar.h" 52 52 53 53 namespace orxonox … … 152 152 153 153 if (!this->myShip_) 154 OverlayGroup::getHUD().removeRadarObject(this);154 HUDRadar::getInstance().removeRadarObject(this); 155 155 } 156 156 } … … 161 161 myShip_=true; 162 162 else 163 OverlayGroup::getHUD().addRadarObject(this, this->getProjectileColour());163 HUDRadar::getInstance().addRadarObject(this, this->getProjectileColour()); 164 164 } 165 165 if(Model::create()) -
code/branches/hud/src/orxonox/overlays/OrxonoxOverlay.cc
r1601 r1604 66 66 67 67 XMLPortParam(OrxonoxOverlay, "correctAspect", setAspectCorrection, getAspectCorrection, xmlElement, mode); 68 XMLPortParam(OrxonoxOverlay, "size", setSize, get Size, xmlElement, mode);68 XMLPortParam(OrxonoxOverlay, "size", setSize, getUncorrectedSize, xmlElement, mode); 69 69 XMLPortParam(OrxonoxOverlay, "rotation", setRotation, getRotation, xmlElement, mode); 70 70 XMLPortParam(OrxonoxOverlay, "origin", setOrigin, getOrigin, xmlElement, mode); … … 78 78 79 79 this->sizeChanged(); 80 this->positionChanged(); 81 this->angleChanged(); 80 82 } 81 83 } … … 129 131 { 130 132 this->overlay_->setScale(size_.x * sizeCorrection_.x, size_.y * sizeCorrection_.y); 133 positionChanged(); 131 134 } 132 135 … … 146 149 void OrxonoxOverlay::positionChanged() 147 150 { 148 Vector2 scroll = (position_ - 0.5 - size_ * (origin_ - 0.5)) * 2.0;151 Vector2 scroll = (position_ - 0.5 - size_ * sizeCorrection_ * (origin_ - 0.5)) * 2.0; 149 152 this->overlay_->setScroll(scroll.x, -scroll.y); 150 153 } -
code/branches/hud/src/orxonox/overlays/OrxonoxOverlay.h
r1601 r1604 42 42 { 43 43 public: 44 Ogre::Overlay* getOverlay() { return this->overlay_; } 44 45 OrxonoxOverlay(); 45 46 virtual ~OrxonoxOverlay(); … … 74 75 void rotate(const Radian& angle) { this->angle_ += angle; this->angleChanged(); } 75 76 76 /** Sets the s caling factorof this overlay. */77 /** Sets the size of this overlay. */ 77 78 void setSize(const Vector2& size) { this->size_ = size; this->sizeChanged(); } 78 79 79 80 /** Gets the current size (not corrected) */ 80 Vector2 get Size() const { return this->size_; }81 Vector2 getUncorrectedSize() const { return this->size_; } 81 82 82 83 /** Gets the current size (corrected) */ 83 Vector2 get ActualSize() const { return this->size_ * this->sizeCorrection_; }84 Vector2 getSize() const { return this->size_ * this->sizeCorrection_; } 84 85 85 86 /** Gets the current size correction */ -
code/branches/hud/src/orxonox/overlays/OverlayGroup.cc
r1601 r1604 21 21 * 22 22 * Author: 23 * Yuning Chai23 * Reto Grieder 24 24 * Co-authors: 25 * Felix Schulthess25 * ... 26 26 * 27 27 */ … … 30 30 #include "OverlayGroup.h" 31 31 32 #include <string>33 #include <set>34 32 #include <assert.h> 35 #include <OgreOverlay.h>36 #include <OgreOverlayContainer.h>37 #include <OgreOverlayManager.h>38 #include <OgreStringConverter.h>39 40 33 #include "core/Debug.h" 41 34 #include "core/ConsoleCommand.h" 42 35 #include "core/CoreIncludes.h" 43 #include "objects/SpaceShip.h" 44 #include "objects/WorldEntity.h" 45 #include "GraphicsEngine.h" 46 #include "hud/HUDBar.h" 47 #include "hud/RadarObject.h" 48 #include "hud/RadarOverlayElement.h" 49 #include "hud/HUDNavigation.h" 36 #include "OrxonoxOverlay.h" 50 37 51 38 namespace orxonox 52 39 { 53 40 CreateFactory(OverlayGroup); 54 41 55 SetConsoleCommandShortcut(OverlayGroup, cycleNavigationFocus).setAccessLevel(AccessLevel::User); 56 SetConsoleCommandShortcut(OverlayGroup, releaseNavigationFocus).setAccessLevel(AccessLevel::User); 57 SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); 42 SetConsoleCommand(OverlayGroup, toggleVisibility, false).setAccessLevel(AccessLevel::User); 58 43 59 44 OverlayGroup* OverlayGroup::hudInstance_s = 0; 60 45 61 46 using namespace Ogre; 62 47 63 OverlayGroup::OverlayGroup() 48 OverlayGroup::OverlayGroup() 49 : scale_(1.0, 1.0) 50 { 51 RegisterObject(OverlayGroup); 52 53 // Singleton like in Ogre. Constructor and destructor are public, 54 // but the assert prevents from having multiple instances. 55 assert(hudInstance_s == 0); 56 hudInstance_s = this; 57 } 58 59 OverlayGroup::~OverlayGroup() 60 { 61 if (this->isInitialized()) 64 62 { 65 assert(hudInstance_s == 0);66 hudInstance_s = this;67 RegisterObject(OverlayGroup);68 69 // Singleton like in Ogre. Constructor and destructor are public,70 // but the assert prevents from having multiple instances.71 72 orxonoxHUD_ = 0;73 container_ = 0;74 fpsText_ = 0;75 rTRText_ = 0;76 energyBar_ = 0;77 speedoBar_ = 0;78 radar_ = 0;79 nav_ = 0;80 showFPS_ = true;81 showRenderTime_ = true;82 63 } 83 64 84 OverlayGroup::~OverlayGroup() 65 hudInstance_s = 0; 66 } 67 68 void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) 69 { 70 BaseObject::XMLPort(xmlElement, mode); 71 72 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true); 73 XMLPortParam(OverlayGroup, "scale", scale, getScale, xmlElement, mode); 74 } 75 76 void OverlayGroup::scale(const Vector2& scale) 77 { 78 for (std::map<std::string, OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it) 79 (*it).second->scale(scale); 80 this->scale_ = scale; 81 } 82 83 void OverlayGroup::addElement(OrxonoxOverlay* element) 84 { 85 if (hudElements_.find(element->getName()) != hudElements_.end()) 85 86 { 86 if (this->isInitialized()) 87 { 88 if (this->container_) 89 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->container_); 90 this->container_ = 0; 91 if (this->fpsText_) 92 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->fpsText_); 93 this->fpsText_ = 0; 94 if (this->rTRText_) 95 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->rTRText_); 96 this->rTRText_ = 0; 97 if (this->energyBar_) 98 delete this->energyBar_; 99 this->energyBar_ = 0; 100 /*if (this->speedoBar_) 101 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->speedoBar_);*/ 102 this->speedoBar_ = 0; 103 if (this->radar_) 104 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->radar_); 105 this->radar_ = 0; 106 if (this->orxonoxHUD_) 107 Ogre::OverlayManager::getSingleton().destroy(this->orxonoxHUD_); 108 this->orxonoxHUD_ = 0; 109 } 87 COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl; 88 } 89 else 90 hudElements_[element->getName()] = element; 91 } 110 92 111 hudInstance_s = 0; 93 OrxonoxOverlay* OverlayGroup::getElement(unsigned int index) 94 { 95 if (index < this->hudElements_.size()) 96 { 97 std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin(); 98 for (unsigned int i = 0; i != index; ++it, ++i) 99 ; 100 return (*it).second; 112 101 } 102 else 103 return 0; 104 } 113 105 114 void OverlayGroup::XMLPort(Element& xmlElement, XMLPort::Mode mode) 106 /*static*/ OverlayGroup& OverlayGroup::getHUD() 107 { 108 assert(hudInstance_s); 109 return *hudInstance_s; 110 } 111 112 /*static*/ void OverlayGroup::toggleVisibility(const std::string& name) 113 { 114 if (OverlayGroup::getHUD().hudElements_.find(name) != OverlayGroup::getHUD().hudElements_.end()) 115 115 { 116 BaseObject::XMLPort(xmlElement, mode); 116 OverlayGroup::getHUD().hudElements_[name]->setVisibility(!OverlayGroup::getHUD().hudElements_[name]->isVisible()); 117 } 118 } 117 119 118 showFPS_ = true;119 showRenderTime_ = true;120 121 XMLPortObject(OverlayGroup, OrxonoxOverlay, "", addElement, getElement, xmlElement, mode, false, true);122 123 // create Factories124 Ogre::OverlayManager::getSingleton().addOverlayElementFactory(&radarOverlayElementFactory_);125 126 // set up screen-wide container127 container_ = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Orxonox/HUD/container"));128 container_->setLeft(0.0);129 container_->setTop(0.0);130 container_->setWidth(1.0);131 container_->setHeight(1.0);132 container_->setMetricsMode(Ogre::GMM_RELATIVE);133 134 orxonoxHUD_ = Ogre::OverlayManager::getSingleton().create("Orxonox/HUD");135 orxonoxHUD_->add2D(container_);136 137 // create radar138 radar_ = static_cast<RadarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Radar", "radar"));139 radar_->init(0.5, 0.9, 0.2, container_);140 141 WorldEntity* object;142 object = new WorldEntity();143 object->setPosition(2000.0, 0.0, 0.0);144 addRadarObject(object, ColourValue(0.5, 0, 0, 1));145 object = new WorldEntity();146 object->setPosition(0.0, 2000.0, 0.0);147 addRadarObject(object, ColourValue(0.5, 0, 0, 1));148 object = new WorldEntity();149 object->setPosition(0.0, 0.0, 2000.0);150 addRadarObject(object, ColourValue(0.5, 0, 0, 1));151 object = new WorldEntity();152 object->setPosition(10000.0,16000.0,0.0);153 addRadarObject(object);154 155 orxonoxHUD_->show();156 }157 158 void OverlayGroup::addElement(OrxonoxOverlay* element)159 {160 if (hudElements_.find(element->getName()) != hudElements_.end())161 {162 COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;163 }164 else165 hudElements_[element->getName()] = element;166 }167 168 OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)169 {170 if (index < this->hudElements_.size())171 {172 std::map<std::string, OrxonoxOverlay*>::const_iterator it = hudElements_.begin();173 for (unsigned int i = 0; i != index; ++it, ++i)174 ;175 return (*it).second;176 }177 else178 return 0;179 }180 181 void OverlayGroup::tick(float dt)182 {183 radar_->update();184 }185 186 void OverlayGroup::windowResized(int newWidth, int newHeight)187 {188 this->radar_->resize();189 }190 191 void OverlayGroup::addRadarObject(WorldEntity* object, const ColourValue& colour){192 RadarObject* obj = new RadarObject(container_, object, colour);193 roSet_.insert(roSet_.end(), obj);194 // // check if this is the first RadarObject to create195 // if(firstRadarObject == NULL){196 // firstRadarObject = new RadarObject(container_, object, colour);197 // lastRadarObject = firstRadarObject;198 // }199 // else{ // if not, append to list200 // lastRadarObject->next = new RadarObject(container_, object, colour);201 // lastRadarObject = lastRadarObject->next;202 // }203 }204 205 void OverlayGroup::removeRadarObject(WorldEntity* object){206 for(std::list<RadarObject*>::iterator it=roSet_.begin(); it!=roSet_.end(); ++it){207 if ((*it)->getObject() == object)208 {209 /*if (this->nav_ && this->nav_->getFocus() == (*it))210 this->nav_->releaseFocus();*/211 212 delete (*it);213 roSet_.erase(it);214 return;215 }216 }217 }218 219 /*static*/ OverlayGroup& OverlayGroup::getHUD()220 {221 assert(hudInstance_s);222 return *hudInstance_s;223 }224 225 /*static*/ void OverlayGroup::toggleVisibility(const std::string& name)226 {227 if (OverlayGroup::getHUD().hudElements_.find(name) != OverlayGroup::getHUD().hudElements_.end())228 {229 OverlayGroup::getHUD().hudElements_[name]->setVisibility(!OverlayGroup::getHUD().hudElements_[name]->isVisible());230 }231 }232 233 /*static*/ void OverlayGroup::setEnergy(float value){234 OverlayGroup::getHUD().energyBar_->setValue(value);235 }236 237 /*static*/ void OverlayGroup::cycleNavigationFocus()238 {239 if (OverlayGroup::getHUD().hudElements_.find("Navigation") != OverlayGroup::getHUD().hudElements_.end())240 {241 HUDNavigation* navi = dynamic_cast<HUDNavigation*>(OverlayGroup::getHUD().hudElements_["Navigation"]);242 navi->cycleFocus();243 }244 }245 246 /*static*/ void OverlayGroup::releaseNavigationFocus(){247 //OverlayGroup::getHUD().nav_->releaseFocus();248 }249 120 } -
code/branches/hud/src/orxonox/overlays/OverlayGroup.h
r1601 r1604 21 21 * 22 22 * Author: 23 * Yuning Chai23 * Reto Grieder 24 24 * Co-authors: 25 * Felix Schulthess25 * ... 26 26 * 27 27 */ 28 29 28 30 29 #ifndef _OverlayGroup_H__ … … 33 32 #include "OrxonoxPrereqs.h" 34 33 34 #include <map> 35 35 #include <OgrePrerequisites.h> 36 #include <OgreTextAreaOverlayElement.h>37 36 #include "core/BaseObject.h" 38 #include "objects/Tickable.h"39 37 #include "util/Math.h" 40 #include "hud/OverlayElementFactories.h"41 #include "tools/WindowEventListener.h"42 38 43 39 namespace orxonox … … 46 42 class OrxonoxOverlay; 47 43 48 class _OrxonoxExport OverlayGroup : public BaseObject , public TickableReal, public WindowEventListener44 class _OrxonoxExport OverlayGroup : public BaseObject 49 45 { 50 46 public: … … 54 50 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 55 51 56 virtual void tick(float); 52 void scale(const Vector2& scale); 53 Vector2 getScale() const { return this->scale_; } 57 54 58 void resize(); 59 void addRadarObject(WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1)); 60 void removeRadarObject(WorldEntity* object); 61 void setFPS(); 62 63 inline std::list<RadarObject*>& getRadarObjects() 64 { return this->roSet_; } 65 55 static void toggleVisibility(const std::string& name); 66 56 static OverlayGroup& getHUD(); 67 68 static void setEnergy(float value);69 static void cycleNavigationFocus();70 static void releaseNavigationFocus();71 static void toggleVisibility(const std::string& name);72 57 73 58 private: … … 77 62 OrxonoxOverlay* getElement(unsigned int index); 78 63 79 void windowResized(int newWidth, int newHeight);80 81 64 std::map<std::string, OrxonoxOverlay*> hudElements_; 82 83 std::list<RadarObject*> roSet_; 84 85 RadarOverlayElementFactory radarOverlayElementFactory_; 86 87 Ogre::Overlay* orxonoxHUD_; 88 Ogre::OverlayContainer* container_; 89 Ogre::TextAreaOverlayElement* fpsText_; 90 Ogre::TextAreaOverlayElement* rTRText_; 91 HUDBar* energyBar_; 92 BarOverlayElement* speedoBar_; 93 RadarOverlayElement* radar_; 94 HUDNavigation* nav_; 95 96 bool showFPS_; 97 bool showRenderTime_; 65 Vector2 scale_; 98 66 99 67 static OverlayGroup* hudInstance_s; -
code/branches/hud/src/orxonox/overlays/hud/HUDBar.cc
r1601 r1604 81 81 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 82 82 this->background_->setMaterialName("Orxonox/BarBackground"); 83 this->background_->setMetricsMode(GMM_RELATIVE);84 this->background_->setDimensions(1.0f, 1.0f);85 this->background_->setPosition(0.0f, 0.0f);86 83 this->overlay_->add2D(this->background_); 87 84 … … 98 95 this->bar_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "Bar")); 99 96 this->bar_->setMaterialName(materialname); 100 this->bar_->setMetricsMode(GMM_RELATIVE);101 97 this->background_->addChild(bar_); 102 98 } -
code/branches/hud/src/orxonox/overlays/hud/HUDNavigation.cc
r1601 r1604 35 35 //#include "GraphicsEngine.h" 36 36 // TODO: remove the SpaceShip and CameraHandler dependencies 37 #include "core/Debug.h" 38 #include "core/CoreIncludes.h" 39 #include "core/ConsoleCommand.h" 37 40 #include "objects/SpaceShip.h" 38 41 #include "objects/Projectile.h" … … 40 43 #include "overlays/OverlayGroup.h" 41 44 #include "RadarObject.h" 42 #include "RadarOverlayElement.h" 43 #include "core/Debug.h" 44 #include "core/CoreIncludes.h" 45 #include "HUDRadar.h" 45 46 46 47 namespace orxonox 47 48 { 48 49 CreateFactory(HUDNavigation); 50 51 SetConsoleCommand(HUDNavigation, cycleNavigationFocus, true).setAccessLevel(AccessLevel::User); 52 SetConsoleCommand(HUDNavigation, releaseNavigationFocus, true).setAccessLevel(AccessLevel::User); 53 54 HUDNavigation* HUDNavigation::instance_s = 0; 49 55 50 56 using namespace Ogre; … … 58 64 { 59 65 RegisterObject(HUDNavigation); 66 67 assert(instance_s == 0); // singleton class 68 HUDNavigation::instance_s = this; 60 69 } 61 70 … … 73 82 OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 74 83 } 84 85 HUDNavigation::instance_s = 0; 75 86 } 76 87 … … 83 94 // create container 84 95 container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer")); 85 container_->setMetricsMode(Ogre::GMM_RELATIVE);86 container_->setLeft(0.0);87 container_->setTop(0.0);88 container_->setWidth(1.0);89 container_->setHeight(1.0);90 96 91 97 // create nav text 92 98 navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText")); 93 navText_->setMetricsMode(Ogre::GMM_RELATIVE);94 navText_->setPosition(0.0f, 0.0f);95 99 navText_->setCharHeight(0.05f); 96 100 navText_->setFontName("Monofur"); … … 98 102 // create nav marker 99 103 navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navMarker")); 100 navMarker_->setMetricsMode(GMM_RELATIVE);101 104 navMarker_->setMaterialName("Orxonox/NavArrows"); 102 this->navMarkerSize_ = 0.05;103 this->wasOutOfView_ = true; // just ato ensure the material is changed right the first time..105 navMarkerSize_ = 0.05; //default 106 wasOutOfView_ = true; // just to ensure the material is changed right the first time.. 104 107 105 108 // create aim marker 106 109 aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_aimMarker")); 107 aimMarker_->setMetricsMode(GMM_RELATIVE);108 110 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 109 this->aimMarkerSize_ = 0.04;111 aimMarkerSize_ = 0.04; // default 110 112 111 113 container_->addChild(navMarker_); … … 114 116 container_->show(); 115 117 116 this->overlay_->add2D(container_);117 this->overlay_->hide();118 overlay_->add2D(container_); 119 overlay_->hide(); 118 120 } 119 121 … … 182 184 return; 183 185 184 updateMarker();185 }186 187 void HUDNavigation::updateMarker()188 {189 186 // set text 190 187 int dist = (int) getDist2Focus()/100.0f; … … 298 295 float distance = (unsigned int) -1; 299 296 Vector3 shipPos = SpaceShip::getLocalShip()->getPosition(); 300 it_ = OverlayGroup::getHUD().getRadarObjects().begin();301 302 for (std::list<RadarObject*>::iterator it = OverlayGroup::getHUD().getRadarObjects().begin(); it != OverlayGroup::getHUD().getRadarObjects().end(); ++it)297 it_ = HUDRadar::getInstance().getRadarObjects().begin(); 298 299 for (std::list<RadarObject*>::iterator it = HUDRadar::getInstance().getRadarObjects().begin(); it != HUDRadar::getInstance().getRadarObjects().end(); ++it) 303 300 { 304 301 float newdist = (*it)->getPosition().squaredDistance(shipPos); … … 310 307 } 311 308 312 if (it_ != OverlayGroup::getHUD().getRadarObjects().end())309 if (it_ != HUDRadar::getInstance().getRadarObjects().end()) 313 310 { 314 311 focus_ = *it_; 315 312 316 313 // move the focused object to the begin of the list, so we will iterate through all other objects when cycling 317 OverlayGroup::getHUD().getRadarObjects().erase(it_);318 OverlayGroup::getHUD().getRadarObjects().insert(OverlayGroup::getHUD().getRadarObjects().begin(), focus_);319 it_ = OverlayGroup::getHUD().getRadarObjects().begin();320 } 321 } 322 else if (it_ != OverlayGroup::getHUD().getRadarObjects().end())314 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()) 323 320 { 324 321 focus_->resetMaterial(); 325 322 ++it_; 326 if (it_ != OverlayGroup::getHUD().getRadarObjects().end())323 if (it_ != HUDRadar::getInstance().getRadarObjects().end()) 327 324 focus_ = *it_; 328 325 else … … 363 360 } 364 361 362 /** 363 @brief Overridden method of OrxonoxOverlay. Usually the entire overlay 364 scales with scale(). Here we obviously have to adjust this. 365 */ 365 366 void HUDNavigation::sizeChanged() 366 367 { 367 float xScale = this->getActualSize().x; 368 float yScale = this->getActualSize().y; 368 // use size to compensate for apspect ratio if enabled. 369 float xScale = this->getSize().x; 370 float yScale = this->getSize().y; 369 371 if (this->navMarker_) 370 372 navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale); … … 374 376 navText_->setCharHeight(navText_->getCharHeight() * yScale); 375 377 } 378 379 /*static*/ HUDNavigation& HUDNavigation::getInstance() 380 { 381 assert(instance_s); 382 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 } 376 400 } -
code/branches/hud/src/orxonox/overlays/hud/HUDNavigation.h
r1601 r1604 44 44 public: 45 45 HUDNavigation(); 46 virtual~HUDNavigation();46 ~HUDNavigation(); 47 47 48 v irtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);48 void XMLPort(Element& xmlElement, XMLPort::Mode mode); 49 49 50 v irtual void tick(float dt);50 void tick(float dt); 51 51 52 52 void cycleFocus(); … … 57 57 void releaseFocus(); 58 58 59 protected: 60 virtual void sizeChanged(); 61 virtual void angleChanged() { } 62 virtual void positionChanged() { } 59 static void cycleNavigationFocus(); 60 static void releaseNavigationFocus(); 61 static HUDNavigation& getInstance(); 62 63 protected: 64 void sizeChanged(); 65 void angleChanged() { } 66 void positionChanged() { } 63 67 64 68 private: 65 void init();69 HUDNavigation(HUDNavigation& instance); 66 70 void updateMarker(); 67 71 void updateFocus(); 68 72 73 // XMLPort accessors 69 74 void setNavMarkerSize(float size); 70 75 float getNavMarkerSize() const; … … 84 89 std::list<RadarObject*>::iterator it_; 85 90 RadarObject* focus_; // next pointer of linked list 86 bool wasOutOfView_; 91 bool wasOutOfView_; //!< Performance booster variable: setMaterial is not cheap 92 93 static HUDNavigation* instance_s; 87 94 }; 88 95 } -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.cc
r1601 r1604 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include " RadarOverlayElement.h"30 #include "HUDRadar.h" 31 31 32 #include < string>32 #include <assert.h> 33 33 #include <OgreOverlayManager.h> 34 #include <OgreStringConverter.h>35 34 36 35 #include "core/ConsoleCommand.h" 37 #include " objects/Tickable.h"36 #include "util/Math.h" 38 37 #include "objects/SpaceShip.h" 39 #include "util/Math.h" 40 41 #include "GraphicsEngine.h" 38 #include "objects/WorldEntity.h" 42 39 #include "RadarObject.h" 43 #include "overlays/OverlayGroup.h"44 40 45 41 namespace orxonox 46 42 { 43 CreateFactory(HUDRadar); 44 45 HUDRadar* HUDRadar::instance_s = 0; 46 47 47 using namespace Ogre; 48 48 49 RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ 49 HUDRadar::HUDRadar() 50 : background_(0) 51 { 52 RegisterObject(HUDRadar); 53 54 assert(instance_s == 0); 55 instance_s = this; 50 56 } 51 57 52 RadarOverlayElement::~RadarOverlayElement(){ 58 HUDRadar::~HUDRadar() 59 { 60 if (this->isInitialized()) 61 { 62 if (this->background_) 63 OverlayManager::getSingleton().destroyOverlayElement(this->background_); 64 } 65 66 instance_s = 0; 53 67 } 54 68 55 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 56 // some initial data 57 dimRel_ = dimRel; 58 leftRel_ = leftRel; 59 topRel_ = topRel; 69 void HUDRadar::XMLPort(Element& xmlElement, XMLPort::Mode mode) 70 { 71 OrxonoxOverlay::XMLPort(xmlElement, mode); 60 72 61 setMetricsMode(GMM_PIXELS); 62 setMaterialName("Orxonox/Radar"); 63 resize(); 73 if (mode == XMLPort::LoadObject) 74 { 75 background_ = (Ogre::PanelOverlayElement*)Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background"); 76 background_->setMaterialName("Orxonox/Radar"); 77 overlay_->add2D(background_); 64 78 65 container->addChild(this); 79 WorldEntity* object; 80 object = new WorldEntity(); 81 object->setPosition(2000.0, 0.0, 0.0); 82 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 83 object = new WorldEntity(); 84 object->setPosition(0.0, 2000.0, 0.0); 85 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 86 object = new WorldEntity(); 87 object->setPosition(0.0, 0.0, 2000.0); 88 addRadarObject(object, ColourValue(0.5, 0, 0, 1)); 89 object = new WorldEntity(); 90 object->setPosition(10000.0,16000.0,0.0); 91 addRadarObject(object); 92 } 93 66 94 } 67 95 68 void RadarOverlayElement::resize() { 69 // if window is resized, we must adapt these... 70 dim_ = (int) (dimRel_*GraphicsEngine::getSingleton().getWindowHeight()); 71 left_ = (int) (leftRel_*GraphicsEngine::getSingleton().getWindowWidth()-dim_/2); 72 top_ = (int) (topRel_*GraphicsEngine::getSingleton().getWindowHeight()-dim_/2); 73 setPosition(left_, top_); 74 setDimensions(dim_,dim_); 75 } 76 77 void RadarOverlayElement::update() { 96 void HUDRadar::tick(float dt) 97 { 78 98 // iterate through all RadarObjects 79 for(std::list<RadarObject*>::iterator it =OverlayGroup::getHUD().getRadarObjects().begin(); it!=OverlayGroup::getHUD().getRadarObjects().end(); it++)99 for(std::list<RadarObject*>::iterator it = getRadarObjects().begin(); it!= getRadarObjects().end(); it++) 80 100 { 81 101 // calc position on radar... 82 102 // set size to fit distance... 83 float distance = ((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length(); 84 if (distance > 20000) (*it)->getPanel()->setDimensions(1, 1); 85 else if (distance > 10000) (*it)->getPanel()->setDimensions(2, 2); 86 else if (distance > 5000) (*it)->getPanel()->setDimensions(3, 3); 87 else if (distance > 2500) (*it)->getPanel()->setDimensions(4, 4); 88 else if (distance > 1000) (*it)->getPanel()->setDimensions(5, 5); 89 else (*it)->getPanel()->setDimensions(6,6); 103 float size = 1.0/(((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length()); 104 size = clamp(size * 100.0f, 0.02f, 0.12f); 105 (*it)->getPanel()->setDimensions(size, size); 90 106 91 107 Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), (*it)->getPosition()); 92 coord = coord * Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 93 float dimfactor = dim_ / 2.0; 94 (*it)->getPanel()->setPosition((1 + coord.x) * dimfactor + left_ - 2, 95 (1 - coord.y) * dimfactor + top_ - 2); 108 coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture 109 (*it)->getPanel()->setPosition((1.0 + coord.x) * 0.5, (1.0 - coord.y) * 0.5); 96 110 } 97 111 } 98 112 99 void RadarOverlayElement::listObjects() const { 113 void HUDRadar::listObjects() 114 { 100 115 int i = 0; 101 116 COUT(3) << "List of RadarObjects:\n"; 102 117 // iterate through all Radar Objects 103 for(std::list<RadarObject*>::const_iterator it=OverlayGroup::getHUD().getRadarObjects().begin(); it!=OverlayGroup::getHUD().getRadarObjects().end(); ++it){ 118 for(std::list<RadarObject*>::const_iterator it = getRadarObjects().begin(); it != getRadarObjects().end(); ++it) 119 { 104 120 COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; 105 121 } 106 122 } 123 124 void HUDRadar::addRadarObject(WorldEntity* object, const ColourValue& colour) 125 { 126 RadarObject* obj = new RadarObject(overlay_, object, colour); 127 roSet_.insert(roSet_.end(), obj); 128 } 129 130 void HUDRadar::removeRadarObject(WorldEntity* object) 131 { 132 for(std::list<RadarObject*>::iterator it=roSet_.begin(); it!=roSet_.end(); ++it) 133 { 134 if ((*it)->getObject() == object) 135 { 136 /*if (this->nav_ && this->nav_->getFocus() == (*it)) 137 this->nav_->releaseFocus();*/ 138 139 delete (*it); 140 roSet_.erase(it); 141 return; 142 } 143 } 144 } 145 146 /*static*/ HUDRadar& HUDRadar::getInstance() 147 { 148 assert(instance_s); 149 return *instance_s; 150 } 107 151 } -
code/branches/hud/src/orxonox/overlays/hud/HUDRadar.h
r1599 r1604 27 27 */ 28 28 29 #ifndef _ RadarOverlayElement_H__30 #define _ RadarOverlayElement_H__29 #ifndef _HUDRadar_H__ 30 #define _HUDRadar_H__ 31 31 32 32 #include "OrxonoxPrereqs.h" … … 34 34 #include <OgrePrerequisites.h> 35 35 #include <OgrePanelOverlayElement.h> 36 #include "util/Math.h" 36 #include "overlays/OrxonoxOverlay.h" 37 #include "objects/Tickable.h" 37 38 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport RadarOverlayElement : public Ogre::PanelOverlayElement41 class _OrxonoxExport HUDRadar : public OrxonoxOverlay, public Tickable 41 42 { 42 43 public: 43 RadarOverlayElement(const Ogre::String& name); 44 ~RadarOverlayElement(); 45 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 46 void resize(); 47 void update(); 48 void listObjects() const; 44 HUDRadar(); 45 ~HUDRadar(); 46 47 void XMLPort(Element& xmlElement, XMLPort::Mode mode); 48 49 void tick(float dt); 50 51 void listObjects(); 52 53 inline std::list<RadarObject*>& getRadarObjects() 54 { return this->roSet_; } 55 56 void addRadarObject(WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1)); 57 void removeRadarObject(WorldEntity* object); 58 59 static HUDRadar& getInstance(); 49 60 50 61 private: 51 Ogre::Real leftRel_, topRel_, dimRel_; // relative position/dimension 52 int left_, top_, dim_; // absolute position/dimension 53 }; 62 HUDRadar(HUDRadar& instance); 63 64 std::list<RadarObject*> roSet_; 65 Ogre::PanelOverlayElement* background_; 66 67 static HUDRadar* instance_s; 68 }; 54 69 } 55 70 56 #endif /* _ RadarOverlayElement_H__ */71 #endif /* _HUDRadar_H__ */ -
code/branches/hud/src/orxonox/overlays/hud/HUDText.cc
r1601 r1604 67 67 this->background_ = static_cast<PanelOverlayElement*>( 68 68 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 69 this->background_->setMetricsMode(GMM_RELATIVE);70 this->background_->setDimensions(1.0f, 1.0f);71 this->background_->setPosition(0.0f, 0.0f);72 69 73 70 this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text")); 74 this->text_->setMetricsMode(Ogre::GMM_RELATIVE);75 this->text_->setPosition(0.0f, 0.0f);76 71 this->text_->setCharHeight(1.0f); 77 72 this->text_->setFontName("Monofur"); -
code/branches/hud/src/orxonox/overlays/hud/RadarObject.cc
r1599 r1604 41 41 { 42 42 template <> 43 class less<orxonox::ColourValue>43 bool less<orxonox::ColourValue>::operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const 44 44 { 45 public: 46 bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const 45 if (__x.r == __y.r) 46 { 47 if (__x.g == __y.g) 47 48 { 48 if (__x. r == __y.r)49 if (__x.b == __y.b) 49 50 { 50 if (__x.g == __y.g) 51 { 52 if (__x.b == __y.b) 53 { 54 return __x.a < __y.a; 55 } 56 return __x.b < __y.b; 57 } 58 return __x.g < __y.g; 51 return __x.a < __y.a; 59 52 } 60 return __x. r < __y.r;53 return __x.b < __y.b; 61 54 } 62 }; 55 return __x.g < __y.g; 56 } 57 return __x.r < __y.r; 58 } 63 59 } 64 60 … … 69 65 std::map<std::string, std::map<ColourValue, std::string> > RadarObject::materials_s; 70 66 71 RadarObject::RadarObject(Ogre::Overlay Container* container, WorldEntity* object, const ColourValue& colour, const std::string& texturename)67 RadarObject::RadarObject(Ogre::Overlay* container, WorldEntity* object, const ColourValue& colour, const std::string& texturename) 72 68 { 73 69 this->colour_ = colour; … … 78 74 this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s++))); 79 75 this->setMaterial(colour, texturename); 80 81 this->panel_->setDimensions(3, 3); 82 this->panel_->setMetricsMode(Ogre::GMM_PIXELS); 83 this->panel_->show(); 84 85 container->addChild(panel_); 76 this->panel_->setDimensions(0.01, 0.01); 77 container->add2D(panel_); 86 78 } 87 79 -
code/branches/hud/src/orxonox/overlays/hud/RadarObject.h
r1599 r1604 42 42 { 43 43 public: 44 RadarObject(Ogre::Overlay Container* container, WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1), const std::string& texturename = "white.tga");44 RadarObject(Ogre::Overlay* container, WorldEntity* object, const ColourValue& colour = ColourValue(0.5, 0.5, 0.5, 1), const std::string& texturename = "white.tga"); 45 45 ~RadarObject(); 46 46 -
code/branches/hud/visual_studio/vc8/orxonox.vcproj
r1601 r1604 463 463 </File> 464 464 <File 465 RelativePath="..\..\src\orxonox\overlays\hud\HUDRadar.cc" 466 > 467 </File> 468 <File 465 469 RelativePath="..\..\src\orxonox\overlays\hud\HUDRTRText.cc" 466 470 > … … 476 480 <File 477 481 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.cc" 478 >479 </File>480 <File481 RelativePath="..\..\src\orxonox\overlays\hud\RadarOverlayElement.cc"482 482 > 483 483 </File> … … 665 665 </File> 666 666 <File 667 RelativePath="..\..\src\orxonox\overlays\hud\HUDRadar.h" 668 > 669 </File> 670 <File 667 671 RelativePath="..\..\src\orxonox\overlays\hud\HUDRTRText.h" 668 672 > … … 682 686 <File 683 687 RelativePath="..\..\src\orxonox\overlays\hud\RadarObject.h" 684 >685 </File>686 <File687 RelativePath="..\..\src\orxonox\overlays\hud\RadarOverlayElement.h"688 688 > 689 689 </File>
Note: See TracChangeset
for help on using the changeset viewer.