Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/hud/HUD.cc @ 1450

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

making radar objects from scene nodes now. radar object supporting multiple colors

File size: 6.1 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 "OrxonoxStableHeaders.h"
29#include "HUD.h"
30
31#include <string>
32#include <OgreOverlay.h>
33#include <OgreOverlayContainer.h>
34#include <OgreOverlayManager.h>
35#include <OgreStringConverter.h>
36
37#include "core/Debug.h"
38#include "core/ConsoleCommand.h"
39#include "objects/SpaceShip.h"
40#include "GraphicsEngine.h"
41#include "BarOverlayElement.h"
42#include "RadarObject.h"
43#include "RadarOverlayElement.h"
44#include "Navigation.h"
45#include "OverlayElementFactories.h"
46
47namespace orxonox
48{
49    SetConsoleCommandShortcut(HUD, cycleNavigationFocus).setAccessLevel(AccessLevel::User);
50
51    using namespace Ogre;
52
53    HUD::HUD(){
54        om = &Ogre::OverlayManager::getSingleton();
55        sm = GraphicsEngine::getSingleton().getSceneManager();
56        firstRadarObject = NULL;
57        lastRadarObject = NULL;
58
59        // create Factories
60        BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory();
61        om->addOverlayElementFactory(barOverlayElementFactory);
62        RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory();
63        om->addOverlayElementFactory(radarOverlayElementFactory);
64
65        orxonoxHUD = om->create("Orxonox/HUD");
66        container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container"));
67
68        // creating text to display fps
69        fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText"));
70        fpsText->show();
71        fpsText->setMetricsMode(Ogre::GMM_PIXELS);
72        fpsText->setDimensions(0.001, 0.001);
73        fpsText->setPosition(10, 10);
74        fpsText->setFontName("Console");
75        fpsText->setCharHeight(20);
76        fpsText->setCaption("init");
77
78        // creating text to display render time ratio
79        rTRText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "rTRText"));
80        rTRText->show();
81        rTRText->setMetricsMode(Ogre::GMM_PIXELS);
82        rTRText->setDimensions(0.001, 0.001);
83        rTRText->setPosition(10, 30);
84        rTRText->setFontName("Console");
85        rTRText->setCharHeight(20);
86        rTRText->setCaption("init");
87
88        // create energy bar
89        energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar"));
90        energyBar->show();
91        // create speedo bar
92        speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar"));
93        speedoBar->show();
94        // create radar
95        radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar"));
96        radar->show();
97
98        // create Navigation
99        nav = new Navigation(container);
100
101        // set up screen-wide container
102        container->show();
103
104        orxonoxHUD->add2D(container);
105        orxonoxHUD->show();
106        container->setLeft(0.0);
107        container->setTop(0.0);
108        container->setWidth(1.0);
109        container->setHeight(1.0);
110        container->setMetricsMode(Ogre::GMM_RELATIVE);
111        container->addChild(fpsText);
112        container->addChild(rTRText);
113
114        energyBar->init(0.01, 0.94, 0.4, container);
115        energyBar->setValue(1);
116
117        speedoBar->init(0.01, 0.90, 0.4, container);
118
119        radar->init(0.5, 0.9, 0.2, container);
120        SceneNode* node;
121        node = sm->getRootSceneNode()->createChildSceneNode("tomato1", Vector3(2000.0, 0.0, 0.0));
122        addRadarObject(node);
123        node = sm->getRootSceneNode()->createChildSceneNode("tomato2", Vector3(0.0, 2000.0, 0.0));
124        addRadarObject(node);
125        node = sm->getRootSceneNode()->createChildSceneNode("tomato3", Vector3(0.0, 0.0, 2000.0));
126        addRadarObject(node);
127    }
128
129    HUD::~HUD(){
130        //todo: clean up objects
131    }
132
133    void HUD::tick(float dt)
134    {
135        energyBar->resize();
136
137        if(!SpaceShip::getLocalShip())
138          return;
139        float v = SpaceShip::getLocalShip()->getVelocity().length();
140        float vmax = SpaceShip::getLocalShip()->getMaxSpeed();
141        speedoBar->setValue(v/vmax);
142        speedoBar->resize();
143
144        radar->resize();
145        radar->update();
146
147        nav->update();
148
149        float fps = GraphicsEngine::getSingleton().getAverageFPS();
150        fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps));
151    }
152
153    void HUD::setRenderTimeRatio(float ratio)
154    {
155      rTRText->setCaption("Render time ratio: " + Ogre::StringConverter::toString(ratio));
156    }
157
158    void HUD::addRadarObject(SceneNode* node, int colour){
159        // check if this is the first RadarObject to create
160        if(firstRadarObject == NULL){
161            firstRadarObject = new RadarObject(container, node, colour);
162            lastRadarObject = firstRadarObject;
163        }
164        else{ // if not, append to list
165            lastRadarObject->next = new RadarObject(container, node, colour);
166            lastRadarObject = lastRadarObject->next;
167        }
168    }
169
170    RadarObject* HUD::getFirstRadarObject(){
171        return firstRadarObject;
172    }
173
174    /*static*/ HUD& HUD::getSingleton(){
175        static HUD theInstance;
176        return theInstance;
177    }
178
179    /*static*/ void HUD::setEnergy(float value){
180        HUD::getSingleton().energyBar->setValue(value);
181    }
182
183    /*static*/ void HUD::cycleNavigationFocus(){
184        HUD::getSingleton().nav->cycleFocus();
185    }
186}
187
188
189
190
191
192
Note: See TracBrowser for help on using the repository browser.