Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/hud/RadarOverlayElement.cc @ 1564

Last change on this file since 1564 was 1564, checked in by landauf, 16 years ago
  • several small changes in most of the HUD classes (code cleanup): removed obsolete variables, privatized all member variables, removed resizing functioncalls from tick, destroying overlayelements, added some const qualifiers.
  • moved calculation functions for RadarObject-position to Math.h and changed the phi/right/radius format to Vector2. the functions are used too by SpaceShipAI.
  • cycleNavigationFocus takes the nearest object if focus was NULL
  • BarOverlayElement works in both directions (left to right and right to left)
  • fixed bug causing SpaceShipAI to not stop shooting when losing target - this also speeds up orxonox a lot, because there are less projectiles

####################################

!! UPDATE YOUR MEDIA REPOSITORY !!

####################################
…or the BarOverlayElement will look strange

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
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 *
22 *   Author:
23 *      Yuning Chai
24 *   Co-authors:
25 *      Felix Schulthess
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "RadarOverlayElement.h"
31
32#include <string>
33#include <OgreOverlayManager.h>
34#include <OgreStringConverter.h>
35
36#include "core/ConsoleCommand.h"
37#include "objects/Tickable.h"
38#include "objects/SpaceShip.h"
39#include "util/Math.h"
40
41#include "GraphicsEngine.h"
42#include "RadarObject.h"
43#include "HUD.h"
44
45namespace orxonox
46{
47    using namespace Ogre;
48
49    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
50    }
51
52    RadarOverlayElement::~RadarOverlayElement(){
53    }
54
55    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
56        // some initial data
57        dimRel_ = dimRel;
58        leftRel_ = leftRel;
59        topRel_ = topRel;
60
61        setMetricsMode(GMM_PIXELS);
62        setMaterialName("Orxonox/Radar");
63        resize();
64
65        container->addChild(this);
66    }
67
68    void RadarOverlayElement::resize() {
69        // if window is resized, we must adapt these...
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);
73        setPosition(left_, top_);
74        setDimensions(dim_,dim_);
75    }
76
77    void RadarOverlayElement::update() {
78        // iterate through all RadarObjects
79        for(std::list<RadarObject*>::iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); it++)
80        {
81            // calc position on radar...
82            // set size to fit distance...
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);
90
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);
96        }
97    }
98
99    void RadarOverlayElement::listObjects() const {
100        int i = 0;
101        COUT(3) << "List of RadarObjects:\n";
102        // iterate through all Radar Objects
103        for(std::list<RadarObject*>::const_iterator it=HUD::getSingleton().getRadarObjects().begin(); it!=HUD::getSingleton().getRadarObjects().end(); ++it){
104            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
105        }
106    }
107}
Note: See TracBrowser for help on using the repository browser.