Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6865


Ignore:
Timestamp:
May 10, 2010, 11:02:12 AM (14 years ago)
Author:
sfluecki
Message:

tick funktion angepasst

Location:
code/branches/hudelements/src/modules/overlays/hud
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hudelements/src/modules/overlays/hud/HUDNavigation.cc

    r6849 r6865  
    2828
    2929#include "HUDNavigation.h"
     30#include <utility>
    3031
    3132#include <string>
     
    5455    {
    5556        RegisterObject(HUDNavigation);
    56 
    57         // create nav text
    58         navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    59             .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
    60 
    61         // create nav marker
    62         navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
    63             .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
    64         navMarker_->setMaterialName("Orxonox/NavArrows");
     57       
     58//         // create nav text
     59//         navText_ = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
     60//             .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
     61//
     62//         // create nav marker
     63//         navMarker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
     64//             .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
     65//         navMarker_->setMaterialName("Orxonox/NavArrows");
    6566
    6667/*
     
    7677        setAimMarkerSize(0.04f);
    7778*/
    78 
    79         background_->addChild(navMarker_);
     79/*
     80        background_->addChild(navMarker_);*/
    8081//        background_->addChild(aimMarker_);
    81         background_->addChild(navText_);
     82//         background_->addChild(navText_);
    8283
    8384        // hide at first
    84         this->setVisible(false);
     85//         this->setVisible(false);
    8586       
    8687       
     
    138139    {
    139140        SUPER(HUDNavigation, tick, dt);
     141       
     142//      updateActiveObjectList(activeObjectList_);
    140143
    141144        // Get radar
    142         Radar* radar = this->getOwner()->getScene()->getRadar();
    143 
    144         if (!radar->getFocus())
    145         {
    146             this->overlay_->hide();
    147             return;
    148         }
    149         else
    150         {
    151             this->overlay_->show();
    152         }
     145//         Radar* radar = this->getOwner()->getScene()->getRadar();
     146//
     147//         if (!radar->getFocus())
     148//         {
     149//             this->overlay_->hide();
     150//             return;
     151//         }
     152//         else
     153//         {
     154//             this->overlay_->show();
     155//         }
    153156
    154157        // set text
    155         int dist = static_cast<int>(getDist2Focus());
    156         navText_->setCaption(multi_cast<std::string>(dist));
    157         float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f;
    158 
    159         orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera();
     158//         int dist = static_cast<int>(getDist2Focus());
     159//         navText_->setCaption(multi_cast<std::string>(dist));
     160//         float textLength = multi_cast<std::string>(dist).size() * navText_->getCharHeight() * 0.3f;
     161
     162      if(!activeObjectList_.empty()) {
     163      for(tempRadarViewable = activeObjectList_.begin(); tempRadarViewable!=activeObjectList_.end(); ++tempRadarViewable)
     164        {
     165       
     166        //get Distance to HumanController and save it in the TextAreaOverlayElement.
     167        int dist = (int)(tempRadarViewable->first->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length();
     168        tempRadarViewable->second.second->setCaption(multi_cast<std::string>(dist));
     169        float textLength = multi_cast<std::string>(dist).size() * tempRadarViewable->second.second->getCharHeight() * 0.3f;
     170         
     171        orxonox::Camera* cam = CameraManager::getInstance().getActiveCamera();
    160172        if (!cam)
    161173            return;
    162174        const Matrix4& transform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
    163175        // transform to screen coordinates
    164         Vector3 pos = transform * radar->getFocus()->getRVWorldPosition();
     176        Vector3 pos = transform * tempRadarViewable->first->getRVWorldPosition();
    165177
    166178        bool outOfView;
     
    184196            if (!wasOutOfView_)
    185197            {
    186                 navMarker_->setMaterialName("Orxonox/NavArrows");
     198                tempRadarViewable->second.first->setMaterialName("Orxonox/NavArrows");
    187199                wasOutOfView_ = true;
    188200            }
     
    194206                    // up
    195207                    float position = pos.x / pos.y + 1.0f;
    196                     navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 0.0f);
    197                     navMarker_->setUV(0.5f, 0.0f, 1.0f, 0.5f);
    198                     navText_->setLeft((position - textLength) * 0.5f);
    199                     navText_->setTop(navMarker_->getHeight());
     208                    tempRadarViewable->second.first->setPosition((position - tempRadarViewable->second.first->getWidth()) * 0.5f, 0.0f);
     209                    tempRadarViewable->second.first->setUV(0.5f, 0.0f, 1.0f, 0.5f);
     210                    tempRadarViewable->second.second->setLeft((position - textLength) * 0.5f);
     211                    tempRadarViewable->second.second->setTop(tempRadarViewable->second.first->getHeight());
    200212                }
    201213                else
     
    203215                    // left
    204216                    float position = pos.y / pos.x + 1.0f;
    205                     navMarker_->setPosition(0.0f, (position - navMarker_->getWidth()) * 0.5f);
    206                     navMarker_->setUV(0.0f, 0.0f, 0.5f, 0.5f);
    207                     navText_->setLeft(navMarker_->getWidth() + 0.01f);
    208                     navText_->setTop((position - navText_->getCharHeight()) * 0.5f);
     217                    tempRadarViewable->second.first->setPosition(0.0f, (position - tempRadarViewable->second.first->getWidth()) * 0.5f);
     218                    tempRadarViewable->second.first->setUV(0.0f, 0.0f, 0.5f, 0.5f);
     219                    tempRadarViewable->second.second->setLeft(tempRadarViewable->second.first->getWidth() + 0.01f);
     220                    tempRadarViewable->second.second->setTop((position - tempRadarViewable->second.second->getCharHeight()) * 0.5f);
    209221                }
    210222            }
     
    215227                    // down
    216228                    float position = -pos.x / pos.y + 1.0f;
    217                     navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight());
    218                     navMarker_->setUV(0.0f, 0.5f, 0.5f, 1.0f);
    219                     navText_->setLeft((position - textLength) * 0.5f);
    220                     navText_->setTop(1.0f - navMarker_->getHeight() - navText_->getCharHeight());
     229                    tempRadarViewable->second.first->setPosition((position - tempRadarViewable->second.first->getWidth()) * 0.5f, 1.0f - navMarker_->getHeight());
     230                    tempRadarViewable->second.first->setUV(0.0f, 0.5f, 0.5f, 1.0f);
     231                    tempRadarViewable->second.second->setLeft((position - textLength) * 0.5f);
     232                    tempRadarViewable->second.second->setTop(1.0f - tempRadarViewable->second.first->getHeight() - tempRadarViewable->second.second->getCharHeight());
    221233                }
    222234                else
     
    224236                    // right
    225237                    float position = -pos.y / pos.x + 1.0f;
    226                     navMarker_->setPosition(1.0f - navMarker_->getWidth(), (position - navMarker_->getHeight()) * 0.5f);
    227                     navMarker_->setUV(0.5f, 0.5f, 1.0f, 1.0f);
    228                     navText_->setLeft(1.0f - navMarker_->getWidth() - textLength - 0.01f);
    229                     navText_->setTop((position - navText_->getCharHeight()) * 0.5f);
     238                    tempRadarViewable->second.first->setPosition(1.0f - tempRadarViewable->second.first->getWidth(), (position - tempRadarViewable->second.first->getHeight()) * 0.5f);
     239                    tempRadarViewable->second.first->setUV(0.5f, 0.5f, 1.0f, 1.0f);
     240                    tempRadarViewable->second.second->setLeft(1.0f - tempRadarViewable->second.first->getWidth() - textLength - 0.01f);
     241                    tempRadarViewable->second.second->setTop((position - tempRadarViewable->second.second->getCharHeight()) * 0.5f);
    230242                }
    231243            }
     
    233245        else
    234246        {
     247         
     248         
    235249            // object is in view
    236250/*
     
    240254            if (wasOutOfView_)
    241255            {
    242                 navMarker_->setMaterialName("Orxonox/NavTDC");
     256                tempRadarViewable->second.first->setMaterialName("Orxonox/NavTDC");
    243257                wasOutOfView_ = false;
    244258            }
    245259
    246260            // object is in view
    247             navMarker_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
    248             navMarker_->setLeft((pos.x + 1.0f - navMarker_->getWidth()) * 0.5f);
    249             navMarker_->setTop((-pos.y + 1.0f - navMarker_->getHeight()) * 0.5f);
     261            tempRadarViewable->second.first->setUV(0.0f, 0.0f, 1.0f, 1.0f);
     262            tempRadarViewable->second.first->setLeft((pos.x + 1.0f - tempRadarViewable->second.first->getWidth()) * 0.5f);
     263            tempRadarViewable->second.first->setTop((-pos.y + 1.0f - tempRadarViewable->second.first->getHeight()) * 0.5f);
    250264
    251265/*
     
    254268            aimMarker_->setTop((-aimpos.y + 1.0f - aimMarker_->getHeight()) * 0.5f);
    255269*/
    256             navText_->setLeft((pos.x + 1.0f + navMarker_->getWidth()) * 0.5f);
    257             navText_->setTop((-pos.y + 1.0f + navMarker_->getHeight()) * 0.5f);
     270            tempRadarViewable->second.second->setLeft((pos.x + 1.0f + tempRadarViewable->second.first->getWidth()) * 0.5f);
     271            tempRadarViewable->second.second->setTop((-pos.y + 1.0f + tempRadarViewable->second.first->getHeight()) * 0.5f);
    258272        }
    259     }
    260 
    261     float HUDNavigation::getDist2Focus() const
    262     {
     273      }
     274    }
     275    }
     276   
     277   
     278    float HUDNavigation::getDist2Focus() const{
     279     
    263280        Radar* radar = this->getOwner()->getScene()->getRadar();
    264281        if (radar->getFocus() && HumanController::getLocalControllerEntityAsPawn())
     
    272289           scales with scale(). Here we obviously have to adjust this.
    273290    */
    274     void HUDNavigation::sizeChanged()
    275     {
    276         // use size to compensate for aspect ratio if enabled.
     291    void HUDNavigation::sizeChanged(){
     292            // use size to compensate for aspect ratio if enabled.
    277293        float xScale = this->getActualSize().x;
    278294        float yScale = this->getActualSize().y;
    279295        if (this->navMarker_)
    280296            navMarker_->setDimensions(navMarkerSize_ * xScale, navMarkerSize_ * yScale);
    281 /*
    282         if (this->aimMarker_)
    283             aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale);
    284 */
     297//         if (this->aimMarker_)
     298//             aimMarker_->setDimensions(aimMarkerSize_ * xScale, aimMarkerSize_ * yScale);
    285299        if (this->navText_)
    286300            navText_->setCharHeight(navText_->getCharHeight() * yScale);
    287301    }
    288302   
    289     void HUDNavigation::addObject(RadarViewable* object)
    290     {
    291         if (object == dynamic_cast<RadarViewable*>(this->getOwner()))
     303   
     304    void HUDNavigation::addObject(RadarViewable* object){
     305            if (object == dynamic_cast<RadarViewable*>(this->getOwner()))
    292306            return;
    293        
     307         
    294308        assert(object);
    295309         
     
    307321        Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton()
    308322             .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
     323             
     324        int dist = (int)(object->getRVWorldPosition() - HumanController::getLocalControllerEntityAsPawn()->getWorldPosition()).length();
     325            activeObjectList_[object].second->setCaption(multi_cast<std::string>(dist));
    309326       
    310327        activeObjectList_[object] = std::make_pair (panel, text) ;     
    311328        activeObjectList_[object].first->show();
    312329        activeObjectList_[object].second->show();
    313         }
    314    
    315         void HUDNavigation::removeObject(RadarViewable* viewable){
    316           assert(activeObjectList_.find(viewable)!=activeObjectList_.end());
     330//      background_->addChild(activeObjectList_[object].first);
     331//      background_->addChild(activeObjectList_[object].second);
     332    }
     333   
     334  void HUDNavigation::removeObject(RadarViewable* viewable){
     335          assert(activeObjectList_.find(viewable)!=activeObjectList_.end());
    317336          activeObjectList_.erase(viewable);
    318         }
     337  }
     338
     339//      void updateActiveObjectList(map activeObjectList_){}
     340//
     341//      void HUDNavigation::objectChanged(RadarViewable* viewable){}
     342//
    319343//     
    320 //         void HUDNavigation::objectChanged(RadarViewable* viewable){}
    321344//         float HUDNavigation::getRadarSensitivity(){}
    322345//         void HUDNavigation::radarTick(float dt){}
    323 //     
    324 
     346       
    325347
    326348}
     349
     350
  • code/branches/hudelements/src/modules/overlays/hud/HUDNavigation.h

    r6849 r6865  
    3939#include "overlays/OrxonoxOverlay.h"
    4040
    41 #include <pair>
    4241#include <vector>
    4342
     
    6564        void positionChanged() { }
    6665       
     66//      void updateActiveObjectList(map activeObjectList_);
     67       
    6768       
    6869
     
    8687        float getDist2Focus() const;
    8788        void getSingleton();
    88         void getSingleton();
     89
    8990   
    9091        void updateActiveObjectMap();
     
    99100        bool wasOutOfView_;                         //!< Performance booster variable: setMaterial is not cheap
    100101       
    101         std::map<RadarViewable*, std::pair<Ogre::PanelOverlayElement*, Ogre::TextAreaOverlayElement*> > activeObjectList_;
     102        typedef std::map<RadarViewable*, std::pair<Ogre::PanelOverlayElement*, Ogre::TextAreaOverlayElement*> > activeObjectListType;
     103        activeObjectListType activeObjectList_;
     104        activeObjectListType::iterator tempRadarViewable;
    102105       
    103106    };
Note: See TracChangeset for help on using the changeset viewer.