Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2008, 5:35:34 PM (16 years ago)
Author:
FelixSchulthess
Message:

rewritten navigation algebra… very ugly, and not optimized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/orxonox/hud/Navigation.cc

    r1410 r1411  
    103103        int xPos = xPosRel*windowW_;
    104104        int yPos = yPosRel*windowH_;
     105        int xFromCenter = xPos-windowW_/2;
     106        int yFromCenter = yPos-windowH_/2;
    105107        // is object in view?
     108        float radius = RadarOverlayElement::calcRadius(navCamPos_, currentDir_, currentOrth_, focus_);
     109        bool isRight = (currentDir_.crossProduct(currentOrth_)).dotProduct(focus_->pos_ - navCamPos_)>0;
     110        bool isAbove = currentOrth_.dotProduct(focus_->pos_ - navCamPos_)>0;
    106111        bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1);
    107112        // if object is behind us, it is out of view anyway:
    108         if(!outOfView && RadarOverlayElement::calcRadius(navCamPos_, currentDir_, currentOrth_, focus_)>3.14/2) outOfView = true;
     113        if(!outOfView && radius>3.14/2) outOfView = true;
    109114
    110115        if(outOfView){
    111             // NO!
     116            // object is not in view
    112117            navMarker_->setMaterialName("Orxonox/NavArrows");
    113118            navMarker_->setDimensions(16,16);
    114             float phiUpRight = atan((float)(windowW_)/(float)(windowH_));
    115             // from the angle we find out where to draw the marker
     119            float phiUpperCorner = atan((float)(windowW_)/(float)(windowH_));
     120            // from the angle we find out on which edge to draw the marker
    116121            // and which of the four arrows to take
    117             float phiNav = RadarOverlayElement::calcPhi(navCamPos_, currentDir_, currentOrth_, focus_);
    118             bool right = RadarOverlayElement::calcRight(navCamPos_, currentDir_, currentOrth_, focus_);
    119             if(right){
    120                 if(phiNav<phiUpRight){
    121                     // arrow up
    122                     navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, 0);
     122            float phiNav = atan((float) xFromCenter / (float) yFromCenter);
     123
     124            if(isAbove && isRight){
     125                // top right quadrant
     126                if(-phiNav<phiUpperCorner){
     127                    COUT(3) << "arrow up\n";
     128                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
    123129                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    124130                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
    125131                    navText_->setTop(navMarker_->getHeight());
    126132                }
    127                 else if(phiNav>3.14-phiUpRight){
    128                     // arrow down
    129                     navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    130                     navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    131                     navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
    132                     navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
    133                 }
    134                 else {
    135                     // arrow right
    136                     navMarker_->setPosition(windowW_-16, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
     133                else {
     134                    COUT(3) << "arrow right\n";
     135                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    137136                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    138137                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
     
    140139                }
    141140            }
    142             else{
    143                 if(phiNav<phiUpRight) {
    144                     // arrow up
     141            if(!isAbove && isRight){
     142                // bottom right quadrant
     143                if(phiNav<phiUpperCorner) {
     144                    COUT(3) << "arrow down\n";
     145                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
     146                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     147                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     148                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
     149                }
     150                else {
     151                    COUT(3) << "arrow right\n";
     152                    navMarker_->setPosition(windowW_-16, tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
     153                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
     154                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
     155                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
     156                }
     157            }
     158            if(isAbove && !isRight){
     159                // top left quadrant
     160                if(phiNav<phiUpperCorner){
     161                    COUT(3) << "arrow up\n";
    145162                    navMarker_->setPosition(-tan(phiNav)*windowH_/2+windowW_/2, 0);
    146163                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     
    148165                    navText_->setTop(navMarker_->getHeight());
    149166                }
    150                 else if(phiNav>3.14-phiUpRight) {
    151                     // arrow down
    152                     navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
    153                     navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    154                     navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
    155                     navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
    156                 }
    157                 else {
    158                     // arrow left
     167                else {
     168                    COUT(3) << "arrow left\n";
    159169                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
    160170                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     
    163173                }
    164174            }
     175            if(!isAbove && !isRight){
     176                // bottom left quadrant
     177                if(phiNav>-phiUpperCorner) {
     178                    COUT(3) << "arrow down\n";
     179                    navMarker_->setPosition(tan(phiNav)*windowH_/2+windowW_/2, windowH_-16);
     180                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     181                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     182                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
     183                }
     184                else {
     185                    COUT(3) << "arrow left\n";
     186                    navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW_/2+windowH_/2);
     187                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     188                    navText_->setLeft(navMarker_->getWidth());
     189                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
     190                }
     191            }
    165192        }
    166193        else{
    167             // YES!
     194            // object is in view
    168195            navMarker_->setMaterialName("Orxonox/NavTDC");
    169196            navMarker_->setDimensions(24,24);
Note: See TracChangeset for help on using the changeset viewer.