Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/hud/RadarObject.cc @ 1569

Last change on this file since 1569 was 1566, checked in by landauf, 17 years ago
  • added a prediction-crosshair to the navigation focus
  • fixed a bug in SpaceShipAI's target movement prediction - bots are more accurate now
  • Property svn:eol-style set to native
File size: 4.2 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 *      Felix Schulthess
24 *   Co-authors:
25 *      Fabian 'x3n' Landau
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "RadarObject.h"
31
32#include <OgreOverlayManager.h>
33#include <OgreMaterialManager.h>
34#include <OgreTechnique.h>
35
36#include "GraphicsEngine.h"
37#include "objects/WorldEntity.h"
38#include "util/Convert.h"
39
40namespace std
41{
42    template <>
43    class less<orxonox::ColourValue>
44    {
45        public:
46            bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const
47            {
48                if (__x.r == __y.r)
49                {
50                    if (__x.g == __y.g)
51                    {
52                        if (__x.b == __y.b)
53                        {
54                            return __x.a < __y.a;
55                        }
56                        return __x.b < __y.b;
57                    }
58                    return __x.g < __y.g;
59                }
60                return __x.r < __y.r;
61            }
62    };
63}
64
65namespace orxonox
66{
67    unsigned int RadarObject::count_s = 0;
68    unsigned int RadarObject::materialcount_s = 0;
69    std::map<std::string, std::map<ColourValue, std::string> > RadarObject::materials_s;
70
71    RadarObject::RadarObject(Ogre::OverlayContainer* container, WorldEntity* object, const ColourValue& colour, const std::string& texturename)
72    {
73        this->colour_ = colour;
74        this->texturename_ = texturename;
75
76        this->object_ = object;
77
78        this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s++)));
79        this->setMaterial(colour, texturename);
80
81        this->panel_->setDimensions(3, 3);
82        this->panel_->setMetricsMode(Ogre::GMM_PIXELS);
83        this->panel_->show();
84
85        container->addChild(panel_);
86    }
87
88    RadarObject::~RadarObject()
89    {
90        Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_);
91    }
92
93    void RadarObject::setMaterial(const ColourValue& colour, const std::string& texturename)
94    {
95        std::map<ColourValue, std::string>& colourmap = this->materials_s[texturename];
96        std::map<ColourValue, std::string>::const_iterator it = colourmap.find(colour);
97        std::string materialname;
98
99        if (it == colourmap.end())
100        {
101            materialname = "radarmaterial" + getConvertedValue<unsigned int, std::string>(RadarObject::materialcount_s++);
102            Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");
103            material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
104            Ogre::TextureUnitState* textureunitstate = material->getTechnique(0)->getPass(0)->createTextureUnitState();
105            textureunitstate->setTextureName(texturename);
106            textureunitstate->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour);
107            colourmap[colour] = materialname;
108        }
109        else
110        {
111            materialname = (*it).second;
112        }
113
114        this->panel_->setMaterialName(materialname);
115    }
116
117    const Vector3& RadarObject::getPosition() const
118    {
119        return this->object_->getPosition();
120    }
121
122    Vector3 RadarObject::getOrientedVelocity() const
123    {
124        return this->object_->getOrientation() * this->object_->getVelocity();
125    }
126}
127
Note: See TracBrowser for help on using the repository browser.