Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

moved navigation marker to new class: Navigation

File size: 5.5 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        // test
63        test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123"));
64        test->show();
65        test->setMetricsMode(Ogre::GMM_RELATIVE);
66        test->setDimensions(0.3, 0.3);
67        test->setPosition(0.02, 0.02);
68        test->setFontName("Console");
69        test->setCaption("init");
70
71        // creating text to display fps
72        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
73        fpsText->show();
74        fpsText->setMetricsMode(Ogre::GMM_RELATIVE);
75        fpsText->setDimensions(0.3, 0.3);
76        fpsText->setPosition(0.9, 0.02);
77        fpsText->setFontName("Console");
78        fpsText->setCaption("init");
79
80        // create energy bar
81        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
82        energyBar->show();
83        // create speedo bar
84        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
85        speedoBar->show();
86        // create radar
87        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
88        radar->show();
89
90        // create Navigation
91        nav = new Navigation(container);
92
93                // set up screen-wide container
94        container->show();
95
96        orxonoxHUD->add2D(container);
97        orxonoxHUD->show();
98        container->setLeft(0.0);
99        container->setTop(0.0);
100        container->setWidth(1.0);
101        container->setHeight(1.0);
102        container->setMetricsMode(Ogre::GMM_RELATIVE);
103        container->addChild(test);
104        container->addChild(fpsText);
105
106        energyBar->init(0.01, 0.94, 0.4, container);
107        energyBar->setValue(1);
108
109        speedoBar->init(0.01, 0.90, 0.4, container);
110
111        radar->init(0.5, 0.9, 0.2, container);
112        addRadarObject(Vector3(2000.0, 1000.0, 1000.0));
113        addRadarObject(Vector3(0.0, 4000.0, 0.0));
114        addRadarObject(Vector3(0.0, 0.0, 6800.0));
115    }
116
117    HUD::~HUD(){
118        //todo: clean up objects
119    }
120
121    void HUD::tick(float dt)
122    {
123        int d = (float)(nav->getDist2Focus()/10);
124        if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d));
125        else test->setCaption("");
126
127        energyBar->resize();
128
129        float v = SpaceShip::instance_s->getVelocity().length();
130        float vmax = SpaceShip::instance_s->getMaxSpeed();
131        speedoBar->setValue(v/vmax);
132        speedoBar->resize();
133
134        radar->resize();
135        radar->update();
136
137        nav->update();
138    }
139
140    void HUD::addRadarObject(Vector3 pos){
141        // check if this is the first RadarObject to create
142        if(firstRadarObject == NULL){
143            firstRadarObject = new RadarObject(container, pos);
144            lastRadarObject = firstRadarObject;
145        }
146        else{ // if not, append to list
147            lastRadarObject->next = new RadarObject(container, pos);
148            lastRadarObject = lastRadarObject->next;
149        }
150    }
151
152    RadarObject* HUD::getFirstRadarObject(){
153        return firstRadarObject;
154    }
155
156    /*static*/HUD& HUD::getSingleton(){
157        static HUD theInstance;
158        return theInstance;
159    }
160
161    /*static*/void HUD::setFPS(float fps){
162        HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
163    }
164
165    /*static*/void HUD::setEnergy(float value){
166        HUD::getSingleton().energyBar->setValue(value);
167    }
168
169    /*static*/void HUD::cycleNavigationFocus(){
170        HUD::getSingleton().nav->cycleFocus();
171    }
172}
173
174
175
176
177
178
Note: See TracBrowser for help on using the repository browser.