Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2008, 1:39:05 PM (16 years ago)
Author:
rgrieder
Message:
  • merged Felix's changes from trunk to network branch
  • added "svn:eol-style native" property to keybindings.ini
File:
1 edited

Legend:

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

    r1384 r1406  
    2222*      Yuning Chai
    2323*   Co-authors:
    24 *      ...
     24*      Felix Schulthess
    2525*
    2626*/
     
    2929#include "RadarOverlayElement.h"
    3030
     31#include <string.h>
     32#include <OgreOverlayManager.h>
     33#include <OgreStringConverter.h>
     34#include <OgrePanelOverlayElement.h>
     35
     36#include "GraphicsEngine.h"
     37#include "core/Tickable.h"
     38#include "core/ConsoleCommand.h"
     39#include "objects/SpaceShip.h"
     40#include "HUD.h"
     41
    3142namespace orxonox
    3243{
    33     ConsoleCommandShortcut(RadarOverlayElement, cycleFocus, AccessLevel::User);
    3444
    3545    using namespace Ogre;
    3646
    37     RadarOverlayElement* RadarOverlayElement::instance_s = NULL;
    38 
    39     RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
    40         RadarOverlayElement::instance_s = this;
     47    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
    4148    }
    4249
     
    4451    }
    4552
    46     void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
     53    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
    4754        // some initial data
    48                 om = &Ogre::OverlayManager::getSingleton();
     55                om = &OverlayManager::getSingleton();
    4956        dimRel_ = dimRel;
    5057        leftRel_ = leftRel;
    5158        topRel_ = topRel;
    5259        container_ = container;
    53         firstRadarObject_ = NULL;
    54         lastRadarObject_ = NULL;
    55         focus_ = NULL;
    5660
    57         // create nav marker ...
    58         navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
    59         navMarker_->setMetricsMode(Ogre::GMM_PIXELS);
    60         navMarker_->setMaterialName("Orxonox/NavMarker");
    61         navMarker_->setDimensions(16,16);
    62         navMarker_->setPosition(0,386);
    63         navMarker_->hide();
    64         container_->addChild(navMarker_);
    65 
    66         // these have to fit the data in the level
    67         shipPos_ = Vector3(0.0, 0.0, 0.0);
    68         initialDir_ = Vector3(1.0, 0.0, 0.0);
    69         currentDir_ = initialDir_;
    70         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    71         currentOrth_ = initialOrth_;
    72         plane = Plane(currentDir_, shipPos_);
    73 
    74         setMetricsMode(Ogre::GMM_PIXELS);
     61        setMetricsMode(GMM_PIXELS);
    7562        setMaterialName("Orxonox/Radar");
    7663        resize();
     
    9178
    9279    void RadarOverlayElement::update() {
     80<<<<<<< .working
    9381        shipPos_ = SpaceShip::getLocalShip()->getPosition();
    9482        currentDir_ = SpaceShip::getLocalShip()->getOrientation()*initialDir_;          // according to beni....
     
    9785
    9886        RadarObject* ro = firstRadarObject_;
     87=======
     88        shipPos_ = SpaceShip::getLocalShip()->getPosition();
     89        currentDir_ = SpaceShip::getLocalShip()->getDir();
     90                currentOrth_ = SpaceShip::getLocalShip()->getOrth();
     91        RadarObject* ro = HUD::getSingleton().getFirstRadarObject();
     92>>>>>>> .merge-right.r1401
    9993        // iterate through all RadarObjects
    10094                while(ro != NULL){
    10195                    // calc position on radar...
    102             ro->radius_ = calcRadius(ro);
    103             ro->phi_ = calcPhi(ro);
    104             ro->right_ = calcRight(ro);
     96            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, ro);
     97            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, ro);
     98            bool right = calcRight(shipPos_, currentDir_, currentOrth_, ro);
    10599
    106100            // set size to fit distance...
     
    111105            else ro->panel_->setDimensions(1,1);
    112106
    113             if (ro->right_){
    114                 ro->panel_->setPosition(sin(ro->phi_)*ro->radius_/
    115                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     107            if (right){
     108                ro->panel_->setPosition(sin(phi)*radius/
     109                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    116110            }
    117111            else {
    118                 ro->panel_->setPosition(-sin(ro->phi_)*ro->radius_/
    119                     3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
     112                ro->panel_->setPosition(-sin(phi)*radius/
     113                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
    120114            }
    121115            ro = ro->next;
    122116                }
    123                 updateNavMarker();
    124117    }
    125 
    126     void RadarOverlayElement::updateNavMarker(){
    127         if(focus_ == NULL) return;
    128         // from the angle we find out where to draw the marker
    129         // and which of the four arrows to take
    130         float r1 = atan((float)(windowW_)/(float)(windowH_));
    131         float phi = focus_->phi_;
    132         if(focus_->right_){
    133             if(phi<r1){
    134                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
    135                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    136             }
    137             else if(phi>3.14-r1){
    138                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    139                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    140             }
    141             else {
    142                 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    143                 navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    144             }
    145         }
    146         else{
    147             if(phi<r1) {
    148                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
    149                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    150             }
    151             else if(phi>3.14-r1) {
    152                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    153                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    154             }
    155             else {
    156                 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    157                 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
    158             }
    159         }
    160     }
    161 
    162     void RadarOverlayElement::addObject(Vector3 pos){
    163         if(firstRadarObject_ == NULL){
    164             firstRadarObject_ = new RadarObject(container_, pos);
    165             lastRadarObject_ = firstRadarObject_;
    166         }
    167         else{
    168             lastRadarObject_->next = new RadarObject(container_, pos);
    169             lastRadarObject_ = lastRadarObject_->next;
    170         }
    171         }
    172118
    173119        void RadarOverlayElement::listObjects(){
    174120            int i = 0;
    175             RadarObject* ro = firstRadarObject_;
     121            RadarObject* ro = HUD::getSingleton().getFirstRadarObject();
    176122            COUT(3) << "List of RadarObjects:\n";
    177123            // iterate through all Radar Objects
     
    182128        }
    183129
    184         float RadarOverlayElement::getDist2Focus(){
    185             if(focus_ == NULL) return(0.0);
    186             return((focus_->pos_-shipPos_).length());
     130        float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     131            return(acos((dir.dotProduct(obj->pos_ - pos))/
     132                        ((obj->pos_ - pos).length()*dir.length())));
    187133        }
    188134
    189         float RadarOverlayElement::calcRadius(RadarObject* obj){
    190             return(acos((currentDir_.dotProduct(obj->pos_ - shipPos_))/
    191                         ((obj->pos_ - shipPos_).length()*currentDir_.length())));
     135        float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     136            // project difference vector on our plane...
     137            Vector3 proj = Plane(dir, pos).projectVector(obj->pos_ - pos);
     138            // ...and find out the angle
     139            return(acos((orth.dotProduct(proj))/
     140            (orth.length()*proj.length())));
    192141        }
    193142
    194         float RadarOverlayElement::calcPhi(RadarObject* obj){
    195             // project difference vector on our plane...
    196             Ogre::Vector3 proj = plane.projectVector(obj->pos_ - shipPos_);
    197             // ...and find out the angle
    198             return(acos((currentOrth_.dotProduct(proj))/
    199             (currentOrth_.length()*proj.length())));
    200         }
    201 
    202         bool RadarOverlayElement::calcRight(RadarObject* obj){
    203             if((currentDir_.crossProduct(currentOrth_)).dotProduct(obj->pos_ - shipPos_) > 0)
     143        bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
     144            if((dir.crossProduct(orth)).dotProduct(obj->pos_ - pos) > 0)
    204145                return true;
    205146        else return false;
    206147        }
    207 
    208         /*static*/void RadarOverlayElement::cycleFocus(){
    209             if(RadarOverlayElement::instance_s == NULL) return;
    210 
    211             if(RadarOverlayElement::instance_s->focus_ == NULL){
    212             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->firstRadarObject_;
    213             }
    214         else{
    215             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/RedDot");
    216             RadarOverlayElement::instance_s->focus_ = RadarOverlayElement::instance_s->focus_->next;
    217         }
    218 
    219         if(RadarOverlayElement::instance_s->focus_ == NULL){
    220             RadarOverlayElement::instance_s->navMarker_->hide();
    221         }
    222         else{
    223             RadarOverlayElement::instance_s->navMarker_->show();
    224             RadarOverlayElement::instance_s->focus_->panel_->setMaterialName("Orxonox/WhiteDot");
    225         }
    226         }
    227148}
    228 
    229 /* my local clipboard...
    230 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    231 COUT(3) << firstRadarObject_->radius_ << "  " << firstRadarObject_->phi_ << std::endl;
    232 COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
    233 */
Note: See TracChangeset for help on using the changeset viewer.