[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 | * Felix Schulthess |
---|
| 24 | * Co-authors: |
---|
[1564] | 25 | * Fabian 'x3n' Landau |
---|
[1502] | 26 | * |
---|
| 27 | */ |
---|
[1346] | 28 | |
---|
[1502] | 29 | #include "OrxonoxStableHeaders.h" |
---|
[1346] | 30 | #include "RadarObject.h" |
---|
| 31 | |
---|
[1502] | 32 | #include <OgreOverlayManager.h> |
---|
[1562] | 33 | #include <OgreMaterialManager.h> |
---|
| 34 | #include <OgreTechnique.h> |
---|
| 35 | |
---|
[1502] | 36 | #include "GraphicsEngine.h" |
---|
[1564] | 37 | #include "objects/WorldEntity.h" |
---|
[1562] | 38 | #include "util/Convert.h" |
---|
[1502] | 39 | |
---|
[1562] | 40 | namespace std |
---|
| 41 | { |
---|
| 42 | template <> |
---|
| 43 | class less<orxonox::ColourValue> |
---|
| 44 | { |
---|
| 45 | public: |
---|
[1564] | 46 | bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const |
---|
[1562] | 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 | |
---|
[1346] | 65 | namespace orxonox |
---|
| 66 | { |
---|
[1562] | 67 | unsigned int RadarObject::count_s = 0; |
---|
[1563] | 68 | unsigned int RadarObject::materialcount_s = 0; |
---|
[1562] | 69 | std::map<std::string, std::map<ColourValue, std::string> > RadarObject::materials_s; |
---|
[1346] | 70 | |
---|
[1564] | 71 | RadarObject::RadarObject(Ogre::OverlayContainer* container, WorldEntity* object, const ColourValue& colour, const std::string& texturename) |
---|
[1562] | 72 | { |
---|
| 73 | this->colour_ = colour; |
---|
| 74 | this->texturename_ = texturename; |
---|
[1346] | 75 | |
---|
[1564] | 76 | this->object_ = object; |
---|
[1562] | 77 | |
---|
[1564] | 78 | this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s++))); |
---|
[1562] | 79 | this->setMaterial(colour, texturename); |
---|
| 80 | |
---|
[1564] | 81 | this->panel_->setDimensions(3, 3); |
---|
[1562] | 82 | this->panel_->setMetricsMode(Ogre::GMM_PIXELS); |
---|
| 83 | this->panel_->show(); |
---|
| 84 | |
---|
[1564] | 85 | container->addChild(panel_); |
---|
[1502] | 86 | } |
---|
| 87 | |
---|
[1562] | 88 | RadarObject::~RadarObject() |
---|
| 89 | { |
---|
[1564] | 90 | Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->panel_); |
---|
[1502] | 91 | } |
---|
| 92 | |
---|
[1562] | 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 | { |
---|
[1563] | 101 | materialname = "radarmaterial" + getConvertedValue<unsigned int, std::string>(RadarObject::materialcount_s++); |
---|
[1562] | 102 | Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); |
---|
[1563] | 103 | material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); |
---|
[1562] | 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; |
---|
[1502] | 108 | } |
---|
[1562] | 109 | else |
---|
| 110 | { |
---|
| 111 | materialname = (*it).second; |
---|
| 112 | } |
---|
[1502] | 113 | |
---|
[1562] | 114 | this->panel_->setMaterialName(materialname); |
---|
[1502] | 115 | } |
---|
| 116 | |
---|
[1564] | 117 | const Vector3& RadarObject::getPosition() const |
---|
[1562] | 118 | { |
---|
[1564] | 119 | return this->object_->getPosition(); |
---|
[1502] | 120 | } |
---|
| 121 | |
---|
[1566] | 122 | Vector3 RadarObject::getOrientedVelocity() const |
---|
[1562] | 123 | { |
---|
[1566] | 124 | return this->object_->getOrientation() * this->object_->getVelocity(); |
---|
[1502] | 125 | } |
---|
[1346] | 126 | } |
---|
[1407] | 127 | |
---|