Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1399


Ignore:
Timestamp:
May 23, 2008, 10:27:52 PM (16 years ago)
Author:
FelixSchulthess
Message:

enhanced navigation with a target designation cursor

Location:
code/trunk/src/orxonox
Files:
7 edited

Legend:

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

    r1394 r1399  
    6464        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
    6565        fpsText->show();
    66         fpsText->setMetricsMode(Ogre::GMM_RELATIVE);
    67         fpsText->setDimensions(0.3, 0.3);
    68         fpsText->setPosition(0.9, 0.02);
     66        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
     67        fpsText->setDimensions(0.001, 0.001);
     68        fpsText->setPosition(10, 10);
    6969        fpsText->setFontName("Console");
     70        fpsText->setCharHeight(20);
    7071        fpsText->setCaption("init");
    7172
  • code/trunk/src/orxonox/hud/Navigation.cc

    r1396 r1399  
    2727
    2828#include <OgreOverlayManager.h>
     29#include <OgrePanelOverlayElement.h>
     30#include <OgreTextAreaOverlayElement.h>
    2931#include <OgreStringConverter.h>
     32#include <OgreMatrix4.h>
    3033#include <GraphicsEngine.h>
     34#include "core/Iterator.h"
    3135#include "objects/SpaceShip.h"
     36#include "objects/CameraHandler.h"
    3237#include "HUD.h"
    3338#include "Navigation.h"
     
    5156    void Navigation::init(){
    5257                om = &OverlayManager::getSingleton();
     58//              for (Iterator<Model> it = ObjectList<Model>::begin(); it; ++it)
     59//              {
     60//            if(it->getPosition() == Vector(2000.0, 1000.0, 1000.0)){
     61//                COUT(3) << "TARGET FOUND\n";
     62//
     63//
     64//        }
     65                cam_ = NULL;
    5366        // create nav text
    5467        navText_ = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "navText"));
    5568        navText_->show();
    56         navText_->setMetricsMode(Ogre::GMM_RELATIVE);
    57         navText_->setDimensions(0.3, 0.3);
     69        navText_->setMetricsMode(Ogre::GMM_PIXELS);
     70        navText_->setDimensions(0.001, 0.001);
    5871        navText_->setPosition(0.02, 0.02);
    5972        navText_->setFontName("Console");
     73        navText_->setCharHeight(20);
    6074        navText_->setCaption("");
    6175        container_->addChild(navText_);
     
    6579        navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
    6680        navMarker_->setMetricsMode(GMM_PIXELS);
    67         navMarker_->setMaterialName("Orxonox/NavMarker");
    68         navMarker_->setDimensions(16,16);
    6981        navMarker_->hide();
     82        navText_->hide();
    7083        container_->addChild(navMarker_);
    7184        }
     
    7386        void Navigation::update(){
    7487        if(focus_ == NULL) return;
    75         shipPos_ = SpaceShip::instance_s->getPosition();
     88        shipPos_ = SpaceShip::getLocalShip()->getPosition();
    7689        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
    7790        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
    78         // from the angle we find out where to draw the marker
    79         // and which of the four arrows to take
    80         float r1 = atan((float)(windowW_)/(float)(windowH_));
    81         float phi = focus_->phi_;
    82         if(focus_->right_){
    83             if(phi<r1){
    84                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
    85                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     91        updateMarker();
     92    }
     93
     94    void Navigation::updateMarker(){
     95        // set text
     96        int dist = (float)(getDist2Focus()/100);
     97        navText_->setCaption(Ogre::StringConverter::toString(dist));
     98
     99        if(cam_ == NULL) cam_ = SpaceShip::getLocalShip()->getCamera()->cam_;
     100        Vector3 pos = focus_->pos_;
     101        // transform to screen coordinates
     102        pos = cam_->getProjectionMatrix()*cam_->getViewMatrix()*pos;
     103        float xPosRel = 0.5*pos.x+0.5;
     104        float yPosRel = 1-(0.5*pos.y+0.5);
     105        int xPos = xPosRel*windowW_;
     106        int yPos = yPosRel*windowH_;
     107        // is object in view?
     108        bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1);
     109        // if object is behind us, it is out of view anyway:
     110        if(!outOfView && focus_->radius_>3.14/2) outOfView = true;
     111
     112        if(outOfView){
     113            // NO!
     114            navMarker_->setMaterialName("Orxonox/NavArrows");
     115            navMarker_->setDimensions(16,16);
     116            float phiUpRight = atan((float)(windowW_)/(float)(windowH_));
     117            // from the angle we find out where to draw the marker
     118            // and which of the four arrows to take
     119            float phi = focus_->phi_;
     120            if(focus_->right_){
     121                if(phi<phiUpRight){
     122                    // arrow up
     123                    navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
     124                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     125                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     126                    navText_->setTop(navMarker_->getHeight());
     127                }
     128                else if(phi>3.14-phiUpRight){
     129                    // arrow down
     130                    navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
     131                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     132                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     133                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
     134                }
     135                else {
     136                    // arrow right
     137                    navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
     138                    navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
     139                    navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth());
     140                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
     141                }
    86142            }
    87             else if(phi>3.14-r1){
    88                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    89                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     143            else{
     144                if(phi<phiUpRight) {
     145                    // arrow up
     146                    navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
     147                    navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
     148                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     149                    navText_->setTop(navMarker_->getHeight());
     150                }
     151                else if(phi>3.14-phiUpRight) {
     152                    // arrow down
     153                    navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
     154                    navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
     155                    navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth());
     156                    navText_->setTop(navMarker_->getTop()-navMarker_->getHeight());
     157                }
     158                else {
     159                    // arrow left
     160                    navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
     161                    navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
     162                    navText_->setLeft(navMarker_->getWidth());
     163                    navText_->setTop(navMarker_->getTop()+navMarker_->getHeight());
     164                }
    90165            }
    91             else {
    92                 navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    93                 navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
    94             }
    95166        }
    96167        else{
    97             if(phi<r1) {
    98                 navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
    99                 navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
    100             }
    101             else if(phi>3.14-r1) {
    102                 navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
    103                 navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
    104             }
    105             else {
    106                 navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
    107                 navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
    108             }
    109         }
    110 
    111         int d = (float)(getDist2Focus()/10);
    112         if(d) navText_->setCaption("Distance: " + Ogre::StringConverter::toString(d));
    113         else navText_->setCaption("");
    114     }
     168            // YES!
     169            navMarker_->setMaterialName("Orxonox/NavTDC");
     170            navMarker_->setDimensions(24,24);
     171            navMarker_->setUV(0.0,0.0,1.0,1.0);
     172            navMarker_->setPosition(xPos-navMarker_->getWidth()/2, yPos-navMarker_->getHeight()/2);
     173            navText_->setPosition(xPos+navMarker_->getWidth()/2, yPos+navMarker_->getHeight()/2);
     174        }
     175        }
    115176
    116177    void Navigation::cycleFocus(){
     
    120181        else{
    121182            focus_->panel_->setMaterialName("Orxonox/RedDot");
    122             focus_ = focus_->next;
     183            if(focus_ != NULL) focus_ = focus_->next;
    123184        }
    124185
    125186        if(focus_ == NULL){
    126187            navMarker_->hide();
     188            navText_->hide();
    127189        }
    128190        else{
    129191            navMarker_->show();
     192            navText_->show();
    130193            focus_->panel_->setMaterialName("Orxonox/WhiteDot");
    131194        }
  • code/trunk/src/orxonox/hud/Navigation.h

    r1395 r1399  
    2020*
    2121*   Author:
    22 *      Yuning Chai
     22*      Felix Schulthess
    2323*   Co-authors:
    2424*      ...
     
    3030
    3131#include <OgrePrerequisites.h>
    32 #include <OgrePanelOverlayElement.h>
    33 #include <OgreTextAreaOverlayElement.h>
    3432#include "../OrxonoxPrereqs.h"
    3533#include "util/Math.h"
     
    4442            Ogre::OverlayContainer* container_;
    4543            Ogre::PanelOverlayElement* navMarker_;      // the panel used to show the arrow
    46             Ogre::TextAreaOverlayElement* navText_;      // displaying distance...
     44            Ogre::TextAreaOverlayElement* navText_;     // displaying distance
     45            Ogre::MovableObject* movo_;
     46            Ogre::Camera* cam_;
    4747                Vector3 shipPos_;                           // position of ship
    4848                int windowW_, windowH_;
    4949
    5050                void init();
     51                void updateMarker();
    5152
    5253        public:
  • code/trunk/src/orxonox/hud/RadarOverlayElement.cc

    r1393 r1399  
    113113                    3.5*dim_/2+dim_/2+left_-2,-cos(ro->phi_)*ro->radius_/3.5*dim_/2+dim_/2+top_-2);
    114114            }
    115             listObjects();
    116115            ro = ro->next;
    117116                }
  • code/trunk/src/orxonox/objects/Camera.h

    r1293 r1399  
    5050        void setTargetNode(Ogre::SceneNode* obj);
    5151
     52        Ogre::Camera* cam_;
     53
    5254        void tick(float dt);
    5355        void update();
     
    6365        Ogre::SceneNode* cameraNode_;
    6466        Ogre::Vector3 oldPos;
    65         Ogre::Camera* cam_;
    6667        bool bHasFocus_;
    6768    };
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1362 r1399  
    6969      return NULL;
    7070    }
    71    
     71
    7272    SpaceShip::SpaceShip() :
    7373      //testvector_(0,0,0),
     
    239239    }
    240240
     241    Camera* SpaceShip::getCamera(){
     242        return cam_;
     243    }
     244
    241245    void SpaceShip::createCamera(){
    242246//       COUT(4) << "begin camera creation" << std::endl;
     
    422426        if (this->bLMousePressed_ && this->timeToReload_ <= 0)
    423427        {
    424          
     428
    425429            Projectile *p = new Projectile(this);
    426            
     430
    427431            p->setBacksync(true);
    428432            this->timeToReload_ = this->reloadTime_;
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1362 r1399  
    4444    {
    4545        public:
    46          
     46
    4747            static SpaceShip *getLocalShip();
    48            
     48
    4949            SpaceShip();
    5050            ~SpaceShip();
     
    6666
    6767            void getFocus();
     68            Camera* getCamera();
    6869            static SpaceShip* instance_s;
    6970            static Vector3 getSPosition();
Note: See TracChangeset for help on using the changeset viewer.