| [1362] | 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 |  | 
|---|
| [1392] | 28 | #include <string.h> | 
|---|
| [1362] | 29 | #include "OrxonoxStableHeaders.h" | 
|---|
 | 30 | #include <OgreOverlay.h> | 
|---|
 | 31 | #include <OgreOverlayContainer.h> | 
|---|
 | 32 | #include <OgreOverlayManager.h> | 
|---|
 | 33 | #include <OgreStringConverter.h> | 
|---|
| [1392] | 34 |  | 
|---|
| [1362] | 35 | #include "core/Debug.h" | 
|---|
| [1392] | 36 | #include "core/ConsoleCommand.h" | 
|---|
| [1362] | 37 | #include "objects/SpaceShip.h" | 
|---|
 | 38 | #include "BarOverlayElement.h" | 
|---|
 | 39 | #include "RadarOverlayElement.h" | 
|---|
 | 40 | #include "OverlayElementFactories.h" | 
|---|
| [1392] | 41 | #include "HUD.h" | 
|---|
| [1362] | 42 |  | 
|---|
 | 43 | namespace orxonox | 
|---|
 | 44 | { | 
|---|
| [1393] | 45 |     ConsoleCommandShortcut(HUD, cycleNavigationFocus, AccessLevel::User); | 
|---|
| [1387] | 46 |  | 
|---|
| [1362] | 47 |     using namespace Ogre; | 
|---|
 | 48 |  | 
|---|
| [1387] | 49 |     HUD::HUD(){ | 
|---|
| [1362] | 50 |         om = &Ogre::OverlayManager::getSingleton(); | 
|---|
| [1393] | 51 |         firstRadarObject = NULL; | 
|---|
 | 52 |         lastRadarObject = NULL; | 
|---|
| [1362] | 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 |  | 
|---|
| [1388] | 63 |         // creating text to display fps | 
|---|
| [1374] | 64 |         fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText")); | 
|---|
 | 65 |         fpsText->show(); | 
|---|
| [1399] | 66 |         fpsText->setMetricsMode(Ogre::GMM_PIXELS); | 
|---|
 | 67 |         fpsText->setDimensions(0.001, 0.001); | 
|---|
 | 68 |         fpsText->setPosition(10, 10); | 
|---|
| [1374] | 69 |         fpsText->setFontName("Console"); | 
|---|
| [1399] | 70 |         fpsText->setCharHeight(20); | 
|---|
| [1374] | 71 |         fpsText->setCaption("init"); | 
|---|
 | 72 |  | 
|---|
| [1362] | 73 |         // create energy bar | 
|---|
 | 74 |         energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar")); | 
|---|
 | 75 |         energyBar->show(); | 
|---|
 | 76 |         // create speedo bar | 
|---|
 | 77 |         speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar")); | 
|---|
 | 78 |         speedoBar->show(); | 
|---|
 | 79 |         // create radar | 
|---|
 | 80 |         radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); | 
|---|
 | 81 |         radar->show(); | 
|---|
 | 82 |  | 
|---|
| [1393] | 83 |         // create Navigation | 
|---|
 | 84 |         nav = new Navigation(container); | 
|---|
 | 85 |  | 
|---|
| [1362] | 86 |                 // set up screen-wide container | 
|---|
 | 87 |         container->show(); | 
|---|
 | 88 |  | 
|---|
 | 89 |         orxonoxHUD->add2D(container); | 
|---|
 | 90 |         orxonoxHUD->show(); | 
|---|
 | 91 |         container->setLeft(0.0); | 
|---|
 | 92 |         container->setTop(0.0); | 
|---|
 | 93 |         container->setWidth(1.0); | 
|---|
 | 94 |         container->setHeight(1.0); | 
|---|
 | 95 |         container->setMetricsMode(Ogre::GMM_RELATIVE); | 
|---|
| [1374] | 96 |         container->addChild(fpsText); | 
|---|
| [1393] | 97 |  | 
|---|
| [1362] | 98 |         energyBar->init(0.01, 0.94, 0.4, container); | 
|---|
 | 99 |         energyBar->setValue(1); | 
|---|
| [1393] | 100 |  | 
|---|
| [1362] | 101 |         speedoBar->init(0.01, 0.90, 0.4, container); | 
|---|
| [1393] | 102 |  | 
|---|
| [1362] | 103 |         radar->init(0.5, 0.9, 0.2, container); | 
|---|
| [1400] | 104 |         addRadarObject(Vector3(2000.0, 0.0, 0.0)); | 
|---|
 | 105 |         addRadarObject(Vector3(0.0, 2000.0, 0.0)); | 
|---|
 | 106 |         addRadarObject(Vector3(0.0, 0.0, 2000.0)); | 
|---|
| [1362] | 107 |     } | 
|---|
 | 108 |  | 
