Changeset 1328
- Timestamp:
- May 19, 2008, 9:39:23 PM (17 years ago)
- Location:
- code/branches/hud3/src/orxonox/hud
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc
r1314 r1328 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 36 36 using namespace Ogre; 37 37 38 39 BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){} 38 BarOverlayElement::BarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){ 39 name_ = name; 40 } 40 41 41 42 BarOverlayElement::~BarOverlayElement(){} 42 43 43 void BarOverlayElement::initialise(){ 44 PanelOverlayElement::initialise(); 45 /* setDimensions(100,100); 46 setPosition(10,10); 47 setMaterialName("Orxonox/Green"); 48 setMetricsMode(Ogre::GMM_PIXELS); 49 */ } 44 void BarOverlayElement::init(Real leftRel, Real topRel, Real widthRel, Real heightRel, 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 dir_ = BarOverlayElement::RIGHT; 50 52 51 52 void BarOverlayElement::initBarOverlayElement(Real leftRel, Real topRel, Real widthRel, Real heightRel, int dir, int colour){ 53 // get window data... 53 54 windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); 54 55 windowH_ = GraphicsEngine::getSingleton().getWindowHeight(); 55 56 dir_ = dir;57 56 leftRel_ = leftRel; 58 57 topRel_ = topRel; … … 60 59 heightRel_ = heightRel; 61 60 61 // cálculate absolute coordinates... 62 62 left_ = leftRel_ * windowW_; 63 63 top_ = topRel_ * windowH_; … … 65 65 height_ = heightRel_ * windowH_; 66 66 67 setMetricsMode(Ogre::GMM_PIXELS); 67 // create background... 68 bar_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", name_+"Bar")); 69 bar_->show(); 70 container_->addChild(bar_); 71 bar_->setPosition(left_, top_); 72 bar_->setDimensions(width_, height_); 73 bar_->setMetricsMode(Ogre::GMM_PIXELS); 74 bar_->setMaterialName("Orxonox/Green"); 75 68 76 setPosition(left_,top_); 69 77 setDimensions(width_,height_); 70 setColour(colour); 78 setMetricsMode(Ogre::GMM_PIXELS); 79 setMaterialName("Orxonox/BarBackground"); 80 setValue(value_); 71 81 } 72 82 73 83 74 void BarOverlayElement::reset(int percentage){ 84 void BarOverlayElement::setValue(float value){ 85 value_ = value; 86 // set color, if nescessary 87 if(autoColor_){ 88 if (value_>0.5) {setColor(BarOverlayElement::GREEN);} 89 else if (value_>0.25) {setColor(BarOverlayElement::YELLOW);} 90 else setColor(BarOverlayElement::RED); 91 } 92 // set value 75 93 switch(dir_){ 76 case 1:77 setPosition(left_,top_);78 setDimensions(width_,height_*percentage/100);94 case BarOverlayElement::DOWN: 95 bar_->setPosition(left_,top_); 96 bar_->setDimensions(width_,height_*value_); 79 97 break; 80 case 2:81 setPosition(left_+width_-width_*percentage/100,top_);82 setDimensions(width_*percentage/100,height_);98 case BarOverlayElement::LEFT: 99 bar_->setPosition(left_+width_-width_*value_,top_); 100 bar_->setDimensions(width_*value_,height_); 83 101 break; 84 case 3:85 setPosition(left_,top_+height_-height_*percentage/100);86 setDimensions(width_,height_*percentage/100);102 case BarOverlayElement::UP: 103 bar_->setPosition(left_,top_+height_-height_*value_); 104 bar_->setDimensions(width_,height_*value_); 87 105 break; 88 106 default: 89 setPosition(left_,top_); 90 setDimensions(width_*percentage/100,height_); 107 bar_->setPosition(left_,top_); 108 bar_->setDimensions(width_*value_,height_); 109 break; 91 110 } 92 111 } 93 112 113 void BarOverlayElement::setDir(int dir){ 114 } 94 115 95 void BarOverlayElement::setColour(int colour){ 96 switch(colour){ 116 void BarOverlayElement::setColor(int color){ 117 color_ = color; 118 switch(color){ 97 119 case 0: 98 setMaterialName("Orxonox/Red");120 bar_->setMaterialName("Orxonox/Red"); 99 121 break; 100 122 case 1: 101 setMaterialName("Orxonox/Yellow");123 bar_->setMaterialName("Orxonox/Yellow"); 102 124 break; 103 125 case 2: 104 setMaterialName("Orxonox/Green");126 bar_->setMaterialName("Orxonox/Green"); 105 127 } 106 128 } 107 129 108 109 SmartBarOverlayElement::SmartBarOverlayElement(const String& name):BarOverlayElement(name){} 110 111 SmartBarOverlayElement::~SmartBarOverlayElement(void){} 112 113 114 void SmartBarOverlayElement::initialise(){ 115 PanelOverlayElement::initialise(); 116 /* setDimensions(100,100); 117 setPosition(10,10); 118 setMaterialName("Orxonox/Green"); 119 setMetricsMode(Ogre::GMM_PIXELS); 120 */ } 121 122 void SmartBarOverlayElement::initSmartBarOverlayElement(Real left, Real top, Real width, Real height, int dir) 123 { 124 BarOverlayElement::initBarOverlayElement(left, top, width, height, dir, BarOverlayElement::GREEN); 130 float BarOverlayElement::getValue(){ 131 return(value_); 125 132 } 126 133 127 128 void SmartBarOverlayElement::reset(int percentage){ 129 if (percentage>50) {setColour(BarOverlayElement::GREEN);} 130 else if (percentage>25) {setColour(BarOverlayElement::YELLOW);} 131 else setColour(BarOverlayElement::RED); 132 BarOverlayElement::reset(percentage); 134 int BarOverlayElement::getBarColor(){ 135 return(color_); 133 136 } 134 135 137 } 136 138 -
code/branches/hud3/src/orxonox/hud/BarOverlayElement.h
r1314 r1328 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:45 private: 46 46 47 int percentage_; 48 int dir_; 47 bool autoColor_; // whether bar changes color automatically 48 float value_; // progress of bar 49 int dir_; // direction of progress 50 int color_; 49 51 int left_; 50 52 int top_; 51 53 int width_; 52 54 int height_; 55 int windowW_, windowH_; 53 56 Ogre::Real leftRel_; 54 57 Ogre::Real topRel_; 55 58 Ogre::Real widthRel_; 56 59 Ogre::Real heightRel_; 57 int windowW_, windowH_; 58 59 static Ogre::String& typeName_s; 60 61 public: 62 63 static const int LEFT = 0; 64 static const int UP = 1; 65 static const int RIGHT = 2; 66 static const int DOWN = 3; 67 68 static const int RED = 0; 69 static const int YELLOW = 1; 70 static const int GREEN = 2; 71 72 BarOverlayElement(const Ogre::String& name); 73 virtual ~BarOverlayElement(); 74 virtual void initialise(); 75 76 void initBarOverlayElement(Real leftRel, Real topRel, Real widthRel, Real heightRel, 77 int dir, int colour); 78 79 void reset(int percentage); 80 void setColour(int colour); 81 82 }; 83 84 85 class _OrxonoxExport SmartBarOverlayElement : public BarOverlayElement 86 { 87 private: 60 Ogre::PanelOverlayElement* bar_; // the actual bar 61 Ogre::OverlayManager* om; // our overlay manager 62 Ogre::OverlayContainer* container_; // our parent container to attach to 63 Ogre::String name_; 88 64 89 65 public: 66 // directions 67 static const int RIGHT = 0; 68 static const int UP = 1; 69 static const int LEFT = 2; 70 static const int DOWN = 3; 71 // predefined colors 72 static const int RED = 0; 73 static const int YELLOW = 1; 74 static const int GREEN = 2; 90 75 91 SmartBarOverlayElement(const Ogre::String& name); 92 virtual ~SmartBarOverlayElement(void); 93 virtual void initialise(); 76 BarOverlayElement(const Ogre::String& name); 77 virtual ~BarOverlayElement(); 94 78 95 void initSmartBarOverlayElement(Ogre::Real left, Ogre::Real top, Ogre::Real width, Ogre::Real height, int dir); 96 void reset(int percentage); 79 void init(Real leftRel, Real topRel, Real widthRel, Real heightRel, Ogre::OverlayContainer* container); 80 void setDir(int dir); 81 void setValue(float value); 82 void setColor(int color); 97 83 98 }; 84 float getValue(); 85 int getBarColor(); 86 }; 99 87 } 100 101 88 #endif 102 89 -
code/branches/hud3/src/orxonox/hud/HUD.cc
r1315 r1328 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 39 39 #include "RadarOverlayElement.h" 40 40 #include "OverlayElementFactories.h" 41 // ugly hack42 #include "Orxonox.h"43 44 41 45 42 namespace orxonox … … 53 50 om->addOverlayElementFactory(barOverlayElementFactory); 54 51 55 SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory();56 om->addOverlayElementFactory(smartBarOverlayElementFactory);57 58 52 RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); 59 53 om->addOverlayElementFactory(radarOverlayElementFactory); … … 63 57 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); 64 58 65 energyCounter = static_cast< SmartBarOverlayElement*>(om->createOverlayElement("SmartBar", "energyCounter"));59 energyCounter = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyCounter")); 66 60 energyCounter->show(); 67 61 68 speedo = static_cast< SmartBarOverlayElement*>(om->createOverlayElement("SmartBar", "speedo"));62 speedo = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedo")); 69 63 speedo->show(); 70 64 … … 72 66 radar->show(); 73 67 74 75 /* TextAreaOverlayElement* test = static_cast<TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "test"));76 77 int dirX, dirY, dirZ; //flying direction78 int ortX, ortY, ortZ; //orthogonal direction79 int dX, dY, dZ; //distance between main ship and the object80 int vecX, vecY, vecZ; //vector product dir X ort81 double alpha; //defines the radius in the radar82 double beta; //defines the angle in the radar83 bool right; //checks whether the object is on the right side (since cos is not bijective)84 85 dirX = 1;86 dirY = 0;87 dirZ = 0;88 89 ortX = 0;90 ortY = 0;91 ortZ = 1;92 93 dX = -2;94 dY = 2;95 dZ = 0;96 97 alpha = acos((dirX*dX+dirY*dY+dirZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(dirX,2)+pow(dirY,2)+pow(dirZ,2))));98 beta = acos((ortX*dX+ortY*dY+ortZ*dZ)/(sqrt(pow(dX,2)+pow(dY,2)+pow(dZ,2))*sqrt(pow(ortX,2)+pow(ortY,2)+pow(ortZ,2))));99 vecX = dirY*ortZ - dirZ*ortY;100 vecY = dirZ*ortX - dirX*ortZ;101 vecZ = dirX*ortY - dirY*ortX;102 103 if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;}104 else right=false;105 106 test->setCaption("hell");107 test->setPosition(10,10);108 test->setDimensions(20,20);109 test->show();110 test->setMetricsMode(Ogre::GMM_PIXELS);111 container->addChild(test);112 113 COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl;114 */115 116 68 container->addChild(energyCounter); 117 69 container->addChild(speedo); 118 70 container->addChild(radar); 119 71 container->show(); 120 121 72 orxonoxHUD->add2D(container); 122 73 orxonoxHUD->show(); 123 124 125 126 // important: don't use SceneManager to create the node! but register the creator scene manager.127 /* ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely");128 129 ogreNode_->setPosition(80,-60,-200);130 ogreNode_->setScale(0.4,0.4,0.4);131 // ugly hack, but I haven't figured out yet how we could change this, since we really need the132 // scene manager..133 ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh"));134 // orxonoxOverlay->add3D(ogreNode_);135 */136 137 74 container->setLeft(0.0); 138 75 container->setTop(0.0); … … 141 78 container->setMetricsMode(Ogre::GMM_RELATIVE); 142 79 143 energyCounter->init SmartBarOverlayElement(0.01, 0.01, 0.2, 0.02, BarOverlayElement::LEFT);144 energyCounter-> reset(100);80 energyCounter->init(0.01, 0.01, 0.2, 0.02, container); 81 energyCounter->setValue(1); 145 82 146 speedo->initSmartBarOverlayElement(0.01, 0.04, 0.2, 0.02, BarOverlayElement::LEFT); 147 speedo->reset(80); 83 speedo->init(0.01, 0.04, 0.2, 0.02, container); 148 84 149 radar->initRadarOverlayElement(0.5, 0.9, 0.2, container); 150 151 85 radar->init(0.5, 0.9, 0.2, container); 152 86 } 153 87 … … 156 90 float v = SpaceShip::instance_s->getVelocity().length(); 157 91 float vmax = SpaceShip::instance_s->getMaxSpeed(); 158 speedo-> reset(100*v/vmax);92 speedo->setValue(v/vmax); 159 93 radar->update(); 160 /*if (this->ogreNode_)161 {162 this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);163 this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);164 this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL);165 }*/166 94 } 167 95 168 HUD::~HUD(void){ }169 96 HUD::~HUD(void){ 97 } 170 98 } 171 99 -
code/branches/hud3/src/orxonox/hud/HUD.h
r1314 r1328 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 50 50 Ogre::Overlay* orxonoxHUD; 51 51 Ogre::OverlayContainer* container; 52 SmartBarOverlayElement* energyCounter;53 SmartBarOverlayElement* speedo;52 BarOverlayElement* energyCounter; 53 BarOverlayElement* speedo; 54 54 RadarOverlayElement* radar; 55 55 -
code/branches/hud3/src/orxonox/hud/OverlayElementFactories.h
r1302 r1328 22 22 * Yuning Chai 23 23 * Co-authors: 24 * ...24 * Felix Schulthess 25 25 * 26 26 */ … … 28 28 #ifndef _FACTORIES_H__ 29 29 #define _FACTORIES_H__ 30 31 30 32 31 #include <OgreOverlayElement.h> … … 36 35 #include "BarOverlayElement.h" 37 36 37 namespace orxonox{ 38 class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{ 39 public: 40 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 41 return new BarOverlayElement(instanceName); 42 } 43 const Ogre::String& getTypeName(void) const{ 44 static Ogre::String name = "Bar"; 45 return name; 46 } 47 }; 38 48 39 namespace orxonox{ 40 41 class _OrxonoxExport BarOverlayElementFactory : public Ogre::OverlayElementFactory{ 42 public: 43 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 44 return new BarOverlayElement(instanceName); 45 } 46 const Ogre::String& getTypeName(void) const{ 47 static Ogre::String name = "Bar"; 48 return name; 49 } 50 }; 51 52 53 class _OrxonoxExport SmartBarOverlayElementFactory : public Ogre::OverlayElementFactory{ 54 public: 55 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 56 return new SmartBarOverlayElement(instanceName); 57 } 58 const Ogre::String& getTypeName(void) const{ 59 static Ogre::String name = "SmartBar"; 60 return name; 61 } 62 }; 63 64 class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{ 65 public: 66 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 67 return new RadarOverlayElement(instanceName); 68 } 69 const Ogre::String& getTypeName(void) const{ 70 static Ogre::String name = "Radar"; 71 return name; 72 } 73 }; 49 class _OrxonoxExport RadarOverlayElementFactory : public Ogre::OverlayElementFactory{ 50 public: 51 Ogre::OverlayElement* createOverlayElement(const Ogre::String& instanceName){ 52 return new RadarOverlayElement(instanceName); 53 } 54 const Ogre::String& getTypeName(void) const{ 55 static Ogre::String name = "Radar"; 56 return name; 57 } 58 }; 74 59 } 75 60 76 77 78 79 61 #endif -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc
r1314 r1328 57 57 } 58 58 59 void RadarOverlayElement::init RadarOverlayElement(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){59 void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){ 60 60 count_ = 0; 61 61 dimRel_ = dimRel; … … 79 79 point->show(); 80 80 container->addChild(point); 81 point->setMaterialName("Orxonox/Red Point");81 point->setMaterialName("Orxonox/RedDot"); 82 82 point->setDimensions(5,5); 83 83 point->setMetricsMode(Ogre::GMM_PIXELS); … … 95 95 setDimensions(dim_,dim_); 96 96 } 97 98 // void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){99 // dirX_=dirX;100 // dirY_=dirY;101 // dirZ_=dirZ;102 // ortX_=ortX;103 // ortY_=ortY;104 // ortZ_=ortZ;105 // }106 97 107 98 void RadarOverlayElement::update() { -
code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h
r1314 r1328 72 72 virtual void initialise(); 73 73 void update(); 74 void init RadarOverlayElement(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);74 void init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container); 75 75 void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ); 76 76 int newShip(int X, int Y, int Z);
Note: See TracChangeset
for help on using the changeset viewer.