Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 8, 2008, 5:46:52 AM (16 years ago)
Author:
landauf
Message:
  • several small changes in most of the HUD classes (code cleanup): removed obsolete variables, privatized all member variables, removed resizing functioncalls from tick, destroying overlayelements, added some const qualifiers.
  • moved calculation functions for RadarObject-position to Math.h and changed the phi/right/radius format to Vector2. the functions are used too by SpaceShipAI.
  • cycleNavigationFocus takes the nearest object if focus was NULL
  • BarOverlayElement works in both directions (left to right and right to left)
  • fixed bug causing SpaceShipAI to not stop shooting when losing target - this also speeds up orxonox a lot, because there are less projectiles

####################################

!! UPDATE YOUR MEDIA REPOSITORY !!

####################################
…or the BarOverlayElement will look strange

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1535 r1564  
    3434#include <OgreStringConverter.h>
    3535
    36 #include "GraphicsEngine.h"
    3736#include "core/ConsoleCommand.h"
    3837#include "objects/Tickable.h"
    3938#include "objects/SpaceShip.h"
     39#include "util/Math.h"
     40
     41#include "GraphicsEngine.h"
    4042#include "RadarObject.h"
    4143#include "HUD.h"
     
    5355    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    5456        // some initial data
    55         om = &OverlayManager::getSingleton();
    5657        dimRel_ = dimRel;
    5758        leftRel_ = leftRel;
    5859        topRel_ = topRel;
    59         container_ = container;
    6060
    6161        setMetricsMode(GMM_PIXELS);
     
    6363        resize();
    6464
    65         container_->addChild(this);
     65        container->addChild(this);
    6666    }
    6767
    6868    void RadarOverlayElement::resize() {
    6969        // if window is resized, we must adapt these...
    70         windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    71         windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
    72         dim_ = (int) (dimRel_*windowH_);
    73         left_ = (int) (leftRel_*windowW_-dim_/2);
    74         top_ = (int) (topRel_*windowH_-dim_/2);
     70        dim_ = (int) (dimRel_*GraphicsEngine::getSingleton().getWindowHeight());
     71        left_ = (int) (leftRel_*GraphicsEngine::getSingleton().getWindowWidth()-dim_/2);
     72        top_ = (int) (topRel_*GraphicsEngine::getSingleton().getWindowHeight()-dim_/2);
    7573        setPosition(left_, top_);
    7674        setDimensions(dim_,dim_);
     
    7876
    7977    void RadarOverlayElement::update() {
    80         shipPos_ = SpaceShip::getLocalShip()->getPosition();
    81         currentDir_ = SpaceShip::getLocalShip()->getDir();
    82         currentOrth_ = SpaceShip::getLocalShip()->getOrth();
    8378        // iterate through all RadarObjects
    84         for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
    85         // calc position on radar...
    86             float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it));
    87             float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it));
    88             bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it));
     79        for(std::list<RadarObject*>::iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); it++)
     80        {
     81            // calc position on radar...
     82            // set size to fit distance...
     83            float distance = ((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length();
     84            if (distance > 20000) (*it)->getPanel()->setDimensions(1, 1);
     85            else if (distance > 10000) (*it)->getPanel()->setDimensions(2, 2);
     86            else if (distance > 5000) (*it)->getPanel()->setDimensions(3, 3);
     87            else if (distance > 2500) (*it)->getPanel()->setDimensions(4, 4);
     88            else if (distance > 1000) (*it)->getPanel()->setDimensions(5, 5);
     89            else (*it)->getPanel()->setDimensions(6,6);
    8990
    90             // set size to fit distance...
    91             float d = ((*it)->getPosition()-shipPos_).length();
    92             if(d<10000) (*it)->panel_->setDimensions(4,4);
    93             else if(d<20000) (*it)->panel_->setDimensions(3,3);
    94             else (*it)->panel_->setDimensions(2,2);
    95 
    96             if (right){
    97                 (*it)->panel_->setPosition(sin(phi)*radius/
    98                     3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    99             }
    100             else {
    101                 (*it)->panel_->setPosition(-sin(phi)*radius/
    102                     3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    103             }
     91            Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), (*it)->getPosition());
     92            coord = coord * Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture
     93            float dimfactor = dim_ / 2.0;
     94            (*it)->getPanel()->setPosition((1 + coord.x) * dimfactor + left_ - 2,
     95                                           (1 - coord.y) * dimfactor + top_ - 2);
    10496        }
    10597    }
    10698
    107     void RadarOverlayElement::listObjects(){
     99    void RadarOverlayElement::listObjects() const {
    108100        int i = 0;
    109101        COUT(3) << "List of RadarObjects:\n";
    110102        // iterate through all Radar Objects
    111         for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
     103        for(std::list<RadarObject*>::const_iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); ++it){
    112104            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
    113105        }
    114106    }
    115 
    116     float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
    117         return(acos((dir.dotProduct(obj->getPosition() - pos))/
    118         ((obj->getPosition() - pos).length()*dir.length())));
    119     }
    120 
    121     float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
    122         // project difference vector on our plane...
    123         Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);
    124         // ...and find out the angle
    125         return(acos((orth.dotProduct(proj))/
    126               (orth.length()*proj.length())));
    127     }
    128 
    129     bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
    130         if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)
    131             return true;
    132         else return false;
    133     }
    134107}
Note: See TracChangeset for help on using the changeset viewer.