|---|
| [1387] | 109 |     HUD::~HUD(){ | 
|---|
 | 110 |         //todo: clean up objects | 
|---|
 | 111 |     } | 
|---|
 | 112 |  | 
|---|
| [1362] | 113 |     void HUD::tick(float dt) | 
|---|
 | 114 |     { | 
|---|
 | 115 |         energyBar->resize(); | 
|---|
 | 116 |  | 
|---|
 | 117 |         float v = SpaceShip::instance_s->getVelocity().length(); | 
|---|
 | 118 |         float vmax = SpaceShip::instance_s->getMaxSpeed(); | 
|---|
 | 119 |         speedoBar->setValue(v/vmax); | 
|---|
 | 120 |         speedoBar->resize(); | 
|---|
 | 121 |  | 
|---|
 | 122 |         radar->resize(); | 
|---|
 | 123 |         radar->update(); | 
|---|
| [1393] | 124 |  | 
|---|
 | 125 |         nav->update(); | 
|---|
| [1362] | 126 |     } | 
|---|
 | 127 |  | 
|---|
| [1393] | 128 |     void HUD::addRadarObject(Vector3 pos){ | 
|---|
 | 129 |         // check if this is the first RadarObject to create | 
|---|
 | 130 |         if(firstRadarObject == NULL){ | 
|---|
 | 131 |             firstRadarObject = new RadarObject(container, pos); | 
|---|
 | 132 |             lastRadarObject = firstRadarObject; | 
|---|
 | 133 |         } | 
|---|
 | 134 |         else{ // if not, append to list | 
|---|
 | 135 |             lastRadarObject->next = new RadarObject(container, pos); | 
|---|
 | 136 |             lastRadarObject = lastRadarObject->next; | 
|---|
 | 137 |         } | 
|---|
 | 138 |     } | 
|---|
 | 139 |  | 
|---|
 | 140 |     RadarObject* HUD::getFirstRadarObject(){ | 
|---|
 | 141 |         return firstRadarObject; | 
|---|
 | 142 |     } | 
|---|
 | 143 |  | 
|---|
| [1387] | 144 |     /*static*/HUD& HUD::getSingleton(){ | 
|---|
 | 145 |         static HUD theInstance; | 
|---|
 | 146 |         return theInstance; | 
|---|
| [1374] | 147 |     } | 
|---|
 | 148 |  | 
|---|
| [1387] | 149 |     /*static*/void HUD::setFPS(float fps){ | 
|---|
 | 150 |         HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps)); | 
|---|
| [1362] | 151 |     } | 
|---|
| [1387] | 152 |  | 
|---|
| [1388] | 153 |     /*static*/void HUD::setEnergy(float value){ | 
|---|
 | 154 |         HUD::getSingleton().energyBar->setValue(value); | 
|---|
 | 155 |     } | 
|---|
 | 156 |  | 
|---|
| [1393] | 157 |     /*static*/void HUD::cycleNavigationFocus(){ | 
|---|
 | 158 |         HUD::getSingleton().nav->cycleFocus(); | 
|---|
| [1387] | 159 |     } | 
|---|
| [1362] | 160 | } | 
|---|
 | 161 |  | 
|---|
 | 162 |  | 
|---|
 | 163 |  | 
|---|
 | 164 |  | 
|---|
 | 165 |  | 
|---|
 | 166 |  | 
|---|