Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved #includes to .cc from .h where possible

File size: 4.8 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 <string.h>
29#include "OrxonoxStableHeaders.h"
30#include <OgreOverlay.h>
31#include <OgreOverlayContainer.h>
32#include <OgreOverlayManager.h>
33#include <OgreStringConverter.h>
34
35#include "core/Debug.h"
36#include "core/ConsoleCommand.h"
37#include "objects/SpaceShip.h"
38#include "BarOverlayElement.h"
39#include "RadarOverlayElement.h"
40#include "OverlayElementFactories.h"
41#include "HUD.h"
42
43namespace orxonox
44{
45    ConsoleCommandShortcut(HUD, cycleRadarFocus, AccessLevel::User);
46
47    using namespace Ogre;
48
49    HUD::HUD(){
50        om = &Ogre::OverlayManager::getSingleton();
51
52                // create Factories
53        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
54        om->addOverlayElementFactory(barOverlayElementFactory);
55        RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
56        om->addOverlayElementFactory(radarOverlayElementFactory);
57
58        orxonoxHUD = om->create("Orxonox/HUD");
59        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
60        // test
61        test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123"));
62        test->show();
63        test->setMetricsMode(Ogre::GMM_RELATIVE);
64        test->setDimensions(0.3, 0.3);
65        test->setPosition(0.02, 0.02);
66        test->setFontName("Console");
67        test->setCaption("init");
68
69        // creating text to display fps
70        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
71        fpsText->show();
72        fpsText->setMetricsMode(Ogre::GMM_RELATIVE);
73        fpsText->setDimensions(0.3, 0.3);
74        fpsText->setPosition(0.9, 0.02);
75        fpsText->setFontName("Console");
76        fpsText->setCaption("init");
77
78        // create energy bar
79        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
80        energyBar->show();
81        // create speedo bar
82        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
83        speedoBar->show();
84        // create radar
85        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
86        radar->show();
87
88                // set up screen-wide container
89        container->show();
90
91        orxonoxHUD->add2D(container);
92        orxonoxHUD->show();
93        container->setLeft(0.0);
94        container->setTop(0.0);
95        container->setWidth(1.0);
96        container->setHeight(1.0);
97        container->setMetricsMode(Ogre::GMM_RELATIVE);
98        container->addChild(test);
99        container->addChild(fpsText);
100        energyBar->init(0.01, 0.94, 0.4, container);
101        energyBar->setValue(1);
102        speedoBar->init(0.01, 0.90, 0.4, container);
103        radar->init(0.5, 0.9, 0.2, container);
104        radar->addObject(Vector3(2000.0, 1000.0, 1000.0));
105        radar->addObject(Vector3(0.0, 4000.0, 0.0));
106        radar->addObject(Vector3(0.0, 0.0, 6800.0));
107    }
108
109    HUD::~HUD(){
110        //todo: clean up objects
111    }
112
113    void HUD::tick(float dt)
114    {
115        int d = (float)(radar->getDist2Focus()/10);
116        if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
117        else test->setCaption("");
118
119        energyBar->resize();
120
121        float v = SpaceShip::instance_s->getVelocity().length();
122        float vmax = SpaceShip::instance_s->getMaxSpeed();
123        speedoBar->setValue(v/vmax);
124        speedoBar->resize();
125
126        radar->resize();
127        radar->update();
128    }
129
130    /*static*/HUD& HUD::getSingleton(){
131        static HUD theInstance;
132        return theInstance;
133    }
134
135    /*static*/void HUD::setFPS(float fps){
136        HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
137    }
138
139    /*static*/void HUD::setEnergy(float value){
140        HUD::getSingleton().energyBar->setValue(value);
141    }
142
143    /*static*/void HUD::cycleRadarFocus(){
144        HUD::getSingleton().radar->cycleFocus();
145    }
146}
147
148
149
150
151
152
Note: See TracBrowser for help on using the repository browser.