Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1396 was 1394, checked in by FelixSchulthess, 17 years ago

moved navigation marker to new class: Navigation

File size: 4.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#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, cycleNavigationFocus, AccessLevel::User);
46
47    using namespace Ogre;
48
49    HUD::HUD(){
50        om = &Ogre::OverlayManager::getSingleton();
51        firstRadarObject = NULL;
52        lastRadarObject = NULL;
53
54                // create Factories
55        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
56        om->addOverlayElementFactory(barOverlayElementFactory);
57        RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
58        om->addOverlayElementFactory(radarOverlayElementFactory);
59
60        orxonoxHUD = om->create("Orxonox/HUD");
61        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
62
63        // creating text to display fps
64        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
65        fpsText->show();
66        fpsText->setMetricsMode(Ogre::GMM_RELATIVE);
67        fpsText->setDimensions(0.3, 0.3);
68        fpsText->setPosition(0.9, 0.02);
69        fpsText->setFontName("Console");
70        fpsText->setCaption("init");
71
72        // create energy bar
73        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
74        energyBar->show();
75        // create speedo bar
76        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
77        speedoBar->show();
78        // create radar
79        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
80        radar->show();
81
82        // create Navigation
83        nav = new Navigation(container);
84
85                // set up screen-wide container
86        container->show();
87
88        orxonoxHUD->add2D(container);
89        orxonoxHUD->show();
90        container->setLeft(0.0);
91        container->setTop(0.0);
92        container->setWidth(1.0);
93        container->setHeight(1.0);
94        container->setMetricsMode(Ogre::GMM_RELATIVE);
95        container->addChild(fpsText);
96
97        energyBar->init(0.01, 0.94, 0.4, container);
98        energyBar->setValue(1);
99
100        speedoBar->init(0.01, 0.90, 0.4, container);
101
102        radar->init(0.5, 0.9, 0.2, container);
103        addRadarObject(Vector3(2000.0, 1000.0, 1000.0));
104        addRadarObject(Vector3(0.0, 4000.0, 0.0));
105        addRadarObject(Vector3(0.0, 0.0, 6800.0));
106    }
107
108    HUD::~HUD(){
109        //todo: clean up objects
110    }
111
112    void HUD::tick(float dt)
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        nav->update();
125    }
126
127    void HUD::addRadarObject(Vector3 pos){
128        // check if this is the first RadarObject to create
129        if(firstRadarObject == NULL){
130            firstRadarObject = new RadarObject(container, pos);
131            lastRadarObject = firstRadarObject;
132        }
133        else{ // if not, append to list
134            lastRadarObject->next = new RadarObject(container, pos);
135            lastRadarObject = lastRadarObject->next;
136        }
137    }
138
139    RadarObject* HUD::getFirstRadarObject(){
140        return firstRadarObject;
141    }
142
143    /*static*/HUD& HUD::getSingleton(){
144        static HUD theInstance;
145        return theInstance;
146    }
147
148    /*static*/void HUD::setFPS(float fps){
149        HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
150    }
151
152    /*static*/void HUD::setEnergy(float value){
153        HUD::getSingleton().energyBar->setValue(value);
154    }
155
156    /*static*/void HUD::cycleNavigationFocus(){
157        HUD::getSingleton().nav->cycleFocus();
158    }
159}
160
161
162
163
164
165
Note: See TracBrowser for help on using the repository browser.