Changeset 1562 for code/trunk/src/orxonox/hud/RadarObject.cc
- Timestamp:
- Jun 7, 2008, 3:39:48 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/hud/RadarObject.cc
r1505 r1562 31 31 32 32 #include <OgreOverlayManager.h> 33 #include <OgreStringConverter.h> 33 #include <OgreMaterialManager.h> 34 #include <OgreTechnique.h> 35 34 36 #include "GraphicsEngine.h" 37 #include "util/Convert.h" 38 39 namespace std 40 { 41 template <> 42 class less<orxonox::ColourValue> 43 { 44 public: 45 bool operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) 46 { 47 if (__x.r == __y.r) 48 { 49 if (__x.g == __y.g) 50 { 51 if (__x.b == __y.b) 52 { 53 return __x.a < __y.a; 54 } 55 return __x.b < __y.b; 56 } 57 return __x.g < __y.g; 58 } 59 return __x.r < __y.r; 60 } 61 }; 62 } 35 63 36 64 namespace orxonox 37 65 { 38 using namespace Ogre; 66 unsigned int RadarObject::count_s = 0; 67 std::map<std::string, std::map<ColourValue, std::string> > RadarObject::materials_s; 39 68 40 int RadarObject::count = 0; // initialize static variable 69 RadarObject::RadarObject(Ogre::OverlayContainer* container, Ogre::SceneNode* node, const ColourValue& colour, const std::string& texturename) 70 { 71 this->colour_ = colour; 72 this->texturename_ = texturename; 41 73 42 RadarObject::RadarObject(OverlayContainer* container, SceneNode* node, int colour){ 43 container_ = container; 44 node_ = node; 45 colour_ = colour; 46 om = &OverlayManager::getSingleton(); 47 panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", 48 "Object"+StringConverter::toString(count))); 49 setColour(colour_); 50 panel_->setDimensions(3,3); 51 panel_->setMetricsMode(Ogre::GMM_PIXELS); 52 panel_->show(); 53 index_ = count; 54 count++; 55 container_->addChild(panel_); 74 this->container_ = container; 75 this->node_ = node; 76 77 this->panel_ = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarObject" + getConvertedValue<unsigned int, std::string>(RadarObject::count_s))); 78 this->setMaterial(colour, texturename); 79 80 this->panel_->setDimensions(3,3); 81 this->panel_->setMetricsMode(Ogre::GMM_PIXELS); 82 this->panel_->show(); 83 84 this->index_ = count_s++; 85 this->container_->addChild(panel_); 56 86 } 57 87 58 RadarObject::~RadarObject(){ 88 RadarObject::~RadarObject() 89 { 59 90 delete panel_; 60 91 } 61 92 62 void RadarObject::setColour(int colour){ 63 switch(colour){ 64 case RED: panel_->setMaterialName("Orxonox/RedDot"); break; 65 case YELLOW: panel_->setMaterialName("Orxonox/YellowDot"); break; 66 case GREEN: panel_->setMaterialName("Orxonox/GreenDot"); break; 67 case BLUE: panel_->setMaterialName("Orxonox/BlueDot"); break; 68 case WHITE: panel_->setMaterialName("Orxonox/WhiteDot"); break; 69 default: panel_->setMaterialName("Orxonox/RedDot"); break; 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::count_s); 102 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); 103 Ogre::TextureUnitState* textureunitstate = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 104 textureunitstate->setTextureName(texturename); 105 textureunitstate->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour); 106 colourmap[colour] = materialname; 70 107 } 108 else 109 { 110 materialname = (*it).second; 111 } 112 113 this->panel_->setMaterialName(materialname); 71 114 } 72 115 73 void RadarObject::resetColour(){ 74 setColour(colour_); 75 } 76 77 Vector3 RadarObject::getPosition(){ 116 Vector3 RadarObject::getPosition() 117 { 78 118 return node_->getPosition(); 79 119 } 80 120 81 SceneNode* RadarObject::getNode(){ 121 Ogre::SceneNode* RadarObject::getNode() 122 { 82 123 return node_; 83 124 }
Note: See TracChangeset
for help on using the changeset viewer.