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