Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/hud/HUD.cc @ 1047

Last change on this file since 1047 was 1039, checked in by rgrieder, 17 years ago
  • train riding doesn't have to be boring
  • added some license notes
  • removed certain header dependencies in audio
  • changed order of header file inclusion in orxonox and audio (coding style guide will be updated)
File size: 7.1 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*      Yuning Chai
23*   Co-authors:
24*      ...
25*
26*/
27
28#include "OrxonoxStableHeaders.h"
29#include "HUD.h"
30
31#include <OgreOverlayManager.h>
32#include <OgreOverlayElement.h>
33#include <OgreStringConverter.h>
34
35
36namespace orxonox
37{
38  using namespace Ogre;
39
40  HUD::HUD(void)
41  {
42    init();
43
44    setTime(99,55);
45
46    setTargetWindowName("HURRA");
47    setTargetWindowDistance(12);
48    setTargetWindowStatus("Dead");
49    setTargetWindowDistance(30);
50
51    setEnergyValue(60.0);
52
53    setShieldLeftTopValue(true);
54    setShieldRightTopValue(false);
55    setShieldLeftBottomValue(false);
56    setShieldRightBottomValue(true);
57
58    setRocket1(11);
59    setRocket2(22);
60    setRocket3(33);
61    setRocket4(44);
62
63    setEnergyDistr(33,33,34);
64
65    setPrimar(3);
66
67    energyDistrPixelX_ = 100;
68    energyDistrPixelY_ = 86;
69
70  }
71
72
73  HUD::~HUD( void ){
74
75  }
76
77  void HUD::setTime(int i, int j){
78    timeMin_=i;
79    timeSec_=j;
80    timeText_->setCaption(StringConverter::toString(timeMin_) + ":" + StringConverter::toString(timeSec_));
81  }
82
83  void HUD::setTargetWindowName(std::string i){
84    targetWindowName_=i;
85    targetWindowNameText_->setCaption( targetWindowName_ );
86  }
87
88  void HUD::setTargetWindowStatus(std::string i){
89    targetWindowStatus_=i;
90    targetWindowStatusText_->setCaption( targetWindowStatus_ );
91  }
92
93  void HUD::setTargetWindowDistance(int i){
94    targetWindowDistance_=i;
95    targetWindowDistanceText_->setCaption(StringConverter::toString(targetWindowDistance_) + "km" );
96  }
97
98  void HUD::setTargetWindowHitRating(int i){
99    targetWindowHitRating_=i;
100    targetWindowHitRatingText_->setCaption(StringConverter::toString(targetWindowHitRating_) + "%" );
101  }
102
103  void HUD::setEnergyValue(int i){
104    energyValue_=i;
105    energyLength_->setWidth((int)((float)energyValue_/(float)100*200));
106  }
107
108  void HUD::setShieldLeftTopValue(bool i){
109    shieldLeftTopValue_=i;
110    if (shieldLeftTopValue_) shieldLeftTop_->show();
111    else shieldLeftTop_->hide();
112  }
113
114  void HUD::setShieldRightTopValue(bool i){
115    shieldRightTopValue_=i;
116    if (shieldRightTopValue_) shieldRightTop_->show();
117    else shieldRightTop_->hide();
118  }
119
120  void HUD::setShieldLeftBottomValue(bool i){
121    shieldLeftBottomValue_=i;
122    if (shieldLeftBottomValue_) shieldLeftBottom_->show();
123    else shieldLeftBottom_->hide();
124  }
125
126  void HUD::setShieldRightBottomValue(bool i){
127    shieldRightBottomValue_=i;
128    if (shieldRightBottomValue_) shieldRightBottom_->show();
129    else shieldRightBottom_->hide();
130  }
131
132  void HUD::setRocket1(int i){
133    rocket1_=i;
134    rocketNum1_->setCaption(StringConverter::toString(rocket1_));
135  }
136
137  void HUD::setRocket2(int i){
138    rocket2_=i;
139    rocketNum2_->setCaption(StringConverter::toString(rocket2_));
140  }
141
142  void HUD::setRocket3(int i){
143    rocket3_=i;
144    rocketNum3_->setCaption(StringConverter::toString(rocket3_));
145  }
146
147  void HUD::setRocket4(int i){
148    rocket4_=i;
149    rocketNum4_->setCaption(StringConverter::toString(rocket4_));
150  }
151
152  void HUD::setEnergyDistr(float s, float e, float l){
153    energyDistrShield_=s;
154    energyDistrEngine_=e;
155    energyDistrLaser_=l;
156
157    float energyDistrShieldInv_ = 100 - energyDistrShield_;
158    float energyDistrEngineInv_ = 100 - energyDistrEngine_;
159    float energyDistrLaserInv_ = 100 - energyDistrLaser_;
160
161    float energyDistrT_ = -energyDistrPixelX_/((energyDistrPixelX_-energyDistrPixelX_/2*energyDistrShieldInv_/(energyDistrShieldInv_+energyDistrEngineInv_))*energyDistrLaserInv_*(energyDistrShieldInv_+energyDistrEngineInv_)/energyDistrShieldInv_/(energyDistrLaserInv_+energyDistrEngineInv_)+energyDistrPixelX_/2+energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_));
162    float energyDistrX_ = (-energyDistrPixelX_/2-energyDistrPixelX_/2*energyDistrEngineInv_/(energyDistrEngineInv_+energyDistrLaserInv_))*energyDistrT_;
163    float energyDistrY_ = energyDistrPixelY_+energyDistrPixelY_*energyDistrLaserInv_/(energyDistrLaserInv_+energyDistrEngineInv_)*energyDistrT_;
164
165    energyDistrPoint_->setLeft((int)energyDistrX_-3);
166    energyDistrPoint_->setTop((int)energyDistrY_-3);
167
168  }
169
170  void HUD::setPrimar(int i){
171    primarValue_=i;
172    if(i==1){
173      primarChoice_->setLeft(2);
174      primarChoice_->setWidth(48);
175    }
176    if(i==2){
177      primarChoice_->setLeft(51);
178      primarChoice_->setWidth(49);
179    }
180    else{
181      primarChoice_->setLeft(101);
182      primarChoice_->setWidth(48);
183    }
184  }
185
186
187
188  void HUD::init(void)
189  {
190    timeText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/Time/Text");
191
192    targetWindowNameText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/Name");
193    targetWindowDistanceText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/DistanceText");
194    targetWindowStatusText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/StatusText");
195    targetWindowHitRatingText_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/TargetWindow/HitRatingText");
196
197    energyLength_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyBackground");
198
199    shieldLeftTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftTop");
200    shieldRightTop_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightTop");
201    shieldLeftBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldLeftBottom");
202    shieldRightBottom_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/shieldRightBottom");
203
204    rocketNum1_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum1");
205    rocketNum2_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum2");
206    rocketNum3_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum3");
207    rocketNum4_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/RocketNum4");
208
209    // FIXME: unused vars!
210    float energyDistrPixelX_ = 100;
211    float energyDistrPixelY_ = 86;
212    energyDistrPoint_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/EnergyDistrPoint");
213
214    primarChoice_ = OverlayManager::getSingleton().getOverlayElement("Orxonox/HUD1.2/PrimarChoice");
215  }
216
217}
Note: See TracBrowser for help on using the repository browser.