Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1479 was 1407, checked in by rgrieder, 17 years ago
  • reverted the HUD changes to ease up back merge from network branch

@everyone: please commit to the network branch from now on if it concerns the presentation.
Oli has also created a folder for the presentation files.
@fabian: you are excluded

File size: 3.9 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.8, 0.8);
63        test->setPosition(0.02, 0.02);
64        test->setFontName("Console");
65        test->setCaption("init");
66
67        // create energy bar
68        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
69        energyBar->show();
70        // create speedo bar
71        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
72        speedoBar->show();
73        // create radar
74        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
75        radar->show();
76
77                // set up screen-wide container
78        container->show();
79
80        orxonoxHUD->add2D(container);
81        orxonoxHUD->show();
82        container->setLeft(0.0);
83        container->setTop(0.0);
84        container->setWidth(1.0);
85        container->setHeight(1.0);
86        container->setMetricsMode(Ogre::GMM_RELATIVE);
87        container->addChild(test);
88        energyBar->init(0.01, 0.94, 0.4, container);
89        energyBar->setValue(1);
90        speedoBar->init(0.01, 0.90, 0.4, container);
91        radar->init(0.5, 0.9, 0.2, container);
92        radar->addObject(Vector3(1500.0, 0.0, 100.0));
93        radar->addObject(Vector3(0.0, 4000.0, 0.0));
94        radar->addObject(Vector3(0.0, 0.0, 6800.0));
95        RadarOverlayElement::cycleFocus();
96    }
97
98    void HUD::tick(float dt)
99    {
100        int d = radar->getDist2Focus()/10;
101        if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
102        else test->setCaption("");
103
104        energyBar->resize();
105
106        float v = SpaceShip::instance_s->getVelocity().length();
107        float vmax = SpaceShip::instance_s->getMaxSpeed();
108        speedoBar->setValue(v/vmax);
109        speedoBar->resize();
110
111        radar->resize();
112        radar->update();
113    }
114
115    HUD::~HUD(void){
116    }
117}
118
119
120
121
122
123
Note: See TracBrowser for help on using the repository browser.