Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2008, 12:24:30 AM (16 years ago)
Author:
FelixSchulthess
Message:

moved to spaceship what belonged there

File:
1 edited

Legend:

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

    r1399 r1400  
    5959        container_ = container;
    6060
    61         // these have to fit the data in the level
    62         shipPos_ = Vector3(0.0, 0.0, 0.0);
    63         initialDir_ = Vector3(1.0, 0.0, 0.0);
    64         currentDir_ = initialDir_;
    65         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    66         currentOrth_ = initialOrth_;
    67         plane = Plane(currentDir_, shipPos_);
    68 
    6961        setMetricsMode(GMM_PIXELS);
    7062        setMaterialName("Orxonox/Radar");
     
    8678
    8779    void RadarOverlayElement::update() {
    88         shipPos_ = SpaceShip::instance_s->getPosition();
    89         currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;
    90                 currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
    91         plane = Plane(currentDir_, shipPos_);
     80        shipPos_ = SpaceShip::getLocalShip()->getPosition();
     81        currentDir_ = SpaceShip::getLocalShip()->getDir();
     82                currentOrth_ = SpaceShip::getLocalShip()->getOrth();
    9283        RadarObject* ro = HUD::getSingleton().getFirstRadarObject();
    9384        // iterate through all RadarObjects
    9485                while(ro != NULL){
    9586                    // calc position on radar...
    96             ro->radius_ = calcRadius(ro);
    97             ro->phi_ = calcPhi(ro);
    98             ro->right_ = calcRight(ro);
     87            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro);
     88            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro);
     89            bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro);
    9990
    10091            // set size to fit distance...
     
    10596            else ro->panel_->setDimensions(1,1);
    10697
    107             if (ro->right_){
    108                 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
    109                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     98            if (right){
     99                ro->panel_->setPosition(sin(phi)*radius/
     100                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    110101            }
    111102            else {
    112                 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
    113                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     103                ro->panel_->setPosition(-sin(phi)*radius/
     104                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    114105            }
    115106            ro = ro->next;
     
    128119        }
    129120
    130         float RadarOverlayElement::calcRadius(RadarObject* obj){
    131             return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
    132                         ((obj->pos_ - shipPos_).length()*currentDir_.length())));
     121        float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     122            return(acos((dir.dotProduct(obj->pos_ - pos))/
     123                        ((obj->pos_ - pos).length()*dir.length())));
    133124        }
    134125
    135         float RadarOverlayElement::calcPhi(RadarObject* obj){
     126        float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
    136127            // project difference vector on our plane...
    137             Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
     128            Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos);
    138129            // ...and find out the angle
    139             return(acos((currentOrth_.dotProduct(proj))/
    140             (currentOrth_.length()*proj.length())));
     130            return(acos((orth.dotProduct(proj))/
     131            (orth.length()*proj.length())));
    141132        }
    142133
    143         bool RadarOverlayElement::calcRight(RadarObject* obj){
    144             if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
     134        bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     135            if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0)
    145136                return true;
    146137        else return false;
Note: See TracChangeset for help on using the changeset viewer.