[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
[1502] | 4 | * |
---|
[1505] | 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
[1502] | 22 | * Author: |
---|
| 23 | * Yuning Chai |
---|
| 24 | * Co-authors: |
---|
| 25 | * Felix Schulthess |
---|
| 26 | * |
---|
| 27 | */ |
---|
[1283] | 28 | |
---|
[1502] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1283] | 30 | #include "RadarOverlayElement.h" |
---|
| 31 | |
---|
[1502] | 32 | #include <string> |
---|
| 33 | #include <OgreOverlayManager.h> |
---|
| 34 | #include <OgreStringConverter.h> |
---|
| 35 | |
---|
| 36 | #include "core/ConsoleCommand.h" |
---|
[1535] | 37 | #include "objects/Tickable.h" |
---|
[1502] | 38 | #include "objects/SpaceShip.h" |
---|
[1564] | 39 | #include "util/Math.h" |
---|
| 40 | |
---|
| 41 | #include "GraphicsEngine.h" |
---|
[1502] | 42 | #include "RadarObject.h" |
---|
| 43 | #include "HUD.h" |
---|
| 44 | |
---|
[1283] | 45 | namespace orxonox |
---|
| 46 | { |
---|
[1302] | 47 | using namespace Ogre; |
---|
[1283] | 48 | |
---|
[1502] | 49 | RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){ |
---|
[1302] | 50 | } |
---|
[1283] | 51 | |
---|
[1302] | 52 | RadarOverlayElement::~RadarOverlayElement(){ |
---|
| 53 | } |
---|
[1283] | 54 | |
---|
[1502] | 55 | void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){ |
---|
[1339] | 56 | // some initial data |
---|
[1314] | 57 | dimRel_ = dimRel; |
---|
| 58 | leftRel_ = leftRel; |
---|
| 59 | topRel_ = topRel; |
---|
[1283] | 60 | |
---|
[1502] | 61 | setMetricsMode(GMM_PIXELS); |
---|
[1310] | 62 | setMaterialName("Orxonox/Radar"); |
---|
[1314] | 63 | resize(); |
---|
[1339] | 64 | |
---|
[1564] | 65 | container->addChild(this); |
---|
[1283] | 66 | } |
---|
[1302] | 67 | |
---|
[1314] | 68 | void RadarOverlayElement::resize() { |
---|
| 69 | // if window is resized, we must adapt these... |
---|
[1564] | 70 | dim_ = (int) (dimRel_*GraphicsEngine::getSingleton().getWindowHeight()); |
---|
| 71 | left_ = (int) (leftRel_*GraphicsEngine::getSingleton().getWindowWidth()-dim_/2); |
---|
| 72 | top_ = (int) (topRel_*GraphicsEngine::getSingleton().getWindowHeight()-dim_/2); |
---|
[1314] | 73 | setPosition(left_, top_); |
---|
| 74 | setDimensions(dim_,dim_); |
---|
| 75 | } |
---|
| 76 | |
---|
[1302] | 77 | void RadarOverlayElement::update() { |
---|
[1339] | 78 | // iterate through all RadarObjects |
---|
[1564] | 79 | for(std::list<RadarObject*>::iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); it++) |
---|
| 80 | { |
---|
| 81 | // calc position on radar... |
---|
[1346] | 82 | // set size to fit distance... |
---|
[1564] | 83 | float distance = ((*it)->getPosition() - SpaceShip::getLocalShip()->getPosition()).length(); |
---|
| 84 | if (distance > 20000) (*it)->getPanel()->setDimensions(1, 1); |
---|
| 85 | else if (distance > 10000) (*it)->getPanel()->setDimensions(2, 2); |
---|
| 86 | else if (distance > 5000) (*it)->getPanel()->setDimensions(3, 3); |
---|
| 87 | else if (distance > 2500) (*it)->getPanel()->setDimensions(4, 4); |
---|
| 88 | else if (distance > 1000) (*it)->getPanel()->setDimensions(5, 5); |
---|
| 89 | else (*it)->getPanel()->setDimensions(6,6); |
---|
[1346] | 90 | |
---|
[1564] | 91 | Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), (*it)->getPosition()); |
---|
| 92 | coord = coord * Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture |
---|
| 93 | float dimfactor = dim_ / 2.0; |
---|
| 94 | (*it)->getPanel()->setPosition((1 + coord.x) * dimfactor + left_ - 2, |
---|
| 95 | (1 - coord.y) * dimfactor + top_ - 2); |
---|
[1502] | 96 | } |
---|
[1339] | 97 | } |
---|
[1310] | 98 | |
---|
[1564] | 99 | void RadarOverlayElement::listObjects() const { |
---|
[1502] | 100 | int i = 0; |
---|
| 101 | COUT(3) << "List of RadarObjects:\n"; |
---|
| 102 | // iterate through all Radar Objects |
---|
[1564] | 103 | for(std::list<RadarObject*>::const_iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); ++it){ |
---|
[1502] | 104 | COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl; |
---|
[1407] | 105 | } |
---|
| 106 | } |
---|
[1283] | 107 | } |
---|