[1281] | 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: |
---|
[1328] | 24 | * Felix Schulthess |
---|
[1281] | 25 | * |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include <OgreOverlay.h> |
---|
| 31 | #include <OgreOverlayContainer.h> |
---|
[1302] | 32 | #include <OgreOverlayManager.h> |
---|
[1281] | 33 | #include <OgreSceneNode.h> |
---|
| 34 | #include <OgreEntity.h> |
---|
| 35 | #include "core/Debug.h" |
---|
| 36 | |
---|
| 37 | #include "HUD.h" |
---|
| 38 | #include "BarOverlayElement.h" |
---|
| 39 | #include "RadarOverlayElement.h" |
---|
| 40 | #include "OverlayElementFactories.h" |
---|
| 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | using namespace Ogre; |
---|
| 45 | |
---|
| 46 | HUD::HUD(int zoom){ |
---|
[1314] | 47 | om = &Ogre::OverlayManager::getSingleton(); |
---|
[1281] | 48 | |
---|
| 49 | BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); |
---|
[1314] | 50 | om->addOverlayElementFactory(barOverlayElementFactory); |
---|
[1302] | 51 | |
---|
[1281] | 52 | RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); |
---|
[1314] | 53 | om->addOverlayElementFactory(radarOverlayElementFactory); |
---|
[1281] | 54 | |
---|
[1314] | 55 | orxonoxHUD = om->create("Orxonox/HUD"); |
---|
[1302] | 56 | |
---|
[1314] | 57 | container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); |
---|
[1302] | 58 | |
---|
[1328] | 59 | energyCounter = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyCounter")); |
---|
[1314] | 60 | energyCounter->show(); |
---|
[1302] | 61 | |
---|
[1328] | 62 | speedo = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedo")); |
---|
[1314] | 63 | speedo->show(); |
---|
[1302] | 64 | |
---|
[1314] | 65 | radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); |
---|
[1281] | 66 | radar->show(); |
---|
| 67 | |
---|
[1314] | 68 | container->addChild(energyCounter); |
---|
| 69 | container->addChild(speedo); |
---|
| 70 | container->addChild(radar); |
---|
| 71 | container->show(); |
---|
| 72 | orxonoxHUD->add2D(container); |
---|
| 73 | orxonoxHUD->show(); |
---|
| 74 | container->setLeft(0.0); |
---|
| 75 | container->setTop(0.0); |
---|
| 76 | container->setWidth(1.0); |
---|
| 77 | container->setHeight(1.0); |
---|
| 78 | container->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
[1302] | 79 | |
---|
[1328] | 80 | energyCounter->init(0.01, 0.01, 0.2, 0.02, container); |
---|
| 81 | energyCounter->setValue(1); |
---|
[1302] | 82 | |
---|
[1328] | 83 | speedo->init(0.01, 0.04, 0.2, 0.02, container); |
---|
[1281] | 84 | |
---|
[1328] | 85 | radar->init(0.5, 0.9, 0.2, container); |
---|
[1281] | 86 | } |
---|
| 87 | |
---|
[1302] | 88 | void HUD::tick(float dt) |
---|
[1281] | 89 | { |
---|
[1314] | 90 | float v = SpaceShip::instance_s->getVelocity().length(); |
---|
| 91 | float vmax = SpaceShip::instance_s->getMaxSpeed(); |
---|
[1328] | 92 | speedo->setValue(v/vmax); |
---|
[1302] | 93 | radar->update(); |
---|
[1281] | 94 | } |
---|
[1302] | 95 | |
---|
[1328] | 96 | HUD::~HUD(void){ |
---|
| 97 | } |
---|
[1281] | 98 | } |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | |
---|