Changeset 1568 for code/trunk/src
- Timestamp:
- Jun 8, 2008, 11:34:55 PM (16 years ago)
- Location:
- code/trunk/src/orxonox/hud
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/BarOverlayElement.cc
r1564 r1568 24 24 * Co-authors: 25 25 * Felix Schulthess 26 * Fabian 'x3n' Landau 26 27 * 27 28 */ … … 29 30 #include "OrxonoxStableHeaders.h" 30 31 #include "BarOverlayElement.h" 32 31 33 #include <OgreOverlayManager.h> 34 #include <OgreMaterialManager.h> 35 #include <OgreTechnique.h> 36 32 37 #include "GraphicsEngine.h" 33 #include "util/ Math.h"38 #include "util/Convert.h" 34 39 35 40 namespace orxonox … … 37 42 using namespace Ogre; 38 43 44 unsigned int BarOverlayElement::materialcount_s = 0; 45 39 46 BarOverlayElement::BarOverlayElement(const String& name) : PanelOverlayElement(name) 40 47 { 41 name_ = name; 42 widthratio_ = 100.0f / 800.0f; // calculates the ratio (backgroundwidth - barwidth) / backgroundwidth 48 this->textureUnitState_ = 0; 49 this->name_ = name; 50 this->widthratio_ = 100.0f / 800.0f; // calculates the ratio (backgroundwidth - barwidth) / backgroundwidth 43 51 } 44 52 … … 48 56 } 49 57 50 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ 58 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container) 59 { 51 60 // init some values... 52 value_ = 0; 53 colour_ = 2; 54 autoColour_ = true; 55 right2Left_ = false; // default is left to right progress 56 leftRel_ = leftRel; 57 topRel_ = topRel; 58 dimRel_ = dimRel; 61 this->value_ = -1; 62 this->autoColour_ = true; 63 this->right2Left_ = false; // default is left to right progress 64 this->leftRel_ = leftRel; 65 this->topRel_ = topRel; 66 this->dimRel_ = dimRel; 59 67 60 68 // create background... 61 background_ = static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement("Panel", name_+"container"));62 background_->show();69 this->background_ = static_cast<OverlayContainer*>(OverlayManager::getSingleton().createOverlayElement("Panel", name_+"container")); 70 this->background_->show(); 63 71 container->addChild(background_); 64 background_->setMetricsMode(GMM_PIXELS);65 background_->setMaterialName("Orxonox/BarBackground");72 this->background_->setMetricsMode(GMM_PIXELS); 73 this->background_->setMaterialName("Orxonox/BarBackground"); 66 74 67 75 // calculate absolute coordinates... 68 resize(); 76 this->resize(); 77 this->show(); 69 78 70 show(); 71 setMetricsMode(GMM_PIXELS); 72 setMaterialName("Orxonox/Green"); 73 background_->addChild(this); 79 // create new material 80 std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(BarOverlayElement::materialcount_s++); 81 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); 82 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); 83 this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 84 this->textureUnitState_->setTextureName("bar2.tga"); 85 // use the default colour 86 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2)); 87 this->setMaterialName(materialname); 88 this->setMetricsMode(GMM_PIXELS); 89 90 this->background_->addChild(this); 74 91 } 75 92 76 void BarOverlayElement::resize(){ 93 void BarOverlayElement::resize() 94 { 77 95 // calculate new absolute coordinates... 78 left_ = (int) (leftRel_ * GraphicsEngine::getSingleton().getWindowWidth());79 t op_ = (int) (topRel_ * GraphicsEngine::getSingleton().getWindowHeight());80 width_ = (int) (dimRel_ * GraphicsEngine::getSingleton().getWindowWidth());81 height_ = (int) (0.1 *width_); // the texture has dimensions height:length = 1:1082 offset_ = (int) (width_ *widthratio_ * 0.5);83 barwidth_ = (int) (width_ * (1.0f -widthratio_));96 this->left_ = (int) (this->leftRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 97 this->top_ = (int) (this->topRel_ * GraphicsEngine::getSingleton().getWindowHeight()); 98 this->width_ = (int) (this->dimRel_ * GraphicsEngine::getSingleton().getWindowWidth()); 99 this->height_ = (int) (0.1 * this->width_); // the texture has dimensions height:length = 1:10 100 this->offset_ = (int) (this->width_ * this->widthratio_ * 0.5); 101 this->barwidth_ = (int) (this->width_ * (1.0f - this->widthratio_)); 84 102 85 103 // adapt background 86 background_->setPosition(left_,top_);87 background_->setDimensions(width_,height_);104 this->background_->setPosition(this->left_, this->top_); 105 this->background_->setDimensions(this->width_,this-> height_); 88 106 // adapt bar 89 setValue(value_);107 this->setValue(this->value_); 90 108 } 91 109 92 void BarOverlayElement::setValue(float value){ 93 value_ = clamp<float>(value, 0, 1); 94 // set colour, if nescessary 95 if(autoColour_){ 96 if (value_>0.5) {setColour(BarOverlayElement::GREEN);} 97 else if (value_>0.25) {setColour(BarOverlayElement::YELLOW);} 98 else setColour(BarOverlayElement::RED); 110 void BarOverlayElement::setValue(float value) 111 { 112 if (value == this->value_) 113 return; 114 115 this->value_ = clamp<float>(value, 0, 1); 116 if (this->autoColour_ && this->textureUnitState_) 117 { 118 // set colour 119 if (this->colours_.size() > 0) 120 { 121 ColourValue colour1, colour2 = (*this->colours_.rbegin()).second; 122 float value1, value2 = (*this->colours_.rbegin()).first; 123 for (std::map<float, ColourValue>::reverse_iterator it = this->colours_.rbegin(); it != this->colours_.rend(); ++it) 124 { 125 colour1 = colour2; 126 value1 = value2; 127 colour2 = (*it).second; 128 value2 = (*it).first; 129 130 if (value2 < this->value_) 131 break; 132 } 133 134 if (value2 > this->value_) 135 { 136 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour2); 137 } 138 else if (value1 < this->value_) 139 { 140 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1); 141 } 142 else 143 { 144 //float interpolationfactor = (this->value_ - value2) / (value1 - value2); 145 float interpolationfactor = interpolateSmooth((this->value_ - value2) / (value1 - value2), 0.0f, 1.0f); 146 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour1 * interpolationfactor + colour2 * (1 - interpolationfactor)); 147 } 148 } 99 149 } 100 150 101 151 // set value 102 if(right2Left_){ // backward case 103 setPosition(offset_ + barwidth_ * (1 - value_), 0); 104 setDimensions(barwidth_ * value_, height_); 105 }else{ // default case 106 setPosition(offset_, 0); 107 setDimensions(barwidth_ * value_, height_); 152 if (this->right2Left_) 153 { 154 // backward case 155 this->setPosition(this->offset_ + this->barwidth_ * (1 - this->value_), 0); 156 this->setDimensions(this->barwidth_ * this->value_, this->height_); 108 157 } 109 if(value_ != 0) setTiling(value_, 1.0); 158 else 159 { 160 // default case 161 this->setPosition(this->offset_, 0); 162 this->setDimensions(this->barwidth_ * this->value_, this->height_); 163 } 164 if (this->value_ != 0) 165 this->setTiling(this->value_, 1.0); 110 166 } 111 167 112 void BarOverlayElement::setColour(int colour){ 113 colour_ = colour; 114 switch(colour){ 115 case 0: 116 setMaterialName("Orxonox/Red"); 117 break; 118 case 1: 119 setMaterialName("Orxonox/Yellow"); 120 break; 121 case 2: 122 setMaterialName("Orxonox/Green"); 123 } 168 void BarOverlayElement::addColour(float value, const ColourValue& colour) 169 { 170 value = clamp<float>(value, 0, 1); 171 this->colours_[value] = colour; 172 } 173 174 void BarOverlayElement::clearColours() 175 { 176 this->colours_.clear(); 124 177 } 125 178 } -
code/trunk/src/orxonox/hud/BarOverlayElement.h
r1564 r1568 24 24 * Co-authors: 25 25 * Felix Schulthess 26 * Fabian 'x3n' Landau 26 27 * 27 28 */ … … 32 33 #include "OrxonoxPrereqs.h" 33 34 35 #include <map> 36 34 37 #include <OgrePrerequisites.h> 35 38 #include <OgrePanelOverlayElement.h> 39 40 #include "util/Math.h" 36 41 37 42 namespace orxonox … … 46 51 void resize(); 47 52 void setValue(float value); 48 void setColour(int colour); 53 void addColour(float value, const ColourValue& colour); 54 void clearColours(); 49 55 50 56 inline void setRightToLeft(bool r2l) … … 54 60 inline float getValue() const 55 61 { return this->value_; } 56 inline int getBarColour() const57 { return this->colour_; }58 62 59 63 private: 60 static const int RED = 0; // predefined colours 61 static const int YELLOW = 1; 62 static const int GREEN = 2; 63 64 static unsigned int materialcount_s; 64 65 bool right2Left_; 65 66 bool autoColour_; // whether bar changes colour automatically 66 67 float value_; // progress of bar 67 int colour_;68 68 int left_; 69 69 int top_; … … 78 78 Ogre::OverlayContainer* background_; 79 79 Ogre::String name_; 80 Ogre::TextureUnitState* textureUnitState_; 81 std::map<float, ColourValue> colours_; 80 82 }; 81 83 } -
code/trunk/src/orxonox/hud/HUD.cc
r1567 r1568 66 66 radar_ = 0; 67 67 nav_ = 0; 68 boolshowFPS_ = true;69 boolshowRenderTime_ = true;68 showFPS_ = true; 69 showRenderTime_ = true; 70 70 } 71 71 … … 84 84 Ogre::OverlayManager::getSingleton().addOverlayElementFactory(&radarOverlayElementFactory_); 85 85 86 orxonoxHUD_ = Ogre::OverlayManager::getSingleton().create("Orxonox/HUD");87 container_ = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Orxonox/HUD/container"));88 89 86 // creating text to display fps 90 87 fpsText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "fpsText")); 91 fpsText_->show();92 88 fpsText_->setMetricsMode(Ogre::GMM_PIXELS); 93 89 fpsText_->setDimensions(0.001, 0.001); … … 96 92 fpsText_->setCharHeight(20); 97 93 fpsText_->setCaption("init"); 94 fpsText_->show(); 98 95 99 96 // creating text to display render time ratio 100 97 rTRText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "rTRText")); 101 rTRText_->show();102 98 rTRText_->setMetricsMode(Ogre::GMM_PIXELS); 103 99 rTRText_->setDimensions(0.001, 0.001); … … 106 102 rTRText_->setCharHeight(20); 107 103 rTRText_->setCaption("init"); 108 109 // create energy bar 110 energyBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "energyBar")); 111 energyBar_->show(); 112 // create speedo bar 113 speedoBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "speedoBar")); 114 speedoBar_->show(); 115 // create radar 116 radar_ = static_cast<RadarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Radar", "radar")); 117 radar_->show(); 118 119 // create Navigation 120 nav_ = new Navigation(container_); 104 rTRText_->show(); 121 105 122 106 // set up screen-wide container 123 container_->show(); 124 125 orxonoxHUD_->add2D(container_); 126 orxonoxHUD_->show(); 107 container_ = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "Orxonox/HUD/container")); 127 108 container_->setLeft(0.0); 128 109 container_->setTop(0.0); … … 132 113 container_->addChild(fpsText_); 133 114 container_->addChild(rTRText_); 134 115 container_->show(); 116 117 orxonoxHUD_ = Ogre::OverlayManager::getSingleton().create("Orxonox/HUD"); 118 orxonoxHUD_->add2D(container_); 119 orxonoxHUD_->show(); 120 121 // create energy bar 122 energyBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "energyBar")); 135 123 energyBar_->init(0.01, 0.94, 0.4, container_); 136 124 energyBar_->setValue(1); 137 125 energyBar_->show(); 126 127 // create speedo bar 128 speedoBar_ = static_cast<BarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Bar", "speedoBar")); 138 129 speedoBar_->init(0.01, 0.90, 0.4, container_); 139 130 speedoBar_->addColour(0.7, ColourValue(0.2, 0.7, 0.2)); 131 speedoBar_->addColour(0.4, ColourValue(0.7, 0.5, 0.2)); 132 speedoBar_->addColour(0.1, ColourValue(0.7, 0.2, 0.2)); 133 speedoBar_->show(); 134 135 // create radar 136 radar_ = static_cast<RadarOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Radar", "radar")); 140 137 radar_->init(0.5, 0.9, 0.2, container_); 138 radar_->show(); 139 140 // create Navigation 141 nav_ = new Navigation(container_); 141 142 142 143 WorldEntity* object; … … 247 248 { 248 249 if (this->nav_->getFocus() == (*it)) 249 this->nav_-> setFocus(0);250 this->nav_->releaseFocus(); 250 251 251 252 delete (*it); … … 270 271 271 272 /*static*/ void HUD::releaseNavigationFocus(){ 272 HUD::getSingleton().nav_-> setFocus(0);273 HUD::getSingleton().nav_->releaseFocus(); 273 274 } 274 275 -
code/trunk/src/orxonox/hud/Navigation.cc
r1566 r1568 282 282 } 283 283 284 void Navigation::releaseFocus() 285 { 286 this->focus_ = 0; 287 this->it_ = HUD::getSingleton().getRadarObjects().end(); 288 this->updateFocus(); 289 } 290 284 291 float Navigation::getDist2Focus() const { 285 292 if(focus_ == NULL) return(0.0); -
code/trunk/src/orxonox/hud/Navigation.h
r1564 r1568 51 51 inline RadarObject* getFocus() const 52 52 { return this->focus_; } 53 inline void setFocus(RadarObject* object) 54 { this->focus_ = object; this->updateFocus(); } 53 void releaseFocus(); 55 54 56 55 private:
Note: See TracChangeset
for help on using the changeset viewer.