Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 17, 2008, 2:43:23 PM (17 years ago)
Author:
chaiy
Message:

Bars finally work

Location:
code/branches/hud2/src/orxonox
Files:
5 added
5 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud2/src/orxonox/CMakeLists.txt

    r991 r1099  
    55#  SpaceshipSteering.cc
    66  hud/HUD.cc
    7   hud/Bar.cc
     7  hud/BarOverlayElement.cc
    88  particle/ParticleInterface.cc
    99  tools/BillboardSet.cc
  • code/branches/hud2/src/orxonox/Orxonox.cc

    r1002 r1099  
    311311    //orxonoxHUD_->setEnergyDistr(20,20,60);
    312312    //hudOverlay->show();
     313   
     314   
    313315
    314316        /*
  • code/branches/hud2/src/orxonox/hud/HUD.cc

    r1012 r1099  
    3030#include <OgreOverlay.h>
    3131#include <OgreOverlayContainer.h>
    32 #include <OgreOverlayManager.h>
     32#include <OgreOverlayManager.h>ma
    3333#include <OgreSceneNode.h>
    3434#include <OgreEntity.h>
    3535
    3636#include "HUD.h"
    37 #include "Bar.h"
    38 #include "Factories.h"
     37#include "BarOverlayElement.h"
     38#include "OverlayElementFactories.h"
    3939// ugly hack
    4040#include "Orxonox.h"
     
    4545  using namespace Ogre;
    4646
    47 
    48 
    49 
    50 
    5147  HUD::HUD(int zoom){
    5248
    5349    Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
    54 
    55 //    energyCounter = new Bar(0,0,100,20,Bar::LEFT,Bar::YELLOW,"Orxonox/HUD/energyCounterPanel/energyCounter");
     50   
     51    BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
     52    overlayManager.addOverlayElementFactory(barOverlayElementFactory);
     53   
     54    SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory();
     55    overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory);
     56   
     57    Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD");
    5658
    5759    Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel"));
     60   
     61    energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter"));
     62    energyCounter->show();
     63   
     64    energyCounterPanel->addChild(energyCounter);
     65    energyCounterPanel->show();
     66
     67    orxonoxOverlay->add2D(energyCounterPanel);
     68    orxonoxOverlay->show();
     69
     70    // important: don't use SceneManager to create the node! but register the creator scene manager.
     71/*    ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely");
     72   
     73    ogreNode_->setPosition(80,-60,-200);
     74    ogreNode_->setScale(0.4,0.4,0.4);
     75    // ugly hack, but I haven't figured out yet how we could change this, since we really need the
     76    // scene manager..
     77    ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh"));
     78//    orxonoxOverlay->add3D(ogreNode_);
     79*/
     80   
    5881    energyCounterPanel->setLeft(-50);
    5982    energyCounterPanel->setTop(10);
     
    6285    energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER);
    6386    energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS);       
    64     energyCounterPanel->show();
    65 //    energyCounterPanel->addChild(energyCounter->element);
     87       
     88    energyCounter->initSmartBarOverlayElement(-100,0,200,20,BarOverlayElement::LEFT);
     89    energyCounter->reset(80);
    6690
    67     BarOverlayElementFactory *factory = new BarOverlayElementFactory();
    68     overlayManager.addOverlayElementFactory(factory);
    69     Ogre::OverlayElement* BarElement = overlayManager.createOverlayElementFromFactory("Bar", "BarElement");
    70 
    71     energyCounterPanel->addChild(BarElement);
    72 
    73     Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD");
    74     orxonoxOverlay->add2D(energyCounterPanel);
    75 
    76     // important: don't use SceneManager to create the node! but register the creator scene manager.
    77     ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely");
    7891   
    79     ogreNode_->setPosition(80,-60,-200);
    80     ogreNode_->setScale(0.4,0.4,0.4);
    81     // ugly hack, but I haven't figured out yet how we could change this, since we really need the
    82     // scene manager..
    83     ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh"));
    84     orxonoxOverlay->add3D(ogreNode_);
    85 
    86     orxonoxOverlay->show();
    8792  }
    8893
    89   void HUD::tick(float dt)
     94/*  void HUD::tick(float dt)
    9095  {
    9196    if (this->ogreNode_)
     
    96101    }
    97102  }
    98 
     103*/
    99104  HUD::~HUD(void){}
    100105
     
    108113
    109114
    110 /*#include "OrxonoxStableHeaders.h"
    111 
    112 #include <OgreOverlayManager.h>
    113 #include <OgreOverlayElement.h>
    114 #include <OgreStringConverter.h>
    115 
    116 #include "HUD.h"
    117 #include "Bar.h"
    118 
    119 namespace orxonox
    120 {
    121   using namespace Ogre;
    122 
    123   HUD::HUD(void)
    124   {
    125     init();
    126 
    127     setTime(99,55);
    128 
    129     setTargetWindowName("HURRA");
    130     setTargetWindowDistance(12);
    131     setTargetWindowStatus("Dead");
    132     setTargetWindowDistance(30);
    133 
    134     setEnergyValue(60);
    135 
    136     setShieldLeftTopValue(true);
    137     setShieldRightTopValue(false);
    138     setShieldLeftBottomValue(false);
    139     setShieldRightBottomValue(true);
    140 
    141     setRocket1(11);
    142     setRocket2(22);
    143     setRocket3(33);
    144     setRocket4(44);
    145 
    146     setEnergyDistr(33,33,34);
    147 
    148     setPrimar(3);
    149 
    150     energyDistrPixelX_ = 100;
    151     energyDistrPixelY_ = 86;
    152 
    153 
    154   }
    155 
    156 
    157   HUD::~HUD( void ){
    158 
    159   }
    160 
    161   void HUD::setTime(int i, int j){
    162     timeMin_=i;
    163     timeSec_=j;
    164     timeText_->setCaption(StringConverter::toString(timeMin_) + ":" + StringConverter::toString(timeSec_));
    165   }
    166 
    167   void HUD::setTargetWindowName(std::string i){
    168     targetWindowName_=i;
    169     targetWindowNameText_->setCaption( targetWindowName_ );
    170   }
    171 
    172   void HUD::setTargetWindowStatus(std::string i){
    173     targetWindowStatus_=i;
    174     targetWindowStatusText_->setCaption( targetWindowStatus_ );
    175   }
    176 
    177   void HUD::setTargetWindowDistance(int i){
    178     targetWindowDistance_=i;
    179     targetWindowDistanceText_->setCaption(StringConverter::toString(targetWindowDistance_) + "km" );
    180   }
    181 
    182   void HUD::setTargetWindowHitRating(int i){
    183     targetWindowHitRating_=i;
    184     targetWindowHitRatingText_->setCaption(StringConverter::toString(targetWindowHitRating_) + "%" );
    185   }
    186 
    187   void HUD::setEnergyValue(int i){
    188     energyValue_=i;
    189     energyLength_->setWidth((int)((float)energyValue_/(float)100*200));
    190   }
    191 
    192   void HUD::setShieldLeftTopValue(bool i){
    193     shieldLeftTopValue_=i;
    194     if (shieldLeftTopValue_) shieldLeftTop_->show();
    195     else shieldLeftTop_->hide();
    196   }
    197 
    198   void HUD::setShieldRightTopValue(bool i){
    199     shieldRightTopValue_=i;
    200     if (shieldRightTopValue_) shieldRightTop_->show();
    201     else shieldRightTop_->hide();
    202   }
    203 
    204   void HUD::setShieldLeftBottomValue(bool i){
    205     shieldLeftBottomValue_=i;
    206     if (shieldLeftBottomValue_) shieldLeftBottom_->show();
    207     else shieldLeftBottom_->hide();
    208   }
    209 
    210   void HUD::setShieldRightBottomValue(bool i){
    211     shieldRightBottomValue_=i;
    212     if (shieldRightBottomValue_) shieldRightBottom_->show();
    213     else shieldRightBottom_->hide();
    214   }
    215 
    216   void HUD::setRocket1(int i){
    217     rocket1_=i;
    218     rocketNum1_->setCaption(StringConverter::toString(rocket1_));
    219   }
    220 
    221   void HUD::setRocket2(int i){
    222     rocket2_=i;
    223     rocketNum2_->setCaption(StringConverter::toString(rocket2_));
    224   }
    225 
    226   void HUD::setRocket3(int i){
    227     rocket3_=i;
    228     rocketNum3_->setCaption(StringConverter::toString(rocket3_));
    229   }
    230 
    231   void HUD::setRocket4(int i){
    232     rocket4_=i;
    233     rocketNum4_->setCaption(StringConverter::toString(rocket4_));
    234   }
    235 
    236   void HUD::setEnergyDistr(float s, float e, float l){
    237     energyDistrShield_=s;
    238     energyDistrEngine_=e;
    239     energyDistrLaser_=l;
    240 
    241     float energyDistrShieldInv_ = 100 - energyDistrShield_;
    242     float energyDistrEngineInv_ = 100 - energyDistrEngine_;
    243     float energyDistrLaserInv_ = 100 - energyDistrLaser_;
    244 
    245     float energyDistrT_ = -energyDistrPixelX_/((energyDistrPixelX_-energyDistrPixelX_/2*energyDistrShieldInv_/(energyDistrShieldInv_+energyDistrEngineInv_))*energyDistrLaserInv_*(energyDistrShieldInv_+energyDistrEngineInv_)/energyDistrShieldInv_/(energyDistrLaserInv_+energyDistrEngineInv_)+energyDistrPixelX_/2+energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_));
    246     float energyDistrX_ = (-energyDistrPixelX_/2-energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_))*energyDistrT_;
    247     float energyDistrY_ = energyDistrPixelY_+energyDistrPixelY_*energyDistrLaserInv_/(energyDistrLaserInv_+energyDistrEngineInv_)*energyDistrT_;
    248 
    249     energyDistrPoint_->setLeft((int)energyDistrX_-3);
    250     energyDistrPoint_->setTop((int)energyDistrY_-3);
    251 
    252   }
    253 
    254   void HUD::setPrimar(int i){
    255     primarValue_=i;
    256     if(i==1){
    257       primarChoice_->setLeft(2);
    258       primarChoice_->setWidth(48);
    259     }
    260     if(i==2){
    261       primarChoice_->setLeft(51);
    262       primarChoice_->setWidth(49);
    263     }
    264     else{
    265       primarChoice_->setLeft(101);
    266       primarChoice_->setWidth(48);
    267     }
    268   }
    269 
    270 
    271 
    272   void HUD::init(void)
    273   {
    274     timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text");
    275 
    276     targetWindowNameText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name");
    277     targetWindowDistanceText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText");
    278     targetWindowStatusText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText");
    279     targetWindowHitRatingText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText");
    280 
    281     energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground");
    282 
    283     shieldLeftTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftTop");
    284     shieldRightTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightTop");
    285     shieldLeftBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftBottom");
    286     shieldRightBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightBottom");
    287 
    288     rocketNum1_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1");
    289     rocketNum2_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2");
    290     rocketNum3_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3");
    291     rocketNum4_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4");
    292 
    293     // FIXME: unused vars!
    294     float energyDistrPixelX_ = 100;
    295     float energyDistrPixelY_ = 86;
    296     energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint");
    297 
    298     primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice");
    299   }
    300 
    301 }
    302 */
  • code/branches/hud2/src/orxonox/hud/HUD.h

    r1012 r1099  
    3838
    3939#include "core/Tickable.h"
    40 #include "Bar.h"
     40#include "BarOverlayElement.h"
    4141
    4242
    4343namespace orxonox
    4444{
    45   class _OrxonoxExport HUD : Tickable
     45  class _OrxonoxExport HUD// : Tickable
    4646  {
    4747  private:
     
    5151    ~HUD();
    5252
    53     virtual void tick(float);
     53//    virtual void tick(float);
    5454
    55     Bar* energyCounter;
    56     Ogre::SceneNode* ogreNode_;
     55    SmartBarOverlayElement* energyCounter;
     56//    Ogre::SceneNode* ogreNode_;
    5757  };
    5858}       
    5959
    6060
    61 
    62 
    63 
    64 
    65 
    66 
    67 
    6861#endif
    69 
    70 /*#ifndef _HUD_H__
    71 #define _HUD_H__
    72 
    73 #include <string>
    74 
    75 #include <OgrePrerequisites.h>
    76 
    77 #include "../OrxonoxPrereqs.h"
    78 
    79 
    80 namespace orxonox
    81 {
    82   class _OrxonoxExport HUD
    83   {
    84   private:
    85     Ogre::OverlayElement* timeText_;
    86     Ogre::OverlayElement* targetWindowNameText_;
    87     Ogre::OverlayElement* targetWindowStatusText_;
    88     Ogre::OverlayElement* targetWindowDistanceText_;
    89     Ogre::OverlayElement* targetWindowHitRatingText_;
    90     Ogre::OverlayElement* energyLength_;
    91     Ogre::OverlayElement* shieldLeftTop_;
    92     Ogre::OverlayElement* shieldRightTop_;
    93     Ogre::OverlayElement* shieldLeftBottom_;
    94     Ogre::OverlayElement* shieldRightBottom_;
    95     Ogre::OverlayElement* rocketNum1_;
    96     Ogre::OverlayElement* rocketNum2_;
    97     Ogre::OverlayElement* rocketNum3_;
    98     Ogre::OverlayElement* rocketNum4_;
    99     Ogre::OverlayElement* energyDistrPoint_;
    100     Ogre::OverlayElement* primarChoice_;
    101 
    102     int timeMin_;
    103     int timeSec_;
    104 
    105     std::string targetWindowName_;
    106     std::string targetWindowStatus_;
    107     int targetWindowDistance_;
    108     int targetWindowHitRating_;
    109 
    110     int energyValue_;
    111 
    112     bool shieldLeftTopValue_;
    113     bool shieldRightTopValue_;
    114     bool shieldLeftBottomValue_;
    115     bool shieldRightBottomValue_;
    116 
    117     int rocket1_;
    118     int rocket2_;
    119     int rocket3_;
    120     int rocket4_;
    121 
    122     float energyDistrShield_;
    123     float energyDistrEngine_;
    124     float energyDistrLaser_;
    125 
    126     float energyDistrPixelX_;
    127     float energyDistrPixelY_;
    128 
    129     int primarValue_;
    130 
    131   public:
    132     HUD( void );
    133     ~HUD( void );
    134     void init( void );
    135 
    136     void setTime(int i, int j);
    137     void setTargetWindowName(std::string i);
    138     void setTargetWindowStatus(std::string i);
    139     void setTargetWindowDistance(int i);
    140     void setTargetWindowHitRating(int i);
    141     void setEnergyValue(int i);
    142     void setShieldLeftTopValue(bool i);
    143     void setShieldRightTopValue(bool i);
    144     void setShieldLeftBottomValue(bool i);
    145     void setShieldRightBottomValue(bool i);
    146     void setRocket1(int i);
    147     void setRocket2(int i);
    148     void setRocket3(int i);
    149     void setRocket4(int i);
    150     void setEnergyDistr(float s, float e, float l);
    151     void setPrimar(int i);
    152 
    153   };
    154 }
    155 
    156 #endif /* _HUD_H__ */
Note: See TracChangeset for help on using the changeset viewer.