Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2008, 12:57:10 PM (16 years ago)
Author:
FelixSchulthess
Message:

removed some warnings caused by implicit conversion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc~

    r1335 r1342  
    5454
    5555    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
    56                 om = &Ogre::OverlayManager::getSingleton();       
     56        // some initial data
     57                om = &Ogre::OverlayManager::getSingleton();
    5758        dimRel_ = dimRel;
    5859        leftRel_ = leftRel;
    5960        topRel_ = topRel;
    6061        container_ = container;
     62        firstRadarObject_ = NULL;
     63        lastRadarObject_ = NULL;
    6164
     65        // these have to fit the data in the level
    6266        shipPos_ = Vector3(0.0, 0.0, 0.0);
    6367        initialDir_ = Vector3(1.0, 0.0, 0.0);
     
    6973        setMaterialName("Orxonox/Radar");
    7074        resize();
    71        
     75
    7276        container_->addChild(this);
    7377    }
     
    7781        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    7882        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
    79         dim_ = dimRel_*windowH_;
    80         left_ = leftRel_*windowW_-dim_/2;
    81         top_ = topRel_*windowH_-dim_/2;
     83        dim_ = (int) (dimRel_*windowH_);
     84        left_ = (int) (leftRel_*windowW_-dim_/2);
     85        top_ = (int) (topRel_*windowH_-dim_/2);
    8286        setPosition(left_, top_);
    8387        setDimensions(dim_,dim_);
     
    8993                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
    9094
    91                 if(tomato_ == NULL) return;             
    92                
    93                 tomato_->radius_ = acos((currentDir_.dotProduct(tomato_->pos_ - shipPos_))/
    94                         ((tomato_->pos_ - shipPos_).length()*currentDir_.length()));
    95         tomato_->phi_ = acos((currentOrth_.dotProduct(tomato_->pos_ - shipPos_))/
    96                 ((tomato_->pos_ - shipPos_).length()*currentOrth_.length()));
    97         if((currentDir_.crossProduct(currentOrth_)).dotProduct(tomato_->pos_ - shipPos_) > 0)
    98                 tomato_->right_ = true;
    99         else tomato_->right_=false;
     95        RadarObject* ro = firstRadarObject_;
     96        // iterate through all RadarObjects
     97                while(ro != NULL){
     98            ro->radius_ = calcRadius(ro);
     99            ro->phi_ = calcPhi(ro);
     100            ro->right_ = calcRight(ro);
     101            if (ro->right_){
     102                ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
     103                    3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     104            }
     105            else {
     106                ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
     107                    3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     108            }
     109            ro = ro->next;
     110                }
     111    }
    100112
    101         if (tomato_->right_){
    102             tomato_->panel_->setPosition(sin(tomato_->phi_)*tomato_->radius_/
    103                 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
     113    void RadarOverlayElement::addObject(Vector3 pos){
     114        if(firstRadarObject_ == NULL){
     115            firstRadarObject_ = new RadarObject(container_);
     116            firstRadarObject_->pos_ = pos;
     117            lastRadarObject_ = firstRadarObject_;
    104118        }
    105         else {
    106             tomato_->panel_->setPosition(-sin(tomato_->phi_)*tomato_->radius_/
    107                 3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
     119        else{
     120            lastRadarObject_->next = new RadarObject(container_);
     121            lastRadarObject_->next->pos_ = pos;
     122            lastRadarObject_ = lastRadarObject_->next;
    108123        }
    109         COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    110         COUT(3) << tomato_->radius_ << "  " << tomato_->phi_ << std::endl;
    111         COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    112     }
    113    
    114     void RadarOverlayElement::addObject(Vector3 pos){
    115                 tomato_ = new RadarObject(container_);
    116                 tomato_->pos_ = pos;
    117124        }
    118        
    119         //// RadarObject ////
    120        
    121         int RadarObject::count = 0;
    122        
     125
     126        void RadarOverlayElement::listObjects(){
     127            int i = 0;
     128            RadarObject* ro = firstRadarObject_;
     129            COUT(3) << "List of RadarObjects:\n";
     130            // iterate through all Radar Objects
     131            while(ro != NULL) {
     132                COUT(3) << i++ << ": " << ro->pos_ << std::endl;
     133                ro = ro->next;
     134            }
     135        }
     136
     137        float RadarOverlayElement::calcRadius(RadarObject* obj){
     138            return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
     139                        ((obj->pos_ - shipPos_).length()*currentDir_.length())));
     140        }
     141
     142        float RadarOverlayElement::calcPhi(RadarObject* obj){
     143            return(acos((currentOrth_.dotProduct(firstRadarObject_->pos_ - shipPos_))/
     144                ((firstRadarObject_->pos_ - shipPos_).length()*currentOrth_.length())));
     145        }
     146
     147        bool RadarOverlayElement::calcRight(RadarObject* obj){
     148            if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
     149                return true;
     150        else return false;
     151        }
     152
     153//////// RadarObject ////////
     154
     155        int RadarObject::count = 0;             // initialize static variable
     156
    123157        RadarObject::RadarObject(Ogre::OverlayContainer* container){
    124158                container_ = container;
     
    126160                init();
    127161        }
    128        
     162
    129163        RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){
    130164                container_ = container;
     
    132166                init();
    133167        }
    134        
     168
    135169        RadarObject::~RadarObject(){}
    136        
     170
    137171        void RadarObject::init(){
     172            next = NULL;
    138173                om = &Ogre::OverlayManager::getSingleton();
    139174                panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
     
    147182}
    148183
    149 
    150 
     184/* my local clipboard...
     185COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
     186COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
     187COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
     188*/
Note: See TracChangeset for help on using the changeset viewer.