Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9498


Ignore:
Timestamp:
Dec 10, 2012, 3:06:52 PM (11 years ago)
Author:
smerkli
Message:

Merged baptiste's branch spaceNavigation. Works.

Location:
code/branches/presentationHS12
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationHS12

  • code/branches/presentationHS12/data/defaultConfig/keybindings.ini

    r9016 r9498  
    5555KeyLeftBracket=
    5656KeyLeftControl=mouseLook
    57 KeyLeftShift=
     57KeyLeftShif
    5858KeyLeftWindows=
    5959KeyLessThan=
     
    141141KeyWebSearch=
    142142KeyWebStop=
    143 KeyX=
     143KeyX="selectClosest"
    144144KeyY=
    145145KeyYen=
    146 KeyZ=
     146KeyZ="selectNext"
    147147
    148148[MouseButtons]
  • code/branches/presentationHS12/data/overlays/HUD.oxo

    r7679 r9498  
    5252   value      = 0
    5353  >
    54     <BarColour position = 0.7 colour = "0.2,0.7,0.2" />
     54    <BarColounar position = 0.7 colour = "0.2,0.7,0.2" />
    5555    <BarColour position = 0.4 colour = "0.7,0.5,0.2" />
    5656    <BarColour position = 0.1 colour = "0.7,0.2,0.2" />
     
    6363   textSize      = 0.05
    6464   navMarkerSize = 0.03
    65    aimMarkerSize = 0.04
     65   aimMarkerSize = 0.02
    6666  />
    6767
  • code/branches/presentationHS12/data/overlays/HUDTemplates3.oxo

    r9016 r9498  
    105105     textsize      = 0.05
    106106     navMarkerSize = 0.03
    107      aimMarkerSize = 0.04
     107     aimMarkerSize = 0.02
    108108    />
    109109
  • code/branches/presentationHS12/src/modules/overlays/OverlaysPrereqs.h

    r9348 r9498  
    9191    class HUDBoostBar;
    9292    class HUDTimer;
     93    class HUDAimAssistant;
    9394    class KillMessage;
    9495    class LastManStandingInfos;
  • code/branches/presentationHS12/src/modules/overlays/hud/HUDNavigation.cc

    r9348 r9498  
    3737#include <OgrePanelOverlayElement.h>
    3838
     39#include <typeinfo>
     40
    3941#include "util/Math.h"
    4042#include "util/Convert.h"
     43#include "core/command/ConsoleCommand.h"
    4144#include "core/CoreIncludes.h"
    4245#include "core/XMLPort.h"
     
    5558namespace orxonox
    5659{
    57     bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b)
     60
     61    SetConsoleCommand("HUDNavigation","selectClosest", &HUDNavigation::selectClosestTarget).addShortcut().keybindMode(KeybindMode::OnPress);
     62    SetConsoleCommand("HUDNavigation","selectNext", &HUDNavigation::selectNextTarget).addShortcut().keybindMode(KeybindMode::OnPress);
     63
     64    static bool compareDistance(std::pair<RadarViewable*, unsigned int> a,
     65            std::pair<RadarViewable*, unsigned int> b)
    5866    {
    5967        return a.second < b.second;
    6068    }
    61 
    6269    CreateFactory ( HUDNavigation );
    6370
    64     HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator)
    65     {
    66         RegisterObject(HUDNavigation);
    67         this->setConfigValues();
     71    HUDNavigation* HUDNavigation::localHUD_s = 0;
     72
     73    HUDNavigation::HUDNavigation(BaseObject* creator) :
     74        OrxonoxOverlay(creator)
     75    {
     76        RegisterObject(HUDNavigation)
     77;        this->setConfigValues();
    6878
    6979        // Set default values
    7080        this->setFont("Monofur");
    7181        this->setTextSize(0.05f);
    72         this->setNavMarkerSize(0.05f);
     82        this->setNavMarkerSize(0.03f);
     83        this->setAimMarkerSize(0.02f);
     84
    7385        this->setDetectionLimit(10000.0f);
     86        this->currentMunitionSpeed_ = 2500.0f;
     87
     88        this->closestTarget_ = true;
     89        this->nextTarget_ = false;
     90        HUDNavigation::localHUD_s = this;
    7491    }
    7592
     
    7996        {
    8097            for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();)
    81                 removeObject((it++)->first);
     98            removeObject((it++)->first);
    8299        }
    83100        this->sortedObjectList_.clear();
     
    94111        SUPER(HUDNavigation, XMLPort, xmlelement, mode);
    95112
    96         XMLPortParam(HUDNavigation, "font",           setFont,           getFont,          xmlelement, mode);
    97         XMLPortParam(HUDNavigation, "textSize",       setTextSize,       getTextSize,      xmlelement, mode);
    98         XMLPortParam(HUDNavigation, "navMarkerSize",  setNavMarkerSize,  getNavMarkerSize, xmlelement, mode);
     113        XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode);
     114        XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode);
     115        XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode);
    99116        XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode);
     117        XMLPortParam(HUDNavigation, "aimMarkerSize", setAimMarkerSize, getAimMarkerSize, xmlelement, mode);
    100118    }
    101119
     
    112130        {
    113131            if (it->second.text_ != NULL)
    114                 it->second.text_->setFontName(this->fontName_);
     132            it->second.text_->setFontName(this->fontName_);
    115133        }
    116134    }
     
    132150        {
    133151            if (it->second.text_)
    134                 it->second.text_->setCharHeight(size);
     152            it->second.text_->setCharHeight(size);
    135153        }
    136154    }
     
    144162    {
    145163        if (dist < 600)
    146             dist = 600;
     164        dist = 600;
    147165        return this->getActualSize().x * 900 * this->navMarkerSize_ / dist;
    148166    }
     
    151169    {
    152170        if (dist < 600)
    153             dist = 600;
     171        dist = 600;
    154172        return this->getActualSize().y * 900 * this->navMarkerSize_ / dist;
    155173    }
     
    161179        Camera* cam = CameraManager::getInstance().getActiveCamera();
    162180        if (cam == NULL)
    163             return;
     181        return;
    164182        const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
    165183
    166 
    167184        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
    168             listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
     185        listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
    169186
    170187        this->sortedObjectList_.sort(compareDistance);
     
    172189        unsigned int markerCount = 0;
    173190        bool closeEnough = false; // only display objects that are close enough to be relevant for the player
     191
     192        // if the selected object doesn't exist any more or is now out of range select the closest object
     193        std::map<RadarViewable*, ObjectInfo>::iterator selectedActiveObject = this->activeObjectList_.find(this->selectedTarget_);
     194        if(selectedActiveObject == this->activeObjectList_.end())
     195        {
     196            this->closestTarget_ = true;
     197        }
     198        else if(this->detectionLimit_ < (this->selectedTarget_->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f)
     199        {
     200            this->closestTarget_ = true;
     201            selectedActiveObject->second.selected_ = false;
     202        }
     203
     204        bool nextHasToBeSelected = false;
    174205
    175206        for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt)
     
    178209            closeEnough = listIt->second < this->detectionLimit_;
    179210            // display radarviewables on HUD if the marker limit and max-distance is not exceeded
    180             if (markerCount < this->markerLimit_ && (closeEnough ||  this->detectionLimit_ < 0))
     211            if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0))
    181212            {
    182213                // Get Distance to HumanController and save it in the TextAreaOverlayElement.
     
    196227                    textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
    197228                }
     229
     230                // select the object that aim-assistant indicates
     231                if(this->closestTarget_)
     232                // select the closest object
     233                {
     234                    if(listIt == this->sortedObjectList_.begin())
     235                    {
     236                        it->second.selected_ = true;
     237                        this->selectedTarget_ = it->first;
     238                    }
     239                    else if(it->second.selected_)
     240                    {
     241                        it->second.selected_ = false;
     242                    }
     243
     244                }
     245                else if(this->nextTarget_)
     246                // select the next object in sortedObjectList
     247                {
     248                    if(nextHasToBeSelected){
     249                        it->second.selected_ = true;
     250                        this->selectedTarget_ = it->first;
     251                        nextHasToBeSelected = false;
     252                    }
     253                    else if(it->second.selected_)
     254                    {
     255                        nextHasToBeSelected = true;
     256                        it->second.selected_ = false;
     257
     258                        // check if there's a next object
     259                        listIt++;
     260                        if(listIt != this->sortedObjectList_.end())
     261                        {
     262                            // and if the marker limit and max-distance are not exceeded for it
     263                            if (markerCount + 1 >= this->markerLimit_ ||
     264                                    (listIt->second > this->detectionLimit_ && detectionLimit_ >= 0))
     265                            {
     266                                // otherwise select the closest object
     267                                this->activeObjectList_.find(this->sortedObjectList_.begin()->first)->second.selected_ = true;
     268                                this->selectedTarget_ = it->first;
     269                                nextHasToBeSelected = false;
     270                            }
     271                        }
     272                        listIt--;
     273                    }
     274                }
     275
    198276
    199277                // Transform to screen coordinates
     
    222300                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
    223301                        it->second.wasOutOfView_ = true;
     302                        it->second.target_->hide();
    224303                    }
    225304
     
    284363                        it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
    285364                        it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
     365                        it->second.target_->setDimensions(this->aimMarkerSize_ * this->getActualSize().x, this->aimMarkerSize_ * this->getActualSize().y);
    286366                        it->second.wasOutOfView_ = false;
    287367                    }
     
    295375                    it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);
    296376                    it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
    297                 }
    298 
    299                 // Make sure the overlays are shown
    300                 it->second.panel_->show();
    301                 it->second.text_->show();
     377
     378                    // Make sure the overlays are shown
     379                    it->second.panel_->show();
     380                    it->second.text_->show();
     381
     382                    // Target marker
     383                    const Pawn* pawn = dynamic_cast<const Pawn*>(it->first->getWorldEntity());
     384                    /* Pawn* humanPawn = HumanController::getLocalControllerEntityAsPawn();*/
     385                    if(!it->second.selected_
     386                            || it->first->getRVVelocity().squaredLength() == 0
     387                            || pawn == NULL
     388                            /* TODO : improve getTeam in such a way that it works
     389                             * || humanPawn == NULL
     390                             * || pawn->getTeam() == humanPawn->getTeam()*/)
     391                    {
     392                        // don't show marker for not selected enemies nor if the selected doesn't move
     393                        it->second.target_->hide();
     394                    }
     395                    else // object is selected and moves
     396                    {
     397                        // get the aim position
     398                        Vector3* targetPos = this->toAimPosition(it->first);
     399                        // Transform to screen coordinates
     400                        Vector3 screenPos = camTransform * (*targetPos);
     401                        // Check if the target marker is in view too
     402                        if(screenPos.z > 1 || screenPos.x < -1.0 || screenPos.x > 1.0
     403                                || screenPos.y < -1.0 || screenPos.y > 1.0)
     404                        {
     405                            it->second.target_->hide();
     406                        }
     407                        else
     408                        {
     409                            it->second.target_->setLeft((screenPos.x + 1.0f - it->second.target_->getWidth()) * 0.5f);
     410                            it->second.target_->setTop((-screenPos.y + 1.0f - it->second.target_->getHeight()) * 0.5f);
     411                            it->second.target_->show();
     412                        }
     413                        delete targetPos;
     414                    }
     415
     416                }
    302417            }
    303418            else // do not display on HUD
     419
    304420            {
    305421                it->second.panel_->hide();
    306422                it->second.text_->hide();
     423                it->second.target_->hide();
    307424            }
    308425        }
     426
     427        this->closestTarget_ = false;
     428        this->nextTarget_ = false;
    309429    }
    310430
    311431    /** Overridden method of OrxonoxOverlay.
    312     @details
    313         Usually the entire overlay scales with scale().
    314         Here we obviously have to adjust this.
    315     */
     432     @details
     433     Usually the entire overlay scales with scale().
     434     Here we obviously have to adjust this.
     435     */
    316436    void HUDNavigation::sizeChanged()
    317437    {
     
    326446            if (it->second.text_ != NULL)
    327447                it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale);
     448            if (it->second.target_ != NULL)
     449                it->second.target_->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale);
    328450        }
    329451    }
     
    332454    {
    333455        if (showObject(object) == false)
    334             return;
     456        return;
    335457
    336458        if (this->activeObjectList_.size() >= this->markerLimit_)
    337             if (object == NULL)
    338                 return;
     459        if (object == NULL)
     460        return;
    339461
    340462        // Object hasn't been added yet (we know that)
     
    349471        // Create arrow/marker
    350472        Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
    351                                            .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
     473                .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
    352474        //panel->setMaterialName("Orxonox/NavTDC");
    353475        panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour()));
     
    355477        //panel->setColour(object->getRadarObjectColour());
    356478
     479        // Create target marker
     480        Ogre::PanelOverlayElement* target = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
     481                    .createOverlayElement("Panel", "HUDNavigation_targetMarker_" + getUniqueNumberString()));
     482        target->setMaterialName(TextureGenerator::getMaterialName("target.png", object->getRadarObjectColour()));
     483        target->setDimensions(this->aimMarkerSize_ * xScale, this->aimMarkerSize_ * yScale);
     484
     485        // Create text
    357486        Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
    358                                              .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
     487                .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
    359488        text->setFontName(this->fontName_);
    360489        text->setCharHeight(text->getCharHeight() * yScale);
     
    362491
    363492        panel->hide();
     493        target->hide();
    364494        text->hide();
    365495
    366         ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};
     496        ObjectInfo tempStruct =
     497        {   panel, target, text, false, false, false};
    367498        this->activeObjectList_[object] = tempStruct;
    368499
    369500        this->background_->addChild(panel);
     501        this->background_->addChild(target);
    370502        this->background_->addChild(text);
    371503
     
    381513            // Detach overlays
    382514            this->background_->removeChild(it->second.panel_->getName());
     515            this->background_->removeChild(it->second.target_->getName());
    383516            this->background_->removeChild(it->second.text_->getName());
    384517            // Properly destroy the overlay elements (do not use delete!)
    385518            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
     519            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.target_);
    386520            Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);
    387521            // Remove from the list
     
    409543    {
    410544        if (rv == orxonox_cast<RadarViewable*>(this->getOwner()))
    411             return false;
     545        return false;
    412546        assert(rv->getWorldEntity());
    413547        if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false)
    414             return false;
     548        return false;
    415549        return true;
    416550    }
     
    422556        {
    423557            if (!(*it)->isHumanShip_)
    424                 this->addObject(*it);
     558            this->addObject(*it);
     559        }
     560    }
     561
     562    Vector3* HUDNavigation::toAimPosition(RadarViewable* target) const
     563    {
     564        Vector3 wePosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition();
     565        Vector3 targetPosition = target->getRVWorldPosition();
     566        Vector3 targetSpeed = target->getRVVelocity();
     567        Vector3 relativePosition = targetPosition - wePosition; //Vector from attacker to target
     568
     569        float p_half = relativePosition.dotProduct(targetSpeed)/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_);
     570        float time1 = -p_half + sqrt(p_half * p_half - relativePosition.squaredLength()/(targetSpeed.squaredLength() - this->currentMunitionSpeed_ * this->currentMunitionSpeed_));
     571
     572        Vector3* result = new Vector3(targetPosition + targetSpeed * time1);
     573        return result;
     574    }
     575
     576    void HUDNavigation::selectClosestTarget()
     577    {
     578        if(HUDNavigation::localHUD_s)
     579        {
     580            HUDNavigation::localHUD_s->closestTarget_ = true;
     581        }
     582    }
     583
     584    void HUDNavigation::selectNextTarget()
     585    {
     586        if(HUDNavigation::localHUD_s)
     587        {
     588            HUDNavigation::localHUD_s->nextTarget_ = true;
    425589        }
    426590    }
  • code/branches/presentationHS12/src/modules/overlays/hud/HUDNavigation.h

    r9348 r9498  
    7171                { return this->markerLimit_; }
    7272
     73            static void selectClosestTarget();
     74            static void selectNextTarget();
     75
    7376        private:
    7477            struct ObjectInfo
    7578            {
    7679                Ogre::PanelOverlayElement* panel_;
     80                Ogre::PanelOverlayElement* target_;
    7781                Ogre::TextAreaOverlayElement* text_;
    7882                bool outOfView_;
    7983                bool wasOutOfView_;
     84                bool selected_;
    8085            };
    8186
     
    8590            inline void setNavMarkerSize(float size)
    8691            {
    87                 navMarkerSize_ = size;
     92                this->navMarkerSize_ = size;
    8893                this->sizeChanged();
    8994            }
    9095            inline float getNavMarkerSize() const
    9196                { return navMarkerSize_; }
     97            inline void setAimMarkerSize(float size)
     98            {
     99                this->aimMarkerSize_ = size;
     100                this->sizeChanged();
     101            }
     102            inline float getAimMarkerSize() const
     103                { return aimMarkerSize_; }
    92104            inline void setDetectionLimit(float limit)
    93105                { this->detectionLimit_ = limit; }
     
    104116            float getArrowSizeY(int dist) const;
    105117
     118            Vector3* toAimPosition(RadarViewable* target) const;
     119
    106120            std::map<RadarViewable*, ObjectInfo> activeObjectList_;
    107121            std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_;
    108122
    109123            float navMarkerSize_;
     124            float aimMarkerSize_;
    110125            std::string fontName_;
    111126            float textSize_;
    112127            bool showDistance_;
     128
     129            RadarViewable* selectedTarget_;
     130
     131            bool closestTarget_;
     132            bool nextTarget_;
     133
     134            static HUDNavigation* localHUD_s; //!< This is used as a filter. Only the local HUD should be influenced by the static Console Command functions.
     135
     136
     137            float currentMunitionSpeed_;
    113138
    114139            unsigned int markerLimit_;
  • code/branches/presentationHS12/src/orxonox/interfaces/RadarViewable.cc

    r9257 r9498  
    102102    }
    103103
     104    Vector3 RadarViewable::getRVVelocity() const
     105    {
     106        const WorldEntity* object = this->getWorldEntity();
     107        validate(object);
     108        return object->getVelocity();
     109    }
     110
    104111    void RadarViewable::validate(const WorldEntity* object) const
    105112    {
  • code/branches/presentationHS12/src/orxonox/interfaces/RadarViewable.h

    r9348 r9498  
    113113        const Vector3& getRVWorldPosition() const;
    114114        Vector3 getRVOrientedVelocity() const;
     115        Vector3 getRVVelocity() const;
    115116
    116117        inline void setRadarObjectShape(Shape shape)
Note: See TracChangeset for help on using the changeset viewer.