Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/hud/Navigation.cc @ 1393

Last change on this file since 1393 was 1393, checked in by FelixSchulthess, 16 years ago

moved navigation marker to new class: Navigation

File size: 3.9 KB
Line 
1/*
2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      Felix Schulthess
23*   Co-authors:
24*      ...
25*
26*/
27
28#include <OgreOverlayManager.h>
29#include <GraphicsEngine.h>
30#include "objects/SpaceShip.h"
31#include "HUD.h"
32#include "Navigation.h"
33
34namespace orxonox
35{
36    using namespace Ogre;
37
38    Navigation::Navigation(OverlayContainer* container){
39        container_ = container;
40        focus_ = NULL;
41        init();
42    }
43
44    Navigation::Navigation(OverlayContainer* container, RadarObject* focus){
45        container_ = container;
46        focus_ = focus;
47        init();
48    }
49
50    void Navigation::init(){
51                om = &OverlayManager::getSingleton();
52        // create nav marker ...
53        navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker"));
54        navMarker_->setMetricsMode(GMM_PIXELS);
55        navMarker_->setMaterialName("Orxonox/NavMarker");
56        navMarker_->setDimensions(16,16);
57        navMarker_->hide();
58        container_->addChild(navMarker_);
59        }
60
61        void Navigation::update(){
62        if(focus_ == NULL) return;
63        shipPos_ = SpaceShip::instance_s->getPosition();
64        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
65        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
66        // from the angle we find out where to draw the marker
67        // and which of the four arrows to take
68        float r1 = atan((float)(windowW_)/(float)(windowH_));
69        float phi = focus_->phi_;
70        if(focus_->right_){
71            if(phi<r1){
72                navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, 0);
73                navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
74            }
75            else if(phi>3.14-r1){
76                navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, windowH_-16);
77                navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
78            }
79            else {
80                navMarker_->setPosition(windowW_-16, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
81                navMarker_->setUV(0.5, 0.5, 1.0, 1.0);
82            }
83        }
84        else{
85            if(phi<r1) {
86                navMarker_->setPosition(-tan(phi)*windowH_/2+windowW_/2, 0);
87                navMarker_->setUV(0.5, 0.0, 1.0, 0.5);
88            }
89            else if(phi>3.14-r1) {
90                navMarker_->setPosition(tan(phi)*windowH_/2+windowW_/2, windowH_-16);
91                navMarker_->setUV(0.0, 0.5, 0.5, 1.0);
92            }
93            else {
94                navMarker_->setPosition(0, -tan((3.14-2*phi)/2)*windowW_/2+windowH_/2);
95                navMarker_->setUV(0.0, 0.0, 0.5, 0.5);
96            }
97        }
98    }
99
100    void Navigation::cycleFocus(){
101            if(focus_ == NULL){
102            focus_ = HUD::getSingleton().getFirstRadarObject();
103            }
104        else{
105            focus_->panel_->setMaterialName("Orxonox/RedDot");
106            focus_ = focus_->next;
107        }
108
109        if(focus_ == NULL){
110            navMarker_->hide();
111        }
112        else{
113            navMarker_->show();
114            focus_->panel_->setMaterialName("Orxonox/WhiteDot");
115        }
116        }
117
118        float Navigation::getDist2Focus(){
119            if(focus_ == NULL) return(0.0);
120            return((focus_->pos_-shipPos_).length());
121        }
122}
Note: See TracBrowser for help on using the repository browser.