1 | /* |
---|
2 | * ORXONOX - the hotnavText_ 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 <OgreStringConverter.h> |
---|
30 | #include <GraphicsEngine.h> |
---|
31 | #include "objects/SpaceShip.h" |
---|
32 | #include "HUD.h" |
---|
33 | #include "Navigation.h" |
---|
34 | |
---|
35 | namespace orxonox |
---|
36 | { |
---|
37 | using namespace Ogre; |
---|
38 | |
---|
39 | Navigation::Navigation(OverlayContainer* container){ |
---|
40 | container_ = container; |
---|
41 | focus_ = NULL; |
---|
42 | init(); |
---|
43 | } |
---|
44 | |
---|
45 | Navigation::Navigation(OverlayContainer* container, RadarObject* focus){ |
---|
46 | container_ = container; |
---|
47 | focus_ = focus; |
---|
48 | init(); |
---|
49 | } |
---|
50 | |
---|
51 | void Navigation::init(){ |
---|
52 | om = &OverlayManager::getSingleton(); |
---|
53 | // create nav text |
---|
54 | navText_ = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "navText")); |
---|
55 | navText_->show(); |
---|
56 | navText_->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
57 | navText_->setDimensions(0.3, 0.3); |
---|
58 | navText_->setPosition(0.02, 0.02); |
---|
59 | navText_->setFontName("Console"); |
---|
60 | navText_->setCaption("init"); |
---|
61 | container_->addChild(navText_); |
---|
62 | |
---|
63 | |
---|
64 | // create nav marker ... |
---|
65 | navMarker_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "NavMarker")); |
---|
66 | navMarker_->setMetricsMode(GMM_PIXELS); |
---|
67 | navMarker_->setMaterialName("Orxonox/NavMarker"); |
---|
68 | navMarker_->setDimensions(16,16); |
---|
69 | navMarker_->hide(); |
---|
70 | container_->addChild(navMarker_); |
---|
71 | } |
---|
72 | |
---|
73 | void Navigation::update(){ |
---|
74 | if(focus_ == NULL) return; |
---|
75 | shipPos_ = SpaceShip::instance_s->getPosition(); |
---|
76 | windowW_ = GraphicsEngine::getSingleton().getWindowWidth(); |
---|
77 | 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); |
---|
86 | } |
---|
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); |
---|
90 | } |
---|
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 | } |
---|
95 | } |
---|
96 | 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 | } |
---|
115 | |
---|
116 | void Navigation::cycleFocus(){ |
---|
117 | if(focus_ == NULL){ |
---|
118 | focus_ = HUD::getSingleton().getFirstRadarObject(); |
---|
119 | } |
---|
120 | else{ |
---|
121 | focus_->panel_->setMaterialName("Orxonox/RedDot"); |
---|
122 | focus_ = focus_->next; |
---|
123 | } |
---|
124 | |
---|
125 | if(focus_ == NULL){ |
---|
126 | navMarker_->hide(); |
---|
127 | } |
---|
128 | else{ |
---|
129 | navMarker_->show(); |
---|
130 | focus_->panel_->setMaterialName("Orxonox/WhiteDot"); |
---|
131 | } |
---|
132 | } |
---|
133 | |
---|
134 | float Navigation::getDist2Focus(){ |
---|
135 | if(focus_ == NULL) return(0.0); |
---|
136 | return((focus_->pos_-shipPos_).length()); |
---|
137 | } |
---|
138 | } |
---|