Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2008, 12:05:12 AM (16 years ago)
Author:
rgrieder
Message:
  • Radar now working like before
  • but more of a svn save..

There is class called Radar which takes care of the focus and all objects that can be displayed on a Radar.
The actual visual implementation is in HUDRadar.
To make a object radar viewable, simply implement RadarViewable and set the WorldEntitiy pointer in the constructor (assertation will fail otherwise!).
You can also set a camouflage value between 0 and 1 that tells how good a radar can see an object.
The HUDRadar (or another one) on the other side has a sensitivity between 0 and 1. So only if the sensitivity is higher than the camouflage value, the object gets displayed.

File:
1 edited

Legend:

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

    r1604 r1613  
    4242#include "objects/CameraHandler.h"
    4343#include "overlays/OverlayGroup.h"
    44 #include "RadarObject.h"
    45 #include "HUDRadar.h"
     44#include "Radar.h"
    4645
    4746namespace orxonox
     
    4948    CreateFactory(HUDNavigation);
    5049
    51     SetConsoleCommand(HUDNavigation, cycleNavigationFocus, true).setAccessLevel(AccessLevel::User);
    52     SetConsoleCommand(HUDNavigation, releaseNavigationFocus, true).setAccessLevel(AccessLevel::User);
    53 
    54     HUDNavigation* HUDNavigation::instance_s = 0;
     50    //HUDNavigation* HUDNavigation::instance_s = 0;
    5551
    5652    using namespace Ogre;
     
    6157      , aimMarker_(0)
    6258      , navText_(0)
    63       , focus_(0)
    6459    {
    6560        RegisterObject(HUDNavigation);
    6661       
    67         assert(instance_s == 0); // singleton class
    68         HUDNavigation::instance_s = this;
     62        /*assert(instance_s == 0); // singleton class
     63        HUDNavigation::instance_s = this;*/
    6964    }
    7065
     
    8378        }
    8479
    85         HUDNavigation::instance_s = 0;
     80        //HUDNavigation::instance_s = 0;
    8681    }
    8782
     
    117112
    118113            overlay_->add2D(container_);
    119             overlay_->hide();
    120114        }
    121115
     
    181175    void HUDNavigation::tick(float dt)
    182176    {
    183         if (!focus_)
     177        if (!Radar::getInstance().getFocus())
     178        {
     179            this->overlay_->hide();
    184180            return;
     181        }
     182        else
     183        {
     184            this->overlay_->show();
     185        }
    185186
    186187        // set text
    187         int dist = (int) getDist2Focus()/100.0f;
     188        int dist = (int) getDist2Focus();
    188189        navText_->setCaption(convertToString(dist));
    189190        float textLength = convertToString(dist).size() * navText_->getCharHeight() * 0.3;
     
    192193        Matrix4 transformationMatrix = navCam->getProjectionMatrix() * navCam->getViewMatrix();
    193194        // transform to screen coordinates
    194         Vector3 pos = transformationMatrix * focus_->getPosition();
     195        Vector3 pos = transformationMatrix * Radar::getInstance().getFocus()->getWorldPosition();
    195196
    196197        bool outOfView;
     
    266267
    267268            Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(),
    268                     Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity());
     269                    Projectile::getSpeed(), Radar::getInstance().getFocus()->getWorldPosition(), Radar::getInstance().getFocus()->getOrientedVelocity());
    269270
    270271            if (wasOutOfView_)
     
    288289    }
    289290
    290     void HUDNavigation::cycleFocus()
    291     {
    292         if (!focus_)
    293         {
    294             // Get closest object
    295             float distance = (unsigned int) -1;
    296             Vector3 shipPos = SpaceShip::getLocalShip()->getPosition();
    297             it_ = HUDRadar::getInstance().getRadarObjects().begin();
    298 
    299             for (std::list<RadarObject*>::iterator it = HUDRadar::getInstance().getRadarObjects().begin(); it != HUDRadar::getInstance().getRadarObjects().end(); ++it)
    300             {
    301                 float newdist = (*it)->getPosition().squaredDistance(shipPos);
    302                 if (newdist < distance)
    303                 {
    304                     distance = newdist;
    305                     it_ = it;
    306                 }
    307             }
    308 
    309             if (it_ != HUDRadar::getInstance().getRadarObjects().end())
    310             {
    311                 focus_ = *it_;
    312 
    313                 // move the focused object to the begin of the list, so we will iterate through all other objects when cycling
    314                 HUDRadar::getInstance().getRadarObjects().erase(it_);
    315                 HUDRadar::getInstance().getRadarObjects().insert(HUDRadar::getInstance().getRadarObjects().begin(), focus_);
    316                 it_ = HUDRadar::getInstance().getRadarObjects().begin();
    317             }
    318         }
    319         else if (it_ != HUDRadar::getInstance().getRadarObjects().end())
    320         {
    321             focus_->resetMaterial();
    322             ++it_;
    323             if (it_ != HUDRadar::getInstance().getRadarObjects().end())
    324                 focus_ = *it_;
    325             else
    326                 focus_ = 0;
    327         }
    328         else
    329         {
    330             focus_ = 0;
    331         }
    332         updateFocus();
    333     }
    334 
    335     void HUDNavigation::updateFocus()
    336     {
    337         if (focus_)
    338         {
    339             overlay_->show();
    340             focus_->setColour(ColourValue::White);
    341         }
    342         else
    343         {
    344             overlay_->hide();
    345         }
    346     }
    347 
    348     void HUDNavigation::releaseFocus()
    349     {
    350         this->focus_ = 0;
    351         this->updateFocus();
    352     }
    353 
    354291    float HUDNavigation::getDist2Focus() const
    355292    {
    356         if (focus_)
    357             return (focus_->getPosition() - SpaceShip::getLocalShip()->getPosition()).length();
     293        if (Radar::getInstance().getFocus())
     294            return (Radar::getInstance().getFocus()->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();
    358295        else
    359296            return 0;
     
    377314    }
    378315
    379     /*static*/ HUDNavigation& HUDNavigation::getInstance()
     316    /*static*/ /*HUDNavigation& HUDNavigation::getInstance()
    380317    {
    381318        assert(instance_s);
    382319        return *instance_s;
    383     }
    384 
    385     /*static*/ void HUDNavigation::cycleNavigationFocus()
    386     {
    387         // avoid using getInstance because of the assert().
    388         // User might call this fuction even if HUDNavigation doesn't exist.
    389         if (instance_s)
    390             instance_s->cycleFocus();
    391     }
    392 
    393     /*static*/ void HUDNavigation::releaseNavigationFocus()
    394     {
    395         // avoid using getInstance because of the assert().
    396         // User might call this fuction even if HUDNavigation doesn't exist.
    397         if (instance_s)
    398             instance_s->releaseFocus();
    399     }
     320    }*/
    400321}
Note: See TracChangeset for help on using the changeset viewer.