[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 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include <OgreOverlay.h> |
---|
| 31 | #include <OgreOverlayContainer.h> |
---|
| 32 | #include <OgreOverlayManager.h> |
---|
| 33 | #include <OgreSceneNode.h> |
---|
| 34 | #include <OgreEntity.h> |
---|
| 35 | #include <OgreStringConverter.h> |
---|
| 36 | #include "core/Debug.h" |
---|
| 37 | #include "objects/SpaceShip.h" |
---|
| 38 | #include "HUD.h" |
---|
| 39 | #include "BarOverlayElement.h" |
---|
| 40 | #include "RadarOverlayElement.h" |
---|
| 41 | #include "OverlayElementFactories.h" |
---|
| 42 | |
---|
| 43 | namespace orxonox |
---|
| 44 | { |
---|
[1387] | 45 | ConsoleCommandShortcut(HUD, cycleRadarFocus, AccessLevel::User); |
---|
| 46 | |
---|
[1362] | 47 | using namespace Ogre; |
---|
| 48 | |
---|
[1387] | 49 | HUD::HUD(){ |
---|
[1362] | 50 | om = &Ogre::OverlayManager::getSingleton(); |
---|
| 51 | |
---|
| 52 | // create Factories |
---|
| 53 | BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); |
---|
| 54 | om->addOverlayElementFactory(barOverlayElementFactory); |
---|
| 55 | RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); |
---|
| 56 | om->addOverlayElementFactory(radarOverlayElementFactory); |
---|
| 57 | |
---|
| 58 | orxonoxHUD = om->create("Orxonox/HUD"); |
---|
| 59 | container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); |
---|
| 60 | // test |
---|
| 61 | test = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "test123")); |
---|
| 62 | test->show(); |
---|
| 63 | test->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
[1374] | 64 | test->setDimensions(0.3, 0.3); |
---|
[1362] | 65 | test->setPosition(0.02, 0.02); |
---|
| 66 | test->setFontName("Console"); |
---|
| 67 | test->setCaption("init"); |
---|
| 68 | |
---|
[1388] | 69 | // creating text to display fps |
---|
[1374] | 70 | fpsText = static_cast<TextAreaOverlayElement*>(om->createOverlayElement("TextArea", "fpsText")); |
---|
| 71 | fpsText->show(); |
---|
| 72 | fpsText->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
| 73 | fpsText->setDimensions(0.3, 0.3); |
---|
| 74 | fpsText->setPosition(0.9, 0.02); |
---|
| 75 | fpsText->setFontName("Console"); |
---|
| 76 | fpsText->setCaption("init"); |
---|
| 77 | |
---|
[1362] | 78 | // create energy bar |
---|
| 79 | energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar")); |
---|
| 80 | energyBar->show(); |
---|
| 81 | // create speedo bar |
---|
| 82 | speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar")); |
---|
| 83 | speedoBar->show(); |
---|
| 84 | // create radar |
---|
| 85 | radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); |
---|
| 86 | radar->show(); |
---|
| 87 | |
---|
| 88 | // set up screen-wide container |
---|
| 89 | container->show(); |
---|
| 90 | |
---|
| 91 | orxonoxHUD->add2D(container); |
---|
| 92 | orxonoxHUD->show(); |
---|
| 93 | container->setLeft(0.0); |
---|
| 94 | container->setTop(0.0); |
---|
| 95 | container->setWidth(1.0); |
---|
| 96 | container->setHeight(1.0); |
---|
| 97 | container->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
| 98 | container->addChild(test); |
---|
[1374] | 99 | container->addChild(fpsText); |
---|
[1362] | 100 | energyBar->init(0.01, 0.94, 0.4, container); |
---|
| 101 | energyBar->setValue(1); |
---|
| 102 | speedoBar->init(0.01, 0.90, 0.4, container); |
---|
| 103 | radar->init(0.5, 0.9, 0.2, container); |
---|
[1388] | 104 | radar->addObject(Vector3(2000.0, 1000.0, 1000.0)); |
---|
[1362] | 105 | radar->addObject(Vector3(0.0, 4000.0, 0.0)); |
---|
| 106 | radar->addObject(Vector3(0.0, 0.0, 6800.0)); |
---|
| 107 | } |
---|
| 108 | |
---|
[1387] | 109 | HUD::~HUD(){ |
---|
| 110 | //todo: clean up objects |
---|
| 111 | } |
---|
| 112 | |
---|
[1362] | 113 | void HUD::tick(float dt) |
---|
| 114 | { |
---|
[1375] | 115 | int d = (float)(radar->getDist2Focus()/10); |
---|
[1362] | 116 | if(d) test->setCaption("Distance: " + Ogre::StringConverter::toString(d)); |
---|
| 117 | else test->setCaption(""); |
---|
| 118 | |
---|
| 119 | energyBar->resize(); |
---|
| 120 | |
---|
| 121 | float v = SpaceShip::instance_s->getVelocity().length(); |
---|
| 122 | float vmax = SpaceShip::instance_s->getMaxSpeed(); |
---|
| 123 | speedoBar->setValue(v/vmax); |
---|
| 124 | speedoBar->resize(); |
---|
| 125 | |
---|
| 126 | radar->resize(); |
---|
| 127 | radar->update(); |
---|
| 128 | } |
---|
| 129 | |
---|
[1387] | 130 | /*static*/HUD& HUD::getSingleton(){ |
---|
| 131 | static HUD theInstance; |
---|
| 132 | return theInstance; |
---|
[1374] | 133 | } |
---|
| 134 | |
---|
[1387] | 135 | /*static*/void HUD::setFPS(float fps){ |
---|
| 136 | HUD::getSingleton().fpsText->setCaption("FPS: " + Ogre::StringConverter::toString(fps)); |
---|
[1362] | 137 | } |
---|
[1387] | 138 | |
---|
[1388] | 139 | /*static*/void HUD::setEnergy(float value){ |
---|
| 140 | HUD::getSingleton().energyBar->setValue(value); |
---|
| 141 | } |
---|
| 142 | |
---|
[1387] | 143 | /*static*/void HUD::cycleRadarFocus(){ |
---|
| 144 | HUD::getSingleton().radar->cycleFocus(); |
---|
| 145 | } |
---|
[1362] | 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|