- Timestamp:
- May 21, 2008, 12:57:10 PM (16 years ago)
- Location:
- code/branches/hud3/src/orxonox/hud
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc
r1329 r1342 42 42 BarOverlayElement::~BarOverlayElement(){} 43 43 44 void BarOverlayElement::init(Real leftRel, Real topRel, Real widthRel, Real heightRel, Ogre::OverlayContainer* container){44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 45 45 // init some values... 46 46 container_ = container; … … 49 49 color_ = 2; 50 50 autoColor_ = true; 51 left2Right = false; // default: right to left progress 52 53 // get window data... 54 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 55 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 51 left2Right = false; // default is right to left progress 56 52 leftRel_ = leftRel; 57 53 topRel_ = topRel; 58 widthRel_ = widthRel; 59 heightRel_ = heightRel; 60 61 // cálculate absolute coordinates... 62 left_ = leftRel_ * windowW_; 63 top_ = topRel_ * windowH_; 64 width_ = widthRel_ * windowW_; 65 height_ = heightRel_ * windowH_; 66 54 dimRel_ = dimRel; 55 67 56 // create background... 68 57 background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container")); … … 72 61 background_->setMaterialName("Orxonox/BarBackground"); 73 62 63 // calculate absolute coordinates... 64 resize(); 65 74 66 show(); 75 background_->addChild(this);76 67 setMetricsMode(Ogre::GMM_PIXELS); 77 68 setMaterialName("Orxonox/Green"); 78 resize();69 background_->addChild(this); 79 70 } 80 71 … … 82 73 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 83 74 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 84 // c álculate new absolute coordinates...85 left_ = leftRel_ * windowW_;86 top_ = topRel_ * windowH_;87 width_ = widthRel_ * windowW_;88 height_ = heightRel_ * windowH_;75 // calculate new absolute coordinates... 76 left_ = (int) (leftRel_ * windowW_); 77 top_ = (int) (topRel_ * windowH_); 78 width_ = (int) (dimRel_ * windowW_); 79 height_ = (int) (0.1*width_); // the texture has dimensions height:length = 1:10 89 80 // adapt background 90 81 background_->setPosition(left_, top_); -
code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc~
r1283 r1342 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 29 29 #include <OgreOverlayElement.h> 30 30 #include <OgrePanelOverlayElement.h> 31 32 31 #include "GraphicsEngine.h" 33 32 #include "BarOverlayElement.h" 34 33 … … 37 36 using namespace Ogre; 38 37 39 40 BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){} 38 BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 39 name_ = name; 40 } 41 41 42 42 BarOverlayElement::~BarOverlayElement(){} 43 43 44 void BarOverlayElement::initialise(){ 45 PanelOverlayElement::initialise(); 46 /* setDimensions(100,100); 47 setPosition(10,10); 48 setMaterialName("Orxonox/Green"); 49 setMetricsMode(Ogre::GMM_PIXELS); 50 */ } 44 void BarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 45 // init some values... 46 container_ = container; 47 om = &Ogre::OverlayManager::getSingleton(); 48 value_ = 0; 49 color_ = 2; 50 autoColor_ = true; 51 left2Right = false; // default is right to left progress 52 leftRel_ = leftRel; 53 topRel_ = topRel; 54 dimRel_ = dimRel; 55 56 // create background... 57 background_ = static_cast<OverlayContainer*>(om->createOverlayElement("Panel", name_+"container")); 58 background_->show(); 59 container_->addChild(background_); 60 background_->setMetricsMode(Ogre::GMM_PIXELS); 61 background_->setMaterialName("Orxonox/BarBackground"); 51 62 63 // calculate absolute coordinates... 64 resize(); 52 65 53 void BarOverlayElement::initBarOverlayElement(Real left, Real top, Real width, Real height, 54 int dir, int colour){ 55 setMetricsMode(Ogre::GMM_PIXELS); 56 dir_ = dir; 57 left_ = left; 58 top_ = top; 59 width_ = width; 60 height_ = height; 61 setPosition(left_,top_); 62 setDimensions(width_,height_); 63 setColour(colour); 66 show(); 67 setMetricsMode(Ogre::GMM_PIXELS); 68 setMaterialName("Orxonox/Green"); 69 background_->addChild(this); 64 70 } 65 71 66 67 void BarOverlayElement::reset(int percentage){ 68 switch(dir_){ 69 case 1: 70 setPosition(left_,top_); 71 setDimensions(width_,height_*percentage/100); 72 break; 73 case 2: 74 setPosition(left_+width_-width_*percentage/100,top_); 75 setDimensions(width_*percentage/100,height_); 76 break; 77 case 3: 78 setPosition(left_,top_+height_-height_*percentage/100); 79 setDimensions(width_,height_*percentage/100); 80 break; 81 default: 82 setPosition(left_,top_); 83 setDimensions(width_*percentage/100,height_); 84 } 85 } 86 87 88 void BarOverlayElement::setColour(int colour){ 89 switch(colour){ 90 case 0: 91 setMaterialName("Orxonox/Red"); 92 break; 93 case 1: 94 setMaterialName("Orxonox/Yellow"); 95 break; 96 case 2: 97 setMaterialName("Orxonox/Green"); 98 } 72 void BarOverlayElement::resize(){ 73 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 74 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 75 // calculate new absolute coordinates... 76 left_ = (int) (leftRel_ * windowW_); 77 top_ = (int) (topRel_ * windowH_); 78 width_ = (int) (dimRel_ * windowW_); 79 height_ = (int) (0.1*width_); // the texture has dimensions height:length = 1:10 80 // adapt background 81 background_->setPosition(left_, top_); 82 background_->setDimensions(width_, height_); 83 // adapt bar 84 setValue(value_); 99 85 } 100 86 101 102 SmartBarOverlayElement::SmartBarOverlayElement(const String& name):BarOverlayElement(name){}103 104 SmartBarOverlayElement::~SmartBarOverlayElement(void){}105 106 107 void SmartBarOverlayElement::initialise(){108 PanelOverlayElement::initialise();109 /* setDimensions(100,100); 110 setPosition(10,10);111 setMaterialName("Orxonox/Green");112 setMetricsMode(Ogre::GMM_PIXELS);113 */ } 114 115 void SmartBarOverlayElement::initSmartBarOverlayElement(Real left, Real top, Real width, Real height, int dir)116 {117 BarOverlayElement::initBarOverlayElement(left, top, width, height, dir, BarOverlayElement::GREEN);87 void BarOverlayElement::setValue(float value){ 88 value_ = value; 89 // set color, if nescessary 90 if(autoColor_){ 91 if (value_>0.5) {setColor(BarOverlayElement::GREEN);} 92 else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);} 93 else setColor(BarOverlayElement::RED); 94 } 95 // set value 96 if(left2Right){ // backward case 97 setPosition(0+width_-width_*value_, 0); 98 setDimensions(width_*value_,height_); 99 }else{ // default case 100 setPosition(0, 0); 101 setDimensions(width_*value_,height_); 102 } 103 if(value_ != 0) setTiling(value_, 1.0); 118 104 } 119 105 120 121 void SmartBarOverlayElement::reset(int percentage){ 122 if (percentage>50) {setColour(BarOverlayElement::GREEN);} 123 else if (percentage>25) {setColour(BarOverlayElement::YELLOW);} 124 else setColour(BarOverlayElement::RED); 125 OverlayElementBar::reset(percentage); 106 void BarOverlayElement::setColor(int color){ 107 color_ = color; 108 switch(color){ 109 case 0: 110 setMaterialName("Orxonox/Red"); 111 break; 112 case 1: 113 setMaterialName("Orxonox/Yellow"); 114 break; 115 case 2: 116 setMaterialName("Orxonox/Green"); 117 } 126 118 } 127 119 120 float BarOverlayElement::getValue(){ 121 return(value_); 122 } 123 124 int BarOverlayElement::getBarColor(){ 125 return(color_); 126 } 128 127 } 129 128 -
code/branches/hud3/src/orxonox/hud/BarOverlayElement.h
r1329 r1342 54 54 Ogre::Real leftRel_; 55 55 Ogre::Real topRel_; 56 Ogre::Real widthRel_; 57 Ogre::Real heightRel_; 56 Ogre::Real dimRel_; 58 57 Ogre::OverlayManager* om; // our overlay manager 59 58 Ogre::OverlayContainer* container_; // our parent container to attach to … … 69 68 BarOverlayElement(const Ogre::String& name); 70 69 virtual ~BarOverlayElement(); 71 void init(Real leftRel, Real topRel, Real widthRel, Real heightRel, Ogre::OverlayContainer* container);70 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 72 71 void resize(); 73 72 void setValue(float value); -
code/branches/hud3/src/orxonox/hud/BarOverlayElement.h~
r1283 r1342 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 43 43 class _OrxonoxExport BarOverlayElement : public Ogre::PanelOverlayElement 44 44 { 45 private:46 int percentage_;47 int dir_;48 int left_;49 int top_;50 int width_;51 int height_;52 53 static Ogre::String& typeName_s;54 55 public:56 57 static const int LEFT = 0;58 static const int UP = 1;59 static const int RIGHT = 2;60 static const int DOWN = 3;61 62 static const int RED = 0;63 static const int YELLOW = 1;64 static const int GREEN = 2;65 66 BarOverlayElement(const Ogre::String& name);67 virtual ~BarOverlayElement();68 virtual void initialise();69 70 void initBarOverlayElement(Real left, Real top, Real width, Real height,71 int dir, int colour);72 73 void reset(int percentage);74 void setColour(int colour);75 76 };77 78 79 class _OrxonoxExport SmartBarOverlayElement : public BarOverlayElement80 {81 45 private: 46 bool autoColor_; // whether bar changes color automatically 47 float value_; // progress of bar 48 int color_; 49 int left_; 50 int top_; 51 int width_; 52 int height_; 53 int windowW_, windowH_; 54 Ogre::Real leftRel_; 55 Ogre::Real topRel_; 56 Ogre::Real widthRel_; 57 Ogre::Real heightRel_; 58 Ogre::OverlayManager* om; // our overlay manager 59 Ogre::OverlayContainer* container_; // our parent container to attach to 60 Ogre::OverlayContainer* background_; 61 Ogre::String name_; 82 62 83 63 public: 84 85 SmartBarOverlayElement(const Ogre::String& name); 86 virtual ~SmartBarOverlayElement(void); 87 virtual void initialise(); 88 89 void initSmartBarOverlayElement(Ogre::Real left, Ogre::Real top, Ogre::Real width, Ogre::Real height, int dir); 90 void reset(int percentage); 91 92 }; 64 bool left2Right; 65 static const int RED = 0; // predefined colors 66 static const int YELLOW = 1; 67 static const int GREEN = 2; 68 69 BarOverlayElement(const Ogre::String& name); 70 virtual ~BarOverlayElement(); 71 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 72 void resize(); 73 void setValue(float value); 74 void setColor(int color); 75 float getValue(); 76 int getBarColor(); 77 }; 93 78 } 94 95 79 #endif 96 80 -
code/branches/hud3/src/orxonox/hud/HUD.cc
r1339 r1342 75 75 container->setHeight(1.0); 76 76 container->setMetricsMode(Ogre::GMM_RELATIVE); 77 energyBar->init(0.01, 0.94, 0.4, 0.04,container);77 energyBar->init(0.01, 0.94, 0.4, container); 78 78 energyBar->setValue(1); 79 speedoBar->init(0.01, 0.90, 0.4, 0.04,container);79 speedoBar->init(0.01, 0.90, 0.4, container); 80 80 radar->init(0.5, 0.9, 0.2, container); 81 81 radar->addObject(Vector3(1500.0, 0.0, 0.0)); -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc
r1339 r1342 81 81 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 82 82 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 83 dim_ = dimRel_*windowH_;84 left_ = leftRel_*windowW_-dim_/2;85 top_ = topRel_*windowH_-dim_/2;83 dim_ = (int) (dimRel_*windowH_); 84 left_ = (int) (leftRel_*windowW_-dim_/2); 85 top_ = (int) (topRel_*windowH_-dim_/2); 86 86 setPosition(left_, top_); 87 87 setDimensions(dim_,dim_); … … 151 151 } 152 152 153 //// RadarObject////153 //////// RadarObject //////// 154 154 155 int RadarObject::count = 0; 155 int RadarObject::count = 0; // initialize static variable 156 156 157 157 RadarObject::RadarObject(Ogre::OverlayContainer* container){ -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~
r1335 r1342 54 54 55 55 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 56 om = &Ogre::OverlayManager::getSingleton(); 56 // some initial data 57 om = &Ogre::OverlayManager::getSingleton(); 57 58 dimRel_ = dimRel; 58 59 leftRel_ = leftRel; 59 60 topRel_ = topRel; 60 61 container_ = container; 62 firstRadarObject_ = NULL; 63 lastRadarObject_ = NULL; 61 64 65 // these have to fit the data in the level 62 66 shipPos_ = Vector3(0.0, 0.0, 0.0); 63 67 initialDir_ = Vector3(1.0, 0.0, 0.0); … … 69 73 setMaterialName("Orxonox/Radar"); 70 74 resize(); 71 75 72 76 container_->addChild(this); 73 77 } … … 77 81 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 78 82 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 79 dim_ = dimRel_*windowH_;80 left_ = leftRel_*windowW_-dim_/2;81 top_ = topRel_*windowH_-dim_/2;83 dim_ = (int) (dimRel_*windowH_); 84 left_ = (int) (leftRel_*windowW_-dim_/2); 85 top_ = (int) (topRel_*windowH_-dim_/2); 82 86 setPosition(left_, top_); 83 87 setDimensions(dim_,dim_); … … 89 93 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_; 90 94 91 if(tomato_ == NULL) return; 92 93 tomato_->radius_ = acos((currentDir_.dotProduct(tomato_->pos_ - shipPos_))/ 94 ((tomato_->pos_ - shipPos_).length()*currentDir_.length())); 95 tomato_->phi_ = acos((currentOrth_.dotProduct(tomato_->pos_ - shipPos_))/ 96 ((tomato_->pos_ - shipPos_).length()*currentOrth_.length())); 97 if((currentDir_.crossProduct(currentOrth_)).dotProduct(tomato_->pos_ - shipPos_) > 0) 98 tomato_->right_ = true; 99 else tomato_->right_=false; 95 RadarObject* ro = firstRadarObject_; 96 // iterate through all RadarObjects 97 while(ro != NULL){ 98 ro->radius_ = calcRadius(ro); 99 ro->phi_ = calcPhi(ro); 100 ro->right_ = calcRight(ro); 101 if (ro->right_){ 102 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/ 103 3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2); 104 } 105 else { 106 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/ 107 3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2); 108 } 109 ro = ro->next; 110 } 111 } 100 112 101 if (tomato_->right_){ 102 tomato_->panel_->setPosition(sin(tomato_->phi_)*tomato_->radius_/ 103 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2); 113 void RadarOverlayElement::addObject(Vector3 pos){ 114 if(firstRadarObject_ == NULL){ 115 firstRadarObject_ = new RadarObject(container_); 116 firstRadarObject_->pos_ = pos; 117 lastRadarObject_ = firstRadarObject_; 104 118 } 105 else { 106 tomato_->panel_->setPosition(-sin(tomato_->phi_)*tomato_->radius_/ 107 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2); 119 else{ 120 lastRadarObject_->next = new RadarObject(container_); 121 lastRadarObject_->next->pos_ = pos; 122 lastRadarObject_ = lastRadarObject_->next; 108 123 } 109 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";110 COUT(3) << tomato_->radius_ << " " << tomato_->phi_ << std::endl;111 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";112 }113 114 void RadarOverlayElement::addObject(Vector3 pos){115 tomato_ = new RadarObject(container_);116 tomato_->pos_ = pos;117 124 } 118 119 //// RadarObject //// 120 121 int RadarObject::count = 0; 122 125 126 void RadarOverlayElement::listObjects(){ 127 int i = 0; 128 RadarObject* ro = firstRadarObject_; 129 COUT(3) << "List of RadarObjects:\n"; 130 // iterate through all Radar Objects 131 while(ro != NULL) { 132 COUT(3) << i++ << ": " << ro->pos_ << std::endl; 133 ro = ro->next; 134 } 135 } 136 137 float RadarOverlayElement::calcRadius(RadarObject* obj){ 138 return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/ 139 ((obj->pos_ - shipPos_).length()*currentDir_.length()))); 140 } 141 142 float RadarOverlayElement::calcPhi(RadarObject* obj){ 143 return(acos((currentOrth_.dotProduct(firstRadarObject_->pos_ - shipPos_))/ 144 ((firstRadarObject_->pos_ - shipPos_).length()*currentOrth_.length()))); 145 } 146 147 bool RadarOverlayElement::calcRight(RadarObject* obj){ 148 if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0) 149 return true; 150 else return false; 151 } 152 153 //////// RadarObject //////// 154 155 int RadarObject::count = 0; // initialize static variable 156 123 157 RadarObject::RadarObject(Ogre::OverlayContainer* container){ 124 158 container_ = container; … … 126 160 init(); 127 161 } 128 162 129 163 RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){ 130 164 container_ = container; … … 132 166 init(); 133 167 } 134 168 135 169 RadarObject::~RadarObject(){} 136 170 137 171 void RadarObject::init(){ 172 next = NULL; 138 173 om = &Ogre::OverlayManager::getSingleton(); 139 174 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", … … 147 182 } 148 183 149 150 184 /* my local clipboard... 185 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 186 COUT(3) << firstRadarObject_->radius_ << " " << firstRadarObject_->phi_ << std::endl; 187 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n"; 188 */
Note: See TracChangeset
for help on using the changeset viewer.