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 | * Yuning Chai |
---|
23 | * Co-authors: |
---|
24 | * ... |
---|
25 | * |
---|
26 | */ |
---|
27 | |
---|
28 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include <OgreOverlay.h> |
---|
31 | #include <OgreOverlayContainer.h> |
---|
32 | #include <OgreOverlayManager.h> |
---|
33 | #include <OgreSceneNode.h> |
---|
34 | #include <OgreEntity.h> |
---|
35 | |
---|
36 | #include "HUD.h" |
---|
37 | #include "Bar.h" |
---|
38 | #include "Factories.h" |
---|
39 | // ugly hack |
---|
40 | #include "Orxonox.h" |
---|
41 | |
---|
42 | |
---|
43 | namespace orxonox |
---|
44 | { |
---|
45 | using namespace Ogre; |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | HUD::HUD(int zoom){ |
---|
52 | |
---|
53 | Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
54 | |
---|
55 | // energyCounter = new Bar(0,0,100,20,Bar::LEFT,Bar::YELLOW,"Orxonox/HUD/energyCounterPanel/energyCounter"); |
---|
56 | |
---|
57 | Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel")); |
---|
58 | energyCounterPanel->setLeft(-50); |
---|
59 | energyCounterPanel->setTop(10); |
---|
60 | energyCounterPanel->setWidth(100); |
---|
61 | energyCounterPanel->setHeight(20); |
---|
62 | energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER); |
---|
63 | energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS); |
---|
64 | energyCounterPanel->show(); |
---|
65 | // energyCounterPanel->addChild(energyCounter->element); |
---|
66 | |
---|
67 | BarOverlayElementFactory *factory = new BarOverlayElementFactory(); |
---|
68 | overlayManager.addOverlayElementFactory(factory); |
---|
69 | Ogre::OverlayElement* BarElement = overlayManager.createOverlayElementFromFactory("Bar", "BarElement"); |
---|
70 | |
---|
71 | energyCounterPanel->addChild(BarElement); |
---|
72 | |
---|
73 | Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); |
---|
74 | orxonoxOverlay->add2D(energyCounterPanel); |
---|
75 | |
---|
76 | // important: don't use SceneManager to create the node! but register the creator scene manager. |
---|
77 | ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely"); |
---|
78 | |
---|
79 | ogreNode_->setPosition(80,-60,-200); |
---|
80 | ogreNode_->setScale(0.4,0.4,0.4); |
---|
81 | // ugly hack, but I haven't figured out yet how we could change this, since we really need the |
---|
82 | // scene manager.. |
---|
83 | ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh")); |
---|
84 | orxonoxOverlay->add3D(ogreNode_); |
---|
85 | |
---|
86 | orxonoxOverlay->show(); |
---|
87 | } |
---|
88 | |
---|
89 | void HUD::tick(float dt) |
---|
90 | { |
---|
91 | if (this->ogreNode_) |
---|
92 | { |
---|
93 | this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
94 | this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
95 | this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | HUD::~HUD(void){} |
---|
100 | |
---|
101 | |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | /*#include "OrxonoxStableHeaders.h" |
---|
111 | |
---|
112 | #include <OgreOverlayManager.h> |
---|
113 | #include <OgreOverlayElement.h> |
---|
114 | #include <OgreStringConverter.h> |
---|
115 | |
---|
116 | #include "HUD.h" |
---|
117 | #include "Bar.h" |
---|
118 | |
---|
119 | namespace orxonox |
---|
120 | { |
---|
121 | using namespace Ogre; |
---|
122 | |
---|
123 | HUD::HUD(void) |
---|
124 | { |
---|
125 | init(); |
---|
126 | |
---|
127 | setTime(99,55); |
---|
128 | |
---|
129 | setTargetWindowName("HURRA"); |
---|
130 | setTargetWindowDistance(12); |
---|
131 | setTargetWindowStatus("Dead"); |
---|
132 | setTargetWindowDistance(30); |
---|
133 | |
---|
134 | setEnergyValue(60); |
---|
135 | |
---|
136 | setShieldLeftTopValue(true); |
---|
137 | setShieldRightTopValue(false); |
---|
138 | setShieldLeftBottomValue(false); |
---|
139 | setShieldRightBottomValue(true); |
---|
140 | |
---|
141 | setRocket1(11); |
---|
142 | setRocket2(22); |
---|
143 | setRocket3(33); |
---|
144 | setRocket4(44); |
---|
145 | |
---|
146 | setEnergyDistr(33,33,34); |
---|
147 | |
---|
148 | setPrimar(3); |
---|
149 | |
---|
150 | energyDistrPixelX_ = 100; |
---|
151 | energyDistrPixelY_ = 86; |
---|
152 | |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | HUD::~HUD( void ){ |
---|
158 | |
---|
159 | } |
---|
160 | |
---|
161 | void HUD::setTime(int i, int j){ |
---|
162 | timeMin_=i; |
---|
163 | timeSec_=j; |
---|
164 | timeText_->setCaption(StringConverter::toString(timeMin_) + ":" + StringConverter::toString(timeSec_)); |
---|
165 | } |
---|
166 | |
---|
167 | void HUD::setTargetWindowName(std::string i){ |
---|
168 | targetWindowName_=i; |
---|
169 | targetWindowNameText_->setCaption( targetWindowName_ ); |
---|
170 | } |
---|
171 | |
---|
172 | void HUD::setTargetWindowStatus(std::string i){ |
---|
173 | targetWindowStatus_=i; |
---|
174 | targetWindowStatusText_->setCaption( targetWindowStatus_ ); |
---|
175 | } |
---|
176 | |
---|
177 | void HUD::setTargetWindowDistance(int i){ |
---|
178 | targetWindowDistance_=i; |
---|
179 | targetWindowDistanceText_->setCaption(StringConverter::toString(targetWindowDistance_) + "km" ); |
---|
180 | } |
---|
181 | |
---|
182 | void HUD::setTargetWindowHitRating(int i){ |
---|
183 | targetWindowHitRating_=i; |
---|
184 | targetWindowHitRatingText_->setCaption(StringConverter::toString(targetWindowHitRating_) + "%" ); |
---|
185 | } |
---|
186 | |
---|
187 | void HUD::setEnergyValue(int i){ |
---|
188 | energyValue_=i; |
---|
189 | energyLength_->setWidth((int)((float)energyValue_/(float)100*200)); |
---|
190 | } |
---|
191 | |
---|
192 | void HUD::setShieldLeftTopValue(bool i){ |
---|
193 | shieldLeftTopValue_=i; |
---|
194 | if (shieldLeftTopValue_) shieldLeftTop_->show(); |
---|
195 | else shieldLeftTop_->hide(); |
---|
196 | } |
---|
197 | |
---|
198 | void HUD::setShieldRightTopValue(bool i){ |
---|
199 | shieldRightTopValue_=i; |
---|
200 | if (shieldRightTopValue_) shieldRightTop_->show(); |
---|
201 | else shieldRightTop_->hide(); |
---|
202 | } |
---|
203 | |
---|
204 | void HUD::setShieldLeftBottomValue(bool i){ |
---|
205 | shieldLeftBottomValue_=i; |
---|
206 | if (shieldLeftBottomValue_) shieldLeftBottom_->show(); |
---|
207 | else shieldLeftBottom_->hide(); |
---|
208 | } |
---|
209 | |
---|
210 | void HUD::setShieldRightBottomValue(bool i){ |
---|
211 | shieldRightBottomValue_=i; |
---|
212 | if (shieldRightBottomValue_) shieldRightBottom_->show(); |
---|
213 | else shieldRightBottom_->hide(); |
---|
214 | } |
---|
215 | |
---|
216 | void HUD::setRocket1(int i){ |
---|
217 | rocket1_=i; |
---|
218 | rocketNum1_->setCaption(StringConverter::toString(rocket1_)); |
---|
219 | } |
---|
220 | |
---|
221 | void HUD::setRocket2(int i){ |
---|
222 | rocket2_=i; |
---|
223 | rocketNum2_->setCaption(StringConverter::toString(rocket2_)); |
---|
224 | } |
---|
225 | |
---|
226 | void HUD::setRocket3(int i){ |
---|
227 | rocket3_=i; |
---|
228 | rocketNum3_->setCaption(StringConverter::toString(rocket3_)); |
---|
229 | } |
---|
230 | |
---|
231 | void HUD::setRocket4(int i){ |
---|
232 | rocket4_=i; |
---|
233 | rocketNum4_->setCaption(StringConverter::toString(rocket4_)); |
---|
234 | } |
---|
235 | |
---|
236 | void HUD::setEnergyDistr(float s, float e, float l){ |
---|
237 | energyDistrShield_=s; |
---|
238 | energyDistrEngine_=e; |
---|
239 | energyDistrLaser_=l; |
---|
240 | |
---|
241 | float energyDistrShieldInv_ = 100 - energyDistrShield_; |
---|
242 | float energyDistrEngineInv_ = 100 - energyDistrEngine_; |
---|
243 | float energyDistrLaserInv_ = 100 - energyDistrLaser_; |
---|
244 | |
---|
245 | float energyDistrT_ = -energyDistrPixelX_/((energyDistrPixelX_-energyDistrPixelX_/2*energyDistrShieldInv_/(energyDistrShieldInv_+energyDistrEngineInv_))*energyDistrLaserInv_*(energyDistrShieldInv_+energyDistrEngineInv_)/energyDistrShieldInv_/(energyDistrLaserInv_+energyDistrEngineInv_)+energyDistrPixelX_/2+energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_)); |
---|
246 | float energyDistrX_ = (-energyDistrPixelX_/2-energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_))*energyDistrT_; |
---|
247 | float energyDistrY_ = energyDistrPixelY_+energyDistrPixelY_*energyDistrLaserInv_/(energyDistrLaserInv_+energyDistrEngineInv_)*energyDistrT_; |
---|
248 | |
---|
249 | energyDistrPoint_->setLeft((int)energyDistrX_-3); |
---|
250 | energyDistrPoint_->setTop((int)energyDistrY_-3); |
---|
251 | |
---|
252 | } |
---|
253 | |
---|
254 | void HUD::setPrimar(int i){ |
---|
255 | primarValue_=i; |
---|
256 | if(i==1){ |
---|
257 | primarChoice_->setLeft(2); |
---|
258 | primarChoice_->setWidth(48); |
---|
259 | } |
---|
260 | if(i==2){ |
---|
261 | primarChoice_->setLeft(51); |
---|
262 | primarChoice_->setWidth(49); |
---|
263 | } |
---|
264 | else{ |
---|
265 | primarChoice_->setLeft(101); |
---|
266 | primarChoice_->setWidth(48); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | |
---|
271 | |
---|
272 | void HUD::init(void) |
---|
273 | { |
---|
274 | timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text"); |
---|
275 | |
---|
276 | targetWindowNameText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name"); |
---|
277 | targetWindowDistanceText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText"); |
---|
278 | targetWindowStatusText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText"); |
---|
279 | targetWindowHitRatingText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText"); |
---|
280 | |
---|
281 | energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground"); |
---|
282 | |
---|
283 | shieldLeftTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftTop"); |
---|
284 | shieldRightTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightTop"); |
---|
285 | shieldLeftBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftBottom"); |
---|
286 | shieldRightBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightBottom"); |
---|
287 | |
---|
288 | rocketNum1_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1"); |
---|
289 | rocketNum2_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2"); |
---|
290 | rocketNum3_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3"); |
---|
291 | rocketNum4_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4"); |
---|
292 | |
---|
293 | // FIXME: unused vars! |
---|
294 | float energyDistrPixelX_ = 100; |
---|
295 | float energyDistrPixelY_ = 86; |
---|
296 | energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint"); |
---|
297 | |
---|
298 | primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice"); |
---|
299 | } |
---|
300 | |
---|
301 | } |
---|
302 | */ |
---|