[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" |
---|
[1335] | 36 | #include "objects/SpaceShip.h" |
---|
[1281] | 37 | #include "HUD.h" |
---|
| 38 | #include "BarOverlayElement.h" |
---|
| 39 | #include "RadarOverlayElement.h" |
---|
| 40 | #include "OverlayElementFactories.h" |
---|
| 41 | |
---|
| 42 | namespace orxonox |
---|
| 43 | { |
---|
[1330] | 44 | using namespace Ogre; |
---|
[1281] | 45 | |
---|
[1330] | 46 | HUD::HUD(int zoom){ |
---|
| 47 | om = &Ogre::OverlayManager::getSingleton(); |
---|
[1339] | 48 | |
---|
[1335] | 49 | // create Factories |
---|
[1330] | 50 | BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); |
---|
| 51 | om->addOverlayElementFactory(barOverlayElementFactory); |
---|
| 52 | RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); |
---|
| 53 | om->addOverlayElementFactory(radarOverlayElementFactory); |
---|
[1281] | 54 | |
---|
[1330] | 55 | orxonoxHUD = om->create("Orxonox/HUD"); |
---|
| 56 | container = static_cast<Ogre::OverlayContainer*>(om->createOverlayElement("Panel", "Orxonox/HUD/container")); |
---|
[1339] | 57 | // create energy bar |
---|
[1335] | 58 | energyBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "energyBar")); |
---|
| 59 | energyBar->show(); |
---|
| 60 | // create speedo bar |
---|
| 61 | speedoBar = static_cast<BarOverlayElement*>(om->createOverlayElement("Bar", "speedoBar")); |
---|
| 62 | speedoBar->show(); |
---|
| 63 | // create radar |
---|
[1330] | 64 | radar = static_cast<RadarOverlayElement*>(om->createOverlayElement("Radar", "radar")); |
---|
| 65 | radar->show(); |
---|
[1281] | 66 | |
---|
[1335] | 67 | // set up screen-wide container |
---|
[1330] | 68 | container->show(); |
---|
[1339] | 69 | |
---|
[1330] | 70 | orxonoxHUD->add2D(container); |
---|
| 71 | orxonoxHUD->show(); |
---|
| 72 | container->setLeft(0.0); |
---|
| 73 | container->setTop(0.0); |
---|
| 74 | container->setWidth(1.0); |
---|
| 75 | container->setHeight(1.0); |
---|
| 76 | container->setMetricsMode(Ogre::GMM_RELATIVE); |
---|
[1342] | 77 | energyBar->init(0.01, 0.94, 0.4, container); |
---|
[1335] | 78 | energyBar->setValue(1); |
---|
[1342] | 79 | speedoBar->init(0.01, 0.90, 0.4, container); |
---|
[1330] | 80 | radar->init(0.5, 0.9, 0.2, container); |
---|
[1339] | 81 | radar->addObject(Vector3(1500.0, 0.0, 0.0)); |
---|
| 82 | radar->addObject(Vector3(0.0, 4000.0, 0.0)); |
---|
[1352] | 83 | radar->addObject(Vector3(0.0, 0.0, 6800.0)); |
---|
[1350] | 84 | RadarOverlayElement::cycleFocus(); |
---|
[1330] | 85 | } |
---|
[1281] | 86 | |
---|
[1330] | 87 | void HUD::tick(float dt) |
---|
| 88 | { |
---|
[1335] | 89 | energyBar->resize(); |
---|
[1329] | 90 | |
---|
[1330] | 91 | float v = SpaceShip::instance_s->getVelocity().length(); |
---|
| 92 | float vmax = SpaceShip::instance_s->getMaxSpeed(); |
---|
[1335] | 93 | speedoBar->setValue(v/vmax); |
---|
| 94 | speedoBar->resize(); |
---|
[1329] | 95 | |
---|
[1330] | 96 | radar->resize(); |
---|
| 97 | radar->update(); |
---|
| 98 | } |
---|
[1302] | 99 | |
---|
[1330] | 100 | HUD::~HUD(void){ |
---|
| 101 | } |
---|
[1281] | 102 | } |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|