Changeset 1281
- Timestamp:
- May 15, 2008, 2:14:28 PM (17 years ago)
- Location:
- code/branches/hud3/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud3/src/orxonox/CMakeLists.txt
r1278 r1281 6 6 console/InGameConsole.cc 7 7 hud/HUD.cc 8 hud/BarOverlayElement.cc 9 hud/RadarOverlayElement.cc 10 hud/RadarOverlayElement.cc 8 11 particle/ParticleInterface.cc 9 12 tolua/tolua_bind.cc -
code/branches/hud3/src/orxonox/Orxonox.cc
r1272 r1281 347 347 // Load the HUD 348 348 COUT(3) << "Orxonox: Loading HUD..." << std::endl; 349 Ogre::Overlay* hudOverlay = Ogre::OverlayManager::getSingleton().getByName("Orxonox/HUD1.2"); 350 orxonoxHUD_ = new HUD(); 351 orxonoxHUD_->setEnergyValue(20); 352 orxonoxHUD_->setEnergyDistr(20,20,60); 353 hudOverlay->show(); 349 orxonoxHUD_ = new HUD(1); 354 350 355 351 COUT(3) << "Orxonox: Loading Console..." << std::endl; … … 487 483 488 484 // show the current time in the HUD 489 orxonoxHUD_->setTime((int)now, 0);490 orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber());485 // orxonoxHUD_->setTime((int)now, 0); 486 // orxonoxHUD_->setRocket2(ogreRoot.getCurrentFrameNumber()); 491 487 if (eventTimes[3].back() - eventTimes[3].front() != 0) 492 orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front())));488 // orxonoxHUD_->setRocket1((int)(50000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 493 489 494 490 // Iterate through all Tickables and call their tick(dt) function -
code/branches/hud3/src/orxonox/hud/HUD.cc
r1070 r1281 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 * ... 25 * 26 */ 27 28 28 29 29 #include "OrxonoxStableHeaders.h" 30 #include <OgreOverlay.h> 31 #include <OgreOverlayContainer.h> 32 #include <OgreOverlayManager.h>ma 33 #include <OgreSceneNode.h> 34 #include <OgreEntity.h> 35 #include "core/Debug.h" 36 30 37 #include "HUD.h" 31 32 #include <OgreOverlayManager.h> 33 #include <OgreOverlayElement.h> 34 #include <OgreStringConverter.h> 38 #include "BarOverlayElement.h" 39 #include "RadarOverlayElement.h" 40 #include "OverlayElementFactories.h" 41 // ugly hack 42 #include "Orxonox.h" 35 43 36 44 … … 39 47 using namespace Ogre; 40 48 41 HUD::HUD(void) 42 { 43 init(); 49 HUD::HUD(int zoom){ 44 50 45 setTime(99,55); 51 Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); 52 53 BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); 54 overlayManager.addOverlayElementFactory(barOverlayElementFactory); 55 56 SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory(); 57 overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory); 58 59 RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); 60 overlayManager.addOverlayElementFactory(radarOverlayElementFactory); 61 62 Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); 46 63 47 setTargetWindowName("HURRA"); 48 setTargetWindowDistance(12); 49 setTargetWindowStatus("Dead"); 50 setTargetWindowDistance(30); 64 Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel")); 65 66 energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter")); 67 energyCounter->show(); 68 69 70 radar = static_cast<RadarOverlayElement*>(overlayManager.createOverlayElement("Radar", "radar")); 71 radar->show(); 51 72 52 setEnergyValue(60); 73 74 /* TextAreaOverlayElement* test = static_cast<TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "test")); 75 76 int dirX, dirY, dirZ; //flying direction 77 int ortX, ortY, ortZ; //orthogonal direction 78 int dX, dY, dZ; //distance between main ship and the object 79 int vecX, vecY, vecZ; //vector product dir X ort 80 double alpha; //defines the radius in the radar 81 double beta; //defines the angle in the radar 82 bool right; //checks whether the object is on the right side (since cos is not bijective) 83 84 dirX = 1; 85 dirY = 0; 86 dirZ = 0; 87 88 ortX = 0; 89 ortY = 0; 90 ortZ = 1; 91 92 dX = -2; 93 dY = 2; 94 dZ = 0; 95 96 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)))); 97 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)))); 98 vecX = dirY*ortZ - dirZ*ortY; 99 vecY = dirZ*ortX - dirX*ortZ; 100 vecZ = dirX*ortY - dirY*ortX; 101 102 if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;} 103 else right=false; 104 105 test->setCaption("hell"); 106 test->setPosition(10,10); 107 test->setDimensions(20,20); 108 test->show(); 109 test->setMetricsMode(Ogre::GMM_PIXELS); 110 energyCounterPanel->addChild(test); 111 112 COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl; 113 */ 114 115 energyCounterPanel->addChild(energyCounter); 116 energyCounterPanel->addChild(radar); 117 energyCounterPanel->show(); 118 119 orxonoxOverlay->add2D(energyCounterPanel); 120 orxonoxOverlay->show(); 53 121 54 setShieldLeftTopValue(true); 55 setShieldRightTopValue(false); 56 setShieldLeftBottomValue(false); 57 setShieldRightBottomValue(true); 122 123 124 // important: don't use SceneManager to create the node! but register the creator scene manager. 125 /* ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely"); 126 127 ogreNode_->setPosition(80,-60,-200); 128 ogreNode_->setScale(0.4,0.4,0.4); 129 // ugly hack, but I haven't figured out yet how we could change this, since we really need the 130 // scene manager.. 131 ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh")); 132 // orxonoxOverlay->add3D(ogreNode_); 133 */ 134 135 energyCounterPanel->setLeft(-50); 136 energyCounterPanel->setTop(10); 137 energyCounterPanel->setWidth(100); 138 energyCounterPanel->setHeight(20); 139 energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER); 140 energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS); 141 142 energyCounter->initSmartBarOverlayElement(-100,0,200,20,BarOverlayElement::LEFT); 143 energyCounter->reset(80); 144 145 radar->initRadarOverlayElement(10,10,200,energyCounterPanel); 58 146 59 setRocket1(11); 60 setRocket2(22); 61 setRocket3(33); 62 setRocket4(44); 63 64 setEnergyDistr(33,33,34); 65 66 setPrimar(3); 67 68 energyDistrPixelX_ = 100; 69 energyDistrPixelY_ = 86; 70 147 71 148 } 72 149 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); 176 } 177 if(i==2){ 178 primarChoice_->setLeft(51); 179 primarChoice_->setWidth(49); 180 } 181 else{ 182 primarChoice_->setLeft(101); 183 primarChoice_->setWidth(48); 150 /* void HUD::tick(float dt) 151 { 152 if (this->ogreNode_) 153 { 154 this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 155 this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 156 this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); 184 157 } 185 158 } 159 */ 160 HUD::~HUD(void){} 186 161 187 162 188 163 189 void HUD::init(void) 190 { 191 timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text"); 164 } 192 165 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 166 198 energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground");199 167 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 168 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 169 210 // FIXME: unused vars!211 float energyDistrPixelX_ = 100;212 float energyDistrPixelY_ = 86;213 energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint");214 170 215 primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice");216 }217 218 } -
code/branches/hud3/src/orxonox/hud/HUD.h
r1056 r1281 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 * ... 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 38 34 #include <string>35 36 #include <OgrePrerequisites.h>39 #include "core/Tickable.h" 40 #include "BarOverlayElement.h" 41 #include "RadarOverlayElement.h" 37 42 38 43 39 44 namespace orxonox 40 45 { 41 class _OrxonoxExport HUD 46 class _OrxonoxExport HUD// : Tickable 42 47 { 43 48 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_;60 61 int timeMin_;62 int timeSec_;63 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 49 90 50 public: 91 HUD( void ); 92 ~HUD( void ); 93 void init( void ); 51 HUD(int zoom); 52 ~HUD(); 94 53 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); 54 // virtual void tick(float); 111 55 56 SmartBarOverlayElement* energyCounter; 57 58 RadarOverlayElement* radar; 59 // Ogre::SceneNode* ogreNode_; 112 60 }; 113 } 61 } 114 62 115 #endif /* _HUD_H__ */63 #endif
Note: See TracChangeset
for help on using the changeset viewer.