Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/overlays/hud/HUDRadar.cc @ 2020

Last change on this file since 2020 was 2019, checked in by landauf, 16 years ago

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

  • Property svn:eol-style set to native
File size: 5.9 KB
RevLine 
[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
[1614]24 *      Felix Schulthess
[1502]25 *   Co-authors:
[1614]26 *      Reto Grieder
[1502]27 *
28 */
[1283]29
[1502]30#include "OrxonoxStableHeaders.h"
[1604]31#include "HUDRadar.h"
[1283]32
[1502]33#include <OgreOverlayManager.h>
[1614]34#include <OgrePanelOverlayElement.h>
[1502]35
[1614]36#include "util/Math.h"
[2019]37#include "util/String.h"
[1502]38#include "core/ConsoleCommand.h"
[1616]39#include "core/CoreIncludes.h"
40#include "core/XMLPort.h"
[1819]41#include "objects/Radar.h"
[1613]42#include "tools/TextureGenerator.h"
[1502]43
[1283]44namespace orxonox
45{
[1604]46    CreateFactory(HUDRadar);
47
[2019]48    HUDRadar::HUDRadar(BaseObject* creator) : OrxonoxOverlay(creator), marker_(0)
[1604]49    {
50        RegisterObject(HUDRadar);
[1302]51    }
[1283]52
[1604]53    HUDRadar::~HUDRadar()
54    {
[1615]55        if (this->marker_)
56            Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->marker_);
57        for (std::vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin();
58            it != this->radarDots_.end(); ++it)
[1604]59        {
[1615]60            Ogre::OverlayManager::getSingleton().destroyOverlayElement(*it);
[1604]61        }
[1302]62    }
[1283]63
[1604]64    void HUDRadar::XMLPort(Element& xmlElement, XMLPort::Mode mode)
65    {
[1747]66        SUPER(HUDRadar, XMLPort, xmlElement, mode);
[1283]67
[1613]68        if (mode == XMLPort::LoadObject)
69        {
[1615]70            marker_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton()
[2019]71                .createOverlayElement("Panel", "HUDRadar_marker_" + getUniqueNumberString()));
[1615]72            marker_->setMaterialName("Orxonox/RadarMarker");
73            overlay_->add2D(marker_);
74            marker_->hide();
[1613]75        }
[1609]76
[1627]77        XMLPortParam(HUDRadar, "sensitivity", setRadarSensitivity, getRadarSensitivity, xmlElement, mode)
78            .defaultValues(1.0f);
79        XMLPortParam(HUDRadar, "halfDotSizeDistance", setHalfDotSizeDistance, getHalfDotSizeDistance,
80            xmlElement, mode).defaultValues(3000.0f);
81        XMLPortParam(HUDRadar, "maximumDotSize", setMaximumDotSize, getMaximumDotSize, xmlElement, mode)
82            .defaultValues(0.1f);
[1613]83
84        shapeMaterials_[RadarViewable::Dot]      = "RadarSquare.tga";
85        shapeMaterials_[RadarViewable::Triangle] = "RadarSquare.tga";
86        shapeMaterials_[RadarViewable::Square]   = "RadarSquare.tga";
[1609]87    }
[1302]88
[1613]89    void HUDRadar::displayObject(RadarViewable* object, bool bIsMarked)
[1604]90    {
[1916]91/*
[1613]92        const WorldEntity* wePointer = object->getWorldEntity();
[1604]93
[1782]94        // Just to be sure that we actually have a WorldEntity.
95        // We could do a dynamic_cast, but that would be a lot slower.
[1613]96        if (!wePointer)
[1609]97        {
[1613]98            CCOUT(4) << "Cannot display a non-WorldEntitiy on the radar" << std::endl;
99            return;
[1609]100        }
[1916]101*/
[1613]102        // try to find a panel already created
103        Ogre::PanelOverlayElement* panel;
[1614]104        //std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object);
105        if (itRadarDots_ == this->radarDots_.end())
[1613]106        {
107            // we have to create a new entry
108            panel = static_cast<Ogre::PanelOverlayElement*>(
[2019]109                Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString()));
[1614]110            radarDots_.push_back(panel);
[1613]111            // get right material
112            panel->setMaterialName(TextureGenerator::getMaterialName(
113                shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour()));
114            this->overlay_->add2D(panel);
[1614]115            this->itRadarDots_ = this->radarDots_.end();
[1613]116        }
[1609]117        else
[1614]118        {
119            panel = *itRadarDots_;
120            ++itRadarDots_;
121            std::string materialName = TextureGenerator::getMaterialName(
122                shapeMaterials_[object->getRadarObjectType()], object->getRadarObjectColour());
123            if (materialName != panel->getMaterialName())
124                panel->setMaterialName(materialName);
125        }
[1782]126        panel->show();
[1916]127/*
[1613]128        // set size to fit distance...
129        float distance = (wePointer->getWorldPosition() - SpaceShip::getLocalShip()->getPosition()).length();
130        // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda)
131        float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance);
132        panel->setDimensions(size, size);
133
134        // calc position on radar...
135        Vector2 coord = get2DViewcoordinates(SpaceShip::getLocalShip()->getPosition(), SpaceShip::getLocalShip()->getDir(), SpaceShip::getLocalShip()->getOrth(), wePointer->getWorldPosition());
136        coord *= Ogre::Math::PI / 3.5; // small adjustment to make it fit the texture
137        panel->setPosition((1.0 + coord.x - size) * 0.5, (1.0 - coord.y - size) * 0.5);
138
139        if (bIsMarked)
140        {
141            this->marker_->show();
[1614]142            this->marker_->setDimensions(size * 1.5, size * 1.5);
143            this->marker_->setPosition((1.0 + coord.x - size * 1.5) * 0.5, (1.0 - coord.y - size * 1.5) * 0.5);
[1613]144        }
[1916]145*/
[1604]146    }
147
[1613]148    void HUDRadar::radarTick(float dt)
[1604]149    {
[1782]150        for (itRadarDots_ = radarDots_.begin(); itRadarDots_ != radarDots_.end(); ++itRadarDots_)
151            (*itRadarDots_)->hide();
[1614]152        this->itRadarDots_ = this->radarDots_.begin();
153        this->marker_->hide();
[1613]154    }
[1283]155}
Note: See TracBrowser for help on using the repository browser.