Changeset 1362 for code/trunk/src/orxonox/hud
- Timestamp:
- May 22, 2008, 2:56:48 PM (17 years ago)
- Location:
- code/trunk/src/orxonox/hud
- Files:
-
- 2 edited
- 12 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/HUD.cc
r1070 r1362 1 1 /* 2 3 * > www.orxonox.net < 4 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * ... 26 * 27 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 27 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include <OgreOverlay.h> 31 #include <OgreOverlayContainer.h> 32 #include <OgreOverlayManager.h> 33 #include <OgreSceneNode.h> 34 #include <OgreEntity.h> 35 #include <OgreStringConverter.h> 36 #include "core/Debug.h" 37 #include "objects/SpaceShip.h" 30 38 #include "HUD.h" 31 32 #include <OgreOverlayManager.h> 33 #include <OgreOverlayElement.h> 34 #include <OgreStringConverter.h> 35 39 #include "BarOverlayElement.h" 40 #include "RadarOverlayElement.h" 41 #include "OverlayElementFactories.h" 36 42 37 43 namespace orxonox 38 44 { 39 using namespace Ogre;45 using namespace Ogre; 40 46 41 HUD::HUD(void) 42 { 43 init(); 47 HUD::HUD(int zoom){ 48 om = &Ogre::OverlayManager::getSingleton(); 44 49 45 setTime(99,55); 50 // create Factories 51 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 52 om->addOverlayElementFactory(barOverlayElementFactory); 53 RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); 54 om->addOverlayElementFactory(radarOverlayElementFactory); 46 55 47 setTargetWindowName("HURRA"); 48 setTargetWindowDistance(12); 49 setTargetWindowStatus("Dead"); 50 setTargetWindowDistance(30); 56 orxonoxHUD = om->create("Orxonox/HUD"); 57 container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); 58 // test 59 test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123")); 60 test->show(); 61 test->setMetricsMode(Ogre::GMM_RELATIVE); 62 test->setDimensions(0.8, 0.8); 63 test->setPosition(0.02, 0.02); 64 test->setFontName("Console"); 65 test->setCaption("init"); 51 66 52 setEnergyValue(60); 67 // create energy bar 68 energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar")); 69 energyBar->show(); 70 // create speedo bar 71 speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar")); 72 speedoBar->show(); 73 // create radar 74 radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); 75 radar->show(); 53 76 54 setShieldLeftTopValue(true); 55 setShieldRightTopValue(false); 56 setShieldLeftBottomValue(false); 57 setShieldRightBottomValue(true); 77 // set up screen-wide container 78 container->show(); 58 79 59 setRocket1(11); 60 setRocket2(22); 61 setRocket3(33); 62 setRocket4(44); 80 orxonoxHUD->add2D(container); 81 orxonoxHUD->show(); 82 container->setLeft(0.0); 83 container->setTop(0.0); 84 container->setWidth(1.0); 85 container->setHeight(1.0); 86 container->setMetricsMode(Ogre::GMM_RELATIVE); 87 container->addChild(test); 88 energyBar->init(0.01, 0.94, 0.4, container); 89 energyBar->setValue(1); 90 speedoBar->init(0.01, 0.90, 0.4, container); 91 radar->init(0.5, 0.9, 0.2, container); 92 radar->addObject(Vector3(1500.0, 0.0, 100.0)); 93 radar->addObject(Vector3(0.0, 4000.0, 0.0)); 94 radar->addObject(Vector3(0.0, 0.0, 6800.0)); 95 RadarOverlayElement::cycleFocus(); 96 } 63 97 64 setEnergyDistr(33,33,34); 98 void HUD::tick(float dt) 99 { 100 int d = radar->getDist2Focus()/10; 101 if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d)); 102 else test->setCaption(""); 65 103 66 setPrimar(3);104 energyBar->resize(); 67 105 68 energyDistrPixelX_ = 100; 69 energyDistrPixelY_ = 86; 106 float v = SpaceShip::instance_s->getVelocity().length(); 107 float vmax = SpaceShip::instance_s->getMaxSpeed(); 108 speedoBar->setValue(v/vmax); 109 speedoBar->resize(); 70 110 71 } 111 radar->resize(); 112 radar->update(); 113 } 72 114 73 74 HUD::~HUD( void ){ 75 76 } 77 78 void HUD::setTime(int i, int j){ 79 timeMin_=i; 80 timeSec_=j; 81 timeText_->setCaption(StringConverter::toString(timeMin_) + ":" + StringConverter::toString(timeSec_)); 82 } 83 84 void HUD::setTargetWindowName(std::string i){ 85 targetWindowName_=i; 86 targetWindowNameText_->setCaption( targetWindowName_ ); 87 } 88 89 void HUD::setTargetWindowStatus(std::string i){ 90 targetWindowStatus_=i; 91 targetWindowStatusText_->setCaption( targetWindowStatus_ ); 92 } 93 94 void HUD::setTargetWindowDistance(int i){ 95 targetWindowDistance_=i; 96 targetWindowDistanceText_->setCaption(StringConverter::toString(targetWindowDistance_) + "km" ); 97 } 98 99 void HUD::setTargetWindowHitRating(int i){ 100 targetWindowHitRating_=i; 101 targetWindowHitRatingText_->setCaption(StringConverter::toString(targetWindowHitRating_) + "%" ); 102 } 103 104 void HUD::setEnergyValue(int i){ 105 energyValue_=i; 106 energyLength_->setWidth((int)((float)energyValue_/(float)100*200)); 107 } 108 109 void HUD::setShieldLeftTopValue(bool i){ 110 shieldLeftTopValue_=i; 111 if (shieldLeftTopValue_) shieldLeftTop_->show(); 112 else shieldLeftTop_->hide(); 113 } 114 115 void HUD::setShieldRightTopValue(bool i){ 116 shieldRightTopValue_=i; 117 if (shieldRightTopValue_) shieldRightTop_->show(); 118 else shieldRightTop_->hide(); 119 } 120 121 void HUD::setShieldLeftBottomValue(bool i){ 122 shieldLeftBottomValue_=i; 123 if (shieldLeftBottomValue_) shieldLeftBottom_->show(); 124 else shieldLeftBottom_->hide(); 125 } 126 127 void HUD::setShieldRightBottomValue(bool i){ 128 shieldRightBottomValue_=i; 129 if (shieldRightBottomValue_) shieldRightBottom_->show(); 130 else shieldRightBottom_->hide(); 131 } 132 133 void HUD::setRocket1(int i){ 134 rocket1_=i; 135 rocketNum1_->setCaption(StringConverter::toString(rocket1_)); 136 } 137 138 void HUD::setRocket2(int i){ 139 rocket2_=i; 140 rocketNum2_->setCaption(StringConverter::toString(rocket2_)); 141 } 142 143 void HUD::setRocket3(int i){ 144 rocket3_=i; 145 rocketNum3_->setCaption(StringConverter::toString(rocket3_)); 146 } 147 148 void HUD::setRocket4(int i){ 149 rocket4_=i; 150 rocketNum4_->setCaption(StringConverter::toString(rocket4_)); 151 } 152 153 void HUD::setEnergyDistr(float s, float e, float l){ 154 energyDistrShield_=s; 155 energyDistrEngine_=e; 156 energyDistrLaser_=l; 157 158 float energyDistrShieldInv_ = 100 - energyDistrShield_; 159 float energyDistrEngineInv_ = 100 - energyDistrEngine_; 160 float energyDistrLaserInv_ = 100 - energyDistrLaser_; 161 162 float energyDistrT_ = -energyDistrPixelX_/((energyDistrPixelX_-energyDistrPixelX_/2*energyDistrShieldInv_/(energyDistrShieldInv_+energyDistrEngineInv_))*energyDistrLaserInv_*(energyDistrShieldInv_+energyDistrEngineInv_)/energyDistrShieldInv_/(energyDistrLaserInv_+energyDistrEngineInv_)+energyDistrPixelX_/2+energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_)); 163 float energyDistrX_ = (-energyDistrPixelX_/2-energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_))*energyDistrT_; 164 float energyDistrY_ = energyDistrPixelY_+energyDistrPixelY_*energyDistrLaserInv_/(energyDistrLaserInv_+energyDistrEngineInv_)*energyDistrT_; 165 166 energyDistrPoint_->setLeft((int)energyDistrX_-3); 167 energyDistrPoint_->setTop((int)energyDistrY_-3); 168 169 } 170 171 void HUD::setPrimar(int i){ 172 primarValue_=i; 173 if(i==1){ 174 primarChoice_->setLeft(2); 175 primarChoice_->setWidth(48); 115 HUD::~HUD(void){ 176 116 } 177 if(i==2){ 178 primarChoice_->setLeft(51); 179 primarChoice_->setWidth(49); 180 } 181 else{ 182 primarChoice_->setLeft(101); 183 primarChoice_->setWidth(48); 184 } 185 } 117 } 186 118 187 119 188 120 189 void HUD::init(void)190 {191 timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text");192 121 193 targetWindowNameText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name");194 targetWindowDistanceText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText");195 targetWindowStatusText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText");196 targetWindowHitRatingText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText");197 122 198 energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground");199 123 200 shieldLeftTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftTop");201 shieldRightTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightTop");202 shieldLeftBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftBottom");203 shieldRightBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightBottom");204 205 rocketNum1_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1");206 rocketNum2_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2");207 rocketNum3_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3");208 rocketNum4_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4");209 210 // FIXME: unused vars!211 float energyDistrPixelX_ = 100;212 float energyDistrPixelY_ = 86;213 energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint");214 215 primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice");216 }217 218 } -
code/trunk/src/orxonox/hud/HUD.h
r1056 r1362 1 1 /* 2 3 * > www.orxonox.net < 4 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Yuning Chai 24 * Co-authors: 25 * ... 26 * 27 */ 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Yuning Chai 23 * Co-authors: 24 * Felix Schulthess 25 * 26 */ 27 28 28 29 29 #ifndef _HUD_H__ 30 30 #define _HUD_H__ 31 31 32 #include <string.h> 33 #include <OgreOverlayElement.h> 34 #include <OgreTextAreaOverlayElement.h> 35 #include <OgrePrerequisites.h> 36 32 37 #include "OrxonoxPrereqs.h" 33 34 #include <string> 35 36 #include <OgrePrerequisites.h> 38 #include "core/Tickable.h" 39 #include "BarOverlayElement.h" 40 #include "RadarOverlayElement.h" 37 41 38 42 39 43 namespace orxonox 40 44 { 41 class _OrxonoxExport HUD 42 { 43 private: 44 Ogre::OverlayElement* timeText_; 45 Ogre::OverlayElement* targetWindowNameText_; 46 Ogre::OverlayElement* targetWindowStatusText_; 47 Ogre::OverlayElement* targetWindowDistanceText_; 48 Ogre::OverlayElement* targetWindowHitRatingText_; 49 Ogre::OverlayElement* energyLength_; 50 Ogre::OverlayElement* shieldLeftTop_; 51 Ogre::OverlayElement* shieldRightTop_; 52 Ogre::OverlayElement* shieldLeftBottom_; 53 Ogre::OverlayElement* shieldRightBottom_; 54 Ogre::OverlayElement* rocketNum1_; 55 Ogre::OverlayElement* rocketNum2_; 56 Ogre::OverlayElement* rocketNum3_; 57 Ogre::OverlayElement* rocketNum4_; 58 Ogre::OverlayElement* energyDistrPoint_; 59 Ogre::OverlayElement* primarChoice_; 45 class _OrxonoxExport HUD : public Tickable 46 { 47 private: 48 Ogre::OverlayManager* om; 49 Ogre::Overlay* orxonoxHUD; 50 Ogre::OverlayContainer* container; 51 Ogre::TextAreaOverlayElement* test; 52 BarOverlayElement* energyBar; 53 BarOverlayElement* speedoBar; 54 RadarOverlayElement* radar; 60 55 61 int timeMin_; 62 int timeSec_; 56 public: 57 HUD(int zoom); 58 ~HUD(); 59 virtual void tick(float); 63 60 64 std::string targetWindowName_; 65 std::string targetWindowStatus_; 66 int targetWindowDistance_; 67 int targetWindowHitRating_; 68 69 int energyValue_; 70 71 bool shieldLeftTopValue_; 72 bool shieldRightTopValue_; 73 bool shieldLeftBottomValue_; 74 bool shieldRightBottomValue_; 75 76 int rocket1_; 77 int rocket2_; 78 int rocket3_; 79 int rocket4_; 80 81 float energyDistrShield_; 82 float energyDistrEngine_; 83 float energyDistrLaser_; 84 85 float energyDistrPixelX_; 86 float energyDistrPixelY_; 87 88 int primarValue_; 89 90 public: 91 HUD( void ); 92 ~HUD( void ); 93 void init( void ); 94 95 void setTime(int i, int j); 96 void setTargetWindowName(std::string i); 97 void setTargetWindowStatus(std::string i); 98 void setTargetWindowDistance(int i); 99 void setTargetWindowHitRating(int i); 100 void setEnergyValue(int i); 101 void setShieldLeftTopValue(bool i); 102 void setShieldRightTopValue(bool i); 103 void setShieldLeftBottomValue(bool i); 104 void setShieldRightBottomValue(bool i); 105 void setRocket1(int i); 106 void setRocket2(int i); 107 void setRocket3(int i); 108 void setRocket4(int i); 109 void setEnergyDistr(float s, float e, float l); 110 void setPrimar(int i); 111 112 }; 61 }; 113 62 } 114 63 115 #endif /* _HUD_H__ */64 #endif
Note: See TracChangeset
for help on using the changeset viewer.