Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

minor change

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