Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/hud/HUD.cc @ 1356

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

added distance display

File size: 3.8 KB
RevLine 
[1281]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:
[1328]24*      Felix Schulthess
[1281]25*
26*/
27
28
29#include "OrxonoxStableHeaders.h"
30#include <OgreOverlay.h>
31#include <OgreOverlayContainer.h>
[1302]32#include <OgreOverlayManager.h>
[1281]33#include <OgreSceneNode.h>
34#include <OgreEntity.h>
[1356]35#include <OgreStringConverter.h>
[1281]36#include "core/Debug.h"
[1335]37#include "objects/SpaceShip.h"
[1281]38#include "HUD.h"
39#include "BarOverlayElement.h"
40#include "RadarOverlayElement.h"
41#include "OverlayElementFactories.h"
42
43namespace orxonox
44{
[1330]45    using namespace Ogre;
[1281]46
[1330]47    HUD::HUD(int zoom){
48        om = &Ogre::OverlayManager::getSingleton();
[1339]49
[1335]50                // create Factories
[1330]51        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
52        om->addOverlayElementFactory(barOverlayElementFactory);
53        RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
54        om->addOverlayElementFactory(radarOverlayElementFactory);
[1281]55
[1330]56        orxonoxHUD = om->create("Orxonox/HUD");
57        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
[1356]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
[1339]67        // create energy bar
[1335]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
[1330]74        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
75        radar->show();
[1281]76
[1335]77                // set up screen-wide container
[1330]78        container->show();
[1339]79
[1330]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);
[1356]87        container->addChild(test);
[1342]88        energyBar->init(0.01, 0.94, 0.4, container);
[1335]89        energyBar->setValue(1);
[1342]90        speedoBar->init(0.01, 0.90, 0.4, container);
[1330]91        radar->init(0.5, 0.9, 0.2, container);
[1356]92        radar->addObject(Vector3(1500.0, 0.0, 100.0));
[1339]93        radar->addObject(Vector3(0.0, 4000.0, 0.0));
[1356]94        radar->addObject(Vector3(0.0, 0.0, 6800.0));
[1350]95        RadarOverlayElement::cycleFocus();
[1330]96    }
[1281]97
[1330]98    void HUD::tick(float dt)
99    {
[1356]100        int d = radar->getDist2Focus()/10;
101        test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
102
[1335]103        energyBar->resize();
[1329]104
[1330]105        float v = SpaceShip::instance_s->getVelocity().length();
106        float vmax = SpaceShip::instance_s->getMaxSpeed();
[1335]107        speedoBar->setValue(v/vmax);
108        speedoBar->resize();
[1329]109
[1330]110        radar->resize();
111        radar->update();
112    }
[1302]113
[1330]114    HUD::~HUD(void){
115    }
[1281]116}
117
118
119
120
121
122
Note: See TracBrowser for help on using the repository browser.