Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1314


Ignore:
Timestamp:
May 17, 2008, 3:05:27 PM (17 years ago)
Author:
FelixSchulthess
Message:

added speedometer.

Location:
code/branches/hud3/src/orxonox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud3/src/orxonox/hud/BarOverlayElement.cc

    r1283 r1314  
    2929#include <OgreOverlayElement.h>
    3030#include <OgrePanelOverlayElement.h>
    31 
    32 
     31#include "GraphicsEngine.h"
    3332#include "BarOverlayElement.h"
    3433
     
    5150
    5251
    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);
     52    void BarOverlayElement::initBarOverlayElement(Real leftRel, Real topRel, Real widthRel, Real heightRel, int dir,  int colour){
     53        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     54        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     55
     56        dir_ = dir;
     57        leftRel_ = leftRel;
     58        topRel_ = topRel;
     59        widthRel_ = widthRel;
     60        heightRel_ = heightRel;
     61
     62        left_ = leftRel_ * windowW_;
     63        top_ = topRel_ * windowH_;
     64        width_ = widthRel_ * windowW_;
     65        height_ = heightRel_ * windowH_;
     66
     67        setMetricsMode(Ogre::GMM_PIXELS);
     68        setPosition(left_,top_);
     69        setDimensions(width_,height_);
     70        setColour(colour);
    6471    }
    6572
    6673
    6774   void BarOverlayElement::reset(int percentage){
    68       switch(dir_){
     75        switch(dir_){
    6976        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       }
     77            setPosition(left_,top_);
     78            setDimensions(width_,height_*percentage/100);
     79            break;
     80        case 2:
     81            setPosition(left_+width_-width_*percentage/100,top_);
     82            setDimensions(width_*percentage/100,height_);
     83            break;
     84        case 3:
     85            setPosition(left_,top_+height_-height_*percentage/100);
     86            setDimensions(width_,height_*percentage/100);
     87            break;
     88        default:
     89            setPosition(left_,top_);
     90            setDimensions(width_*percentage/100,height_);
     91        }
    8592    }
    86        
    87        
     93
     94
    8895    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       }
     96        switch(colour){
     97        case 0:
     98            setMaterialName("Orxonox/Red");
     99            break;
     100        case 1:
     101            setMaterialName("Orxonox/Yellow");
     102            break;
     103        case 2:
     104            setMaterialName("Orxonox/Green");
     105        }
    99106    }
    100107
     
    103110
    104111    SmartBarOverlayElement::~SmartBarOverlayElement(void){}
    105    
    106    
     112
     113
    107114    void SmartBarOverlayElement::initialise(){
    108115      PanelOverlayElement::initialise();
     
    112119      setMetricsMode(Ogre::GMM_PIXELS);
    113120*/  }
    114    
     121
    115122    void SmartBarOverlayElement::initSmartBarOverlayElement(Real left, Real top, Real width, Real height, int dir)
    116123    {
  • code/branches/hud3/src/orxonox/hud/BarOverlayElement.h

    r1283 r1314  
    4444  {
    4545  private:
    46    
     46
    4747    int percentage_;
    48     int dir_;   
     48    int dir_;
    4949    int left_;
    5050    int top_;
    5151    int width_;
    5252    int height_;
     53    Ogre::Real leftRel_;
     54    Ogre::Real topRel_;
     55    Ogre::Real widthRel_;
     56    Ogre::Real heightRel_;
     57    int windowW_, windowH_;
    5358
    5459    static Ogre::String& typeName_s;
     
    6974    virtual void initialise();
    7075
    71     void initBarOverlayElement(Real left, Real top, Real width, Real height,
     76    void initBarOverlayElement(Real leftRel, Real topRel, Real widthRel, Real heightRel,
    7277          int dir,  int colour);
    7378
     
    7782  };
    7883
    79  
     84
    8085  class _OrxonoxExport SmartBarOverlayElement : public BarOverlayElement
    8186  {
     
    8388
    8489    public:
    85      
     90
    8691      SmartBarOverlayElement(const Ogre::String& name);
    8792      virtual ~SmartBarOverlayElement(void);
    8893      virtual void initialise();
    89      
     94
    9095      void initSmartBarOverlayElement(Ogre::Real left, Ogre::Real top, Ogre::Real width, Ogre::Real height, int dir);
    9196      void reset(int percentage);
    92      
     97
    9398  };
    9499}
  • code/branches/hud3/src/orxonox/hud/HUD.cc

    r1310 r1314  
    4848
    4949  HUD::HUD(int zoom){
    50 
    51     Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
     50    om = &Ogre::OverlayManager::getSingleton();
    5251
    5352    BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
    54     overlayManager.addOverlayElementFactory(barOverlayElementFactory);
     53    om->addOverlayElementFactory(barOverlayElementFactory);
    5554
    5655    SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory();
    57     overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory);
     56    om->addOverlayElementFactory(smartBarOverlayElementFactory);
    5857
    5958    RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
    60     overlayManager.addOverlayElementFactory(radarOverlayElementFactory);
     59    om->addOverlayElementFactory(radarOverlayElementFactory);
    6160
    62     Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD");
     61    orxonoxHUD = om->create("Orxonox/HUD");
    6362
    64     Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel"));
     63    container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
    6564
    66     energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter"));
    67     //energyCounter->show();
     65    energyCounter = static_cast<SmartBarOverlayElement*>(om->createOverlayElement("SmartBar", "energyCounter"));
     66    energyCounter->show();
    6867
     68    speedo = static_cast<SmartBarOverlayElement*>(om->createOverlayElement("SmartBar", "speedo"));
     69    speedo->show();
    6970
    70     radar = static_cast<RadarOverlayElement*>(overlayManager.createOverlayElement("Radar", "radar"));
     71    radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
    7172    radar->show();
    7273
     
    108109    test->show();
    109110    test->setMetricsMode(Ogre::GMM_PIXELS);
    110     energyCounterPanel->addChild(test);
     111    container->addChild(test);
    111112
    112113    COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl;
    113114*/
    114115
    115     energyCounterPanel->addChild(energyCounter);
    116     energyCounterPanel->addChild(radar);
    117     energyCounterPanel->show();
     116    container->addChild(energyCounter);
     117    container->addChild(speedo);
     118    container->addChild(radar);
     119    container->show();
    118120
    119     orxonoxOverlay->add2D(energyCounterPanel);
    120     orxonoxOverlay->show();
     121    orxonoxHUD->add2D(container);
     122    orxonoxHUD->show();
    121123
    122124
     
    133135*/
    134136
    135     energyCounterPanel->setLeft(0.0);
    136     energyCounterPanel->setTop(0.0);
    137     energyCounterPanel->setWidth(1.0);
    138     energyCounterPanel->setHeight(1.0);
    139     energyCounterPanel->setMetricsMode(Ogre::GMM_RELATIVE);
     137    container->setLeft(0.0);
     138    container->setTop(0.0);
     139    container->setWidth(1.0);
     140    container->setHeight(1.0);
     141    container->setMetricsMode(Ogre::GMM_RELATIVE);
    140142
    141     energyCounter->initSmartBarOverlayElement(10,10,200,20,BarOverlayElement::LEFT);
    142     energyCounter->reset(80);
     143    energyCounter->initSmartBarOverlayElement(0.01, 0.01, 0.2, 0.02, BarOverlayElement::LEFT);
     144    energyCounter->reset(100);
    143145
    144     radar->initRadarOverlayElement(0.5, 0.8, 0.2, energyCounterPanel);
     146    speedo->initSmartBarOverlayElement(0.01, 0.04, 0.2, 0.02, BarOverlayElement::LEFT);
     147    speedo->reset(80);
     148
     149    radar->initRadarOverlayElement(0.5, 0.9, 0.2, container);
    145150
    146151
     
    149154  void HUD::tick(float dt)
    150155  {
     156      float v = SpaceShip::instance_s->getVelocity().length();
     157      float vmax = SpaceShip::instance_s->getMaxSpeed();
     158      speedo->reset(100*v/vmax);
     159      COUT(3) << 100*v/vmax << std::endl;
    151160      radar->update();
    152161    /*if (this->ogreNode_)
  • code/branches/hud3/src/orxonox/hud/HUD.h

    r1308 r1314  
    3636
    3737#include "OrxonoxPrereqs.h"
    38 
     38#include "objects/SpaceShip.h"
    3939#include "core/Tickable.h"
    4040#include "BarOverlayElement.h"
     
    4444namespace orxonox
    4545{
    46   class _OrxonoxExport HUD : public Tickable
    47   {
    48   private:
     46    class _OrxonoxExport HUD : public Tickable
     47    {
     48        private:
     49            Ogre::OverlayManager* om;
     50            Ogre::Overlay* orxonoxHUD;
     51            Ogre::OverlayContainer* container;
     52            SmartBarOverlayElement* energyCounter;
     53            SmartBarOverlayElement* speedo;
     54            RadarOverlayElement* radar;
    4955
    50   public:
    51     HUD(int zoom);
    52     ~HUD();
     56        public:
     57            HUD(int zoom);
     58            ~HUD();
     59            virtual void tick(float);
    5360
    54     virtual void tick(float);
    55 
    56     SmartBarOverlayElement* energyCounter;
    57 
    58     RadarOverlayElement* radar;
    59   };
     61    };
    6062}
    6163
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc

    r1311 r1314  
    5757    }
    5858
    59     void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, Real dim, Ogre::OverlayContainer* container){
    60 
    61         windowW = GraphicsEngine::getSingleton().getWindowWidth();
    62         windowH = GraphicsEngine::getSingleton().getWindowHeight();
    63         dim_ = dim*windowH;                         //convert relative data to absolute
    64         left_ = left*windowW-dim_/2;                // ...
    65         top_ = top*windowH-dim_/2;                  // ...
     59    void RadarOverlayElement::initRadarOverlayElement(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
    6660        count_ = 0;
     61        dimRel_ = dimRel;
     62        leftRel_ = leftRel;
     63        topRel_ = topRel;
    6764        container_ = container;
    6865
     
    7673        setMetricsMode(Ogre::GMM_PIXELS);
    7774        setMaterialName("Orxonox/Radar");
    78         setPosition(left_, top_);
    79         setDimensions(dim_,dim_);
     75        resize();
    8076
    8177        om = &Ogre::OverlayManager::getSingleton();
     
    8783        point->setMetricsMode(Ogre::GMM_PIXELS);
    8884
     85    }
     86
     87    void RadarOverlayElement::resize() {
     88        // if window is resized, we must adapt these...
     89        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
     90        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
     91        dim_ = dimRel_*windowH_;
     92        left_ = leftRel_*windowW_-dim_/2;
     93        top_ = topRel_*windowH_-dim_/2;
     94        setPosition(left_, top_);
     95        setDimensions(dim_,dim_);
    8996    }
    9097
     
    99106
    100107    void RadarOverlayElement::update() {
     108        resize();
    101109        shipPos_ = SpaceShip::instance_s->getPosition();
    102110        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.h

    r1310 r1314  
    4848    Ogre::PanelOverlayElement* point;
    4949    Ogre::OverlayContainer* container_;
    50     Ogre::OverlayManager* om;       //pointer to the one and only overlay manager
    51     Vector3 initialDir_;                // direction of nose
     50    Ogre::OverlayManager* om;               // pointer to the one and only overlay manager
     51    Vector3 initialDir_;                        // direction of nose
    5252    Vector3 currentDir_;
    53     Vector3 initialOrth_;           // direction of normal
     53    Vector3 initialOrth_;                   // direction of normal
    5454    Vector3 currentOrth_;
    55     Vector3 targetPos_;             //position of target
    56     Vector3 shipPos_;               //position of ship
     55    Vector3 targetPos_;                     // position of target
     56    Vector3 shipPos_;                       // position of ship
    5757
    58     double radius_;                 //defines the radius on the radar
    59     double phi_;                    //defines the angle on the radar
    60     float left_, top_, dim_;
    61     bool right_;                    //checks whether the object is on the right side (since cos is not bijective)
     58    Ogre::Real radius_;                     // radius on the radar
     59    Ogre::Real phi_;                        // angle on the radar
     60    bool right_;                            // checks whether the object is on the right side (since cos is not bijective)
     61    Ogre::Real leftRel_, topRel_, dimRel_;  // relative position/dimension
     62    int left_, top_, dim_;                  // absolute position/dimension
     63    int windowW_, windowH_;                   // absolute window dimensions
    6264    int count_;
    63     int windowW, windowH;
     65
     66    void resize();
    6467
    6568  public:
     
    6972    virtual void initialise();
    7073    void update();
    71     void initRadarOverlayElement(Real left, Real top, Real dim, Ogre::OverlayContainer* container);
     74    void initRadarOverlayElement(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container);
    7275    void setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ);
    7376    int newShip(int X, int Y, int Z);
  • code/branches/hud3/src/orxonox/objects/SpaceShip.cc

    r1310 r1314  
    270270      camName_=camera;
    271271      // change camera attributes here, if you want to ;)
    272       Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    273       Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
    274       //camNode_->setOrientation(q1*q2);
    275272    }
    276273
     
    298295      cam_->setTargetNode(this->getNode());
    299296//        cam->setPosition(Vector3(0,-350,0));
     297      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
     298      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     299      //camNode_->setOrientation(q1*q2);
    300300      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
    301301        this->setBacksync(true);
     
    448448    }
    449449
     450    float SpaceShip::getMaxSpeed() { return maxSpeed_; }
     451
    450452    void SpaceShip::tick(float dt)
    451453    {
  • code/branches/hud3/src/orxonox/objects/SpaceShip.h

    r1310 r1314  
    6464
    6565            void getFocus();
    66             static SpaceShip* instance_s;
    67             static Vector3 getSPosition();
    68             static Quaternion getSOrientation();
    69             static std::string whereAmI();
     66            static SpaceShip* instance_s;
     67            static Vector3 getSPosition();
     68            static Quaternion getSOrientation();
     69            static std::string whereAmI();
    7070            static void setMaxSpeedTest(float value)
    7171                { SpaceShip::instance_s->setMaxSpeed(value); }
     
    7777            bool mouseScrolled      (const MouseState& state) { return true; }
    7878
     79            float getMaxSpeed();
    7980
    8081        private:
Note: See TracChangeset for help on using the changeset viewer.