Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/hud/HUD.cc @ 1418

Last change on this file since 1418 was 1414, checked in by rgrieder, 17 years ago
  • moved OrxonoxPlatform.h to util (didn't even notice util recently)
  • therefore was able to define uint32_t, etc. for all our libs in OrxonoxPlatform.h
  • made use of OgreRenderWindow::getAverageFPS() in HUD
File size: 5.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*      Felix Schulthess
25*
26*/
27
28#include "OrxonoxStableHeaders.h"
29#include "HUD.h"
30
31#include <string>
32#include <OgreOverlay.h>
33#include <OgreOverlayContainer.h>
34#include <OgreOverlayManager.h>
35#include <OgreStringConverter.h>
36
37#include "core/Debug.h"
38#include "core/ConsoleCommand.h"
39#include "objects/SpaceShip.h"
40#include "GraphicsEngine.h"
41#include "BarOverlayElement.h"
42#include "RadarObject.h"
43#include "RadarOverlayElement.h"
44#include "Navigation.h"
45#include "OverlayElementFactories.h"
46
47namespace orxonox
48{
49    ConsoleCommandShortcut(HUD, cycleNavigationFocus, AccessLevel::User);
50
51    using namespace Ogre;
52
53    HUD::HUD(){
54        om = &Ogre::OverlayManager::getSingleton();
55        firstRadarObject = NULL;
56        lastRadarObject = NULL;
57
58        // create Factories
59        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
60        om->addOverlayElementFactory(barOverlayElementFactory);
61        RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
62        om->addOverlayElementFactory(radarOverlayElementFactory);
63
64        orxonoxHUD = om->create("Orxonox/HUD");
65        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
66
67        // creating text to display fps
68        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
69        fpsText->show();
70        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
71        fpsText->setDimensions(0.001, 0.001);
72        fpsText->setPosition(10, 10);
73        fpsText->setFontName("Console");
74        fpsText->setCharHeight(20);
75        fpsText->setCaption("init");
76
77        // create energy bar
78        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
79        energyBar->show();
80        // create speedo bar
81        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
82        speedoBar->show();
83        // create radar
84        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
85        radar->show();
86
87        // create Navigation
88        nav = new Navigation(container);
89
90        // set up screen-wide container
91        container->show();
92
93        orxonoxHUD->add2D(container);
94        orxonoxHUD->show();
95        container->setLeft(0.0);
96        container->setTop(0.0);
97        container->setWidth(1.0);
98        container->setHeight(1.0);
99        container->setMetricsMode(Ogre::GMM_RELATIVE);
100        container->addChild(fpsText);
101
102        energyBar->init(0.01, 0.94, 0.4, container);
103        energyBar->setValue(1);
104
105        speedoBar->init(0.01, 0.90, 0.4, container);
106
107        radar->init(0.5, 0.9, 0.2, container);
108        addRadarObject(Vector3(2000.0, 0.0, 0.0));
109        addRadarObject(Vector3(0.0, 2000.0, 0.0));
110        addRadarObject(Vector3(0.0, 0.0, 2000.0));
111    }
112
113    HUD::~HUD(){
114        //todo: clean up objects
115    }
116
117    void HUD::tick(float dt)
118    {
119        energyBar->resize();
120
121        if(!SpaceShip::getLocalShip())
122          return;
123        float v = SpaceShip::getLocalShip()->getVelocity().length();
124        float vmax = SpaceShip::getLocalShip()->getMaxSpeed();
125        speedoBar->setValue(v/vmax);
126        speedoBar->resize();
127
128        radar->resize();
129        radar->update();
130
131        nav->update();
132
133        float fps = GraphicsEngine::getSingleton().getAverageFPS();
134        fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
135    }
136
137    void HUD::addRadarObject(Vector3 pos){
138        // check if this is the first RadarObject to create
139        if(firstRadarObject == NULL){
140            firstRadarObject = new RadarObject(container, pos);
141            lastRadarObject = firstRadarObject;
142        }
143        else{ // if not, append to list
144            lastRadarObject->next = new RadarObject(container, pos);
145            lastRadarObject = lastRadarObject->next;
146        }
147    }
148
149    RadarObject* HUD::getFirstRadarObject(){
150        return firstRadarObject;
151    }
152
153    /*static*/ HUD& HUD::getSingleton(){
154        static HUD theInstance;
155        return theInstance;
156    }
157
158    /*static*/ void HUD::setEnergy(float value){
159        HUD::getSingleton().energyBar->setValue(value);
160    }
161
162    /*static*/ void HUD::cycleNavigationFocus(){
163        HUD::getSingleton().nav->cycleFocus();
164    }
165}
166
167
168
169
170
171
Note: See TracBrowser for help on using the repository browser.