Changeset 6727 for code/branches/hudelements/src
- Timestamp:
- Apr 14, 2010, 7:54:41 PM (15 years ago)
- Location:
- code/branches/hudelements/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hudelements/src/modules/objects/triggers/CheckPoint.cc
r5929 r6727 38 38 CreateFactory(CheckPoint); 39 39 40 CheckPoint::CheckPoint(BaseObject* creator) : DistanceTrigger(creator) 40 CheckPoint::CheckPoint(BaseObject* creator) 41 : DistanceTrigger(creator) 42 , RadarViewable(creator) 41 43 { 42 44 RegisterObject(CheckPoint); -
code/branches/hudelements/src/modules/overlays/hud/HUDRadar.cc
r6502 r6727 40 40 #include "worldentities/WorldEntity.h" 41 41 #include "worldentities/pawns/Pawn.h" 42 #include "Scene.h" 43 #include "Radar.h" 42 44 43 45 namespace orxonox … … 72 74 { 73 75 Ogre::OverlayManager::getSingleton().destroyOverlayElement(this->marker_); 74 for (std:: vector<Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.begin();75 it != this->radar Dots_.end(); ++it)76 for (std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it = this->radarObjects_.begin(); 77 it != this->radarObjects_.end(); ++it) 76 78 { 77 Ogre::OverlayManager::getSingleton().destroyOverlayElement( *it);79 Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second); 78 80 } 79 81 } … … 89 91 } 90 92 91 void HUDRadar:: displayObject(RadarViewable* object, bool bIsMarked)93 void HUDRadar::addObject(RadarViewable* object) 92 94 { 93 if (object == static_cast<RadarViewable*>(this->owner_))95 if (object == dynamic_cast<RadarViewable*>(this->owner_)) 94 96 return; 95 97 96 const WorldEntity* wePointer = object->getWorldEntity(); 98 // Make sure the object hasn't been added yet 99 assert( this->radarObjects_.find(object) == this->radarObjects_.end() ); 97 100 98 // Just to be sure that we actually have a WorldEntity. 99 // We could do a dynamic_cast, but that would be a lot slower. 100 if (!wePointer || !this->owner_) 101 // Create everything needed to display the object on the radar and add it to the map 102 Ogre::PanelOverlayElement* panel; 103 panel = static_cast<Ogre::PanelOverlayElement*>( 104 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 105 this->overlay_->add2D(panel); 106 // get right material 107 panel->setMaterialName(TextureGenerator::getMaterialName( 108 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 109 this->radarObjects_[object] = panel; 110 } 111 112 void HUDRadar::removeObject(RadarViewable* object) 113 { 114 // If object was added at all then remove it 115 std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it; 116 it = this->radarObjects_.find( object ); 117 if( it != this->radarObjects_.end() ) 101 118 { 102 if (!wePointer) 103 CCOUT(2) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 104 if (!this->owner_) 105 CCOUT(2) << "No owner defined" << std::endl; 106 return; 119 delete it->second; 120 this->radarObjects_.erase(it); 107 121 } 122 } 108 123 109 // try to find a panel already created 110 Ogre::PanelOverlayElement* panel; 111 //std::map<RadarViewable*, Ogre::PanelOverlayElement*>::iterator it = this->radarDots_.find(object); 112 if (itRadarDots_ == this->radarDots_.end()) 113 { 114 // we have to create a new entry 115 panel = static_cast<Ogre::PanelOverlayElement*>( 116 Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "RadarDot" + getUniqueNumberString())); 117 radarDots_.push_back(panel); 118 // get right material 119 panel->setMaterialName(TextureGenerator::getMaterialName( 120 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour())); 121 this->overlay_->add2D(panel); 122 this->itRadarDots_ = this->radarDots_.end(); 123 } 124 else 125 { 126 panel = *itRadarDots_; 127 ++itRadarDots_; 128 const std::string& materialName = TextureGenerator::getMaterialName( 129 shapeMaterials_[object->getRadarObjectShape()], object->getRadarObjectColour()); 130 if (materialName != panel->getMaterialName()) 131 panel->setMaterialName(materialName); 132 } 133 panel->show(); 124 void HUDRadar::objectChanged( RadarViewable* rv ) 125 { 126 assert( this->radarObjects_.find(rv) != this->radarObjects_.end() ); 127 Ogre::PanelOverlayElement* panel = this->radarObjects_[rv]; 128 panel->setMaterialName(TextureGenerator::getMaterialName( 129 shapeMaterials_[rv->getRadarObjectShape()], rv->getRadarObjectColour())); 130 } 134 131 135 // set size to fit distance... 136 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 137 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 138 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); 139 panel->setDimensions(size, size); 140 141 // calc position on radar... 142 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 143 coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture 144 panel->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f); 145 146 if (bIsMarked) 147 { 148 this->marker_->show(); 149 this->marker_->setDimensions(size * 1.5f, size * 1.5f); 150 this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f); 151 } 132 void HUDRadar::gatherObjects() 133 { 134 const std::set<RadarViewable*>& objectSet = this->getCreator()->getScene()->getRadar()->getRadarObjects(); 135 std::set<RadarViewable*>::const_iterator it; 136 for( it=objectSet.begin(); it!=objectSet.end(); ++it ) 137 this->addObject(*it); 152 138 } 153 139 154 140 void HUDRadar::radarTick(float dt) 155 141 { 156 for (itRadarDots_ = radarDots_.begin(); itRadarDots_ != radarDots_.end(); ++itRadarDots_) 157 (*itRadarDots_)->hide(); 158 this->itRadarDots_ = this->radarDots_.begin(); 159 this->marker_->hide(); 142 // Make sure the owner of the radar was defined 143 if( !this->owner_ ) 144 { 145 CCOUT(0) << "No owner defined" << std::endl; 146 assert(0); 147 } 148 149 this->marker_->hide(); // in case that no object is in focus 150 // get the focus object 151 Radar* radar = this->getOwner()->getScene()->getRadar(); 152 const RadarViewable* focusObject = radar->getFocus(); 153 154 // update the distances for all objects 155 std::map<RadarViewable*,Ogre::PanelOverlayElement*>::iterator it; 156 for( it = this->radarObjects_.begin(); it != this->radarObjects_.end(); ++it ) 157 { 158 // Make sure the object really is a WorldEntity 159 const WorldEntity* wePointer = it->first->getWorldEntity(); 160 if( !wePointer ) 161 { 162 CCOUT(0) << "Cannot display a non-WorldEntitiy on the radar" << std::endl; 163 assert(0); 164 } 165 bool isFocus = (it->first == focusObject); 166 // set size to fit distance... 167 float distance = (wePointer->getWorldPosition() - this->owner_->getPosition()).length(); 168 // calculate the size with 1/distance dependency for simplicity (instead of exp(-distance * lambda) 169 float size = maximumDotSize_ * halfDotSizeDistance_ / (halfDotSizeDistance_ + distance); 170 it->second->setDimensions(size, size); 171 172 // calc position on radar... 173 Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 174 coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture 175 it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f); 176 it->second->show(); 177 178 // if this object is in focus, then set the focus marker 179 if (isFocus) 180 { 181 this->marker_->setDimensions(size * 1.5f, size * 1.5f); 182 this->marker_->setPosition((1.0f + coord.x - size * 1.5f) * 0.5f, (1.0f - coord.y - size * 1.5f) * 0.5f); 183 this->marker_->show(); 184 } 185 } 160 186 } 161 187 … … 165 191 166 192 this->owner_ = orxonox_cast<Pawn*>(this->getOwner()); 193 assert(this->radarObjects_.size()==0); 194 this->gatherObjects(); 167 195 } 168 196 } -
code/branches/hudelements/src/modules/overlays/hud/HUDRadar.h
r5781 r6727 65 65 66 66 // RadarListener interface 67 void displayObject(RadarViewable* viewable, bool bIsMarked); 67 virtual void addObject(RadarViewable* viewable); 68 virtual void removeObject(RadarViewable* viewable); 69 virtual void objectChanged( RadarViewable* rv ); 68 70 void radarTick(float dt); 71 72 void gatherObjects(); 69 73 70 74 std::map<RadarViewable::Shape, std::string> shapeMaterials_; 71 75 72 std::vector<Ogre::PanelOverlayElement*> radarDots_; 73 std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_; 76 // std::vector<Ogre::PanelOverlayElement*> radarDots_; 77 // std::vector<Ogre::PanelOverlayElement*>::iterator itRadarDots_; 78 std::map<RadarViewable*, Ogre::PanelOverlayElement*> radarObjects_; 74 79 Ogre::PanelOverlayElement* marker_; 75 80 -
code/branches/hudelements/src/orxonox/Radar.cc
r6417 r6727 77 77 } 78 78 79 void Radar::addRadarObject(RadarViewable* rv) 80 { 81 assert( this->radarObjects_.find(rv) == this->radarObjects_.end() ); 82 this->radarObjects_.insert(rv); 83 // iterate through all radarlisteners and notify them 84 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 85 { 86 (*itListener)->addObject(rv); 87 } 88 } 89 90 void Radar::removeRadarObject(RadarViewable* rv) 91 { 92 assert( this->radarObjects_.find(rv) != this->radarObjects_.end() ); 93 this->radarObjects_.erase(rv); 94 // iterate through all radarlisteners and notify them 95 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 96 { 97 (*itListener)->removeObject(rv); 98 } 99 } 100 79 101 const RadarViewable* Radar::getFocus() 80 102 { … … 109 131 { 110 132 (*itListener)->radarTick(dt); 111 112 for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)113 {114 if ((*itElement)->getRadarVisibility())115 if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())116 (*itListener)->displayObject(*itElement, *itElement == this->focus_);117 }118 133 } 119 134 } … … 188 203 } 189 204 } 205 206 void Radar::radarObjectChanged(RadarViewable* rv) 207 { 208 for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener) 209 { 210 (*itListener)->objectChanged(rv); 211 } 212 } 190 213 } -
code/branches/hudelements/src/orxonox/Radar.h
r6417 r6727 38 38 39 39 #include <map> 40 #include <set> 40 41 #include <string> 41 42 … … 48 49 class _OrxonoxExport Radar : public Tickable 49 50 { 51 friend class RadarViewable; 50 52 public: 51 53 Radar(); … … 58 60 59 61 void listObjects() const; 62 const std::set<RadarViewable*>& getRadarObjects() const 63 { return this->radarObjects_; } 60 64 61 65 void releaseFocus(); … … 66 70 67 71 void updateFocus(); 72 void addRadarObject(RadarViewable* rv); 73 void removeRadarObject(RadarViewable* rv); 74 void radarObjectChanged(RadarViewable* rv); 68 75 69 76 ObjectListIterator<RadarViewable> itFocus_; 70 77 RadarViewable* focus_; 71 78 std::map<std::string, RadarViewable::Shape> objectTypes_; 79 std::set<RadarViewable*> radarObjects_; 72 80 int objectTypeCounter_; 73 81 }; -
code/branches/hudelements/src/orxonox/interfaces/RadarListener.h
r5781 r6727 41 41 virtual ~RadarListener() { } 42 42 43 virtual void displayObject(RadarViewable* viewable, bool bIsMarked) = 0; 43 virtual void addObject(RadarViewable* viewable) = 0; 44 virtual void removeObject(RadarViewable* viewable) = 0; 45 virtual void objectChanged(RadarViewable* viewable) = 0; 44 46 virtual float getRadarSensitivity() const = 0; 45 47 virtual void radarTick(float dt) = 0; -
code/branches/hudelements/src/orxonox/interfaces/RadarViewable.cc
r6717 r6727 40 40 @brief Constructor. 41 41 */ 42 RadarViewable::RadarViewable( )42 RadarViewable::RadarViewable(BaseObject* creator) 43 43 : isHumanShip_(false) 44 44 , bVisibility_(true) 45 , bInitialized_(false) 46 , creator_(creator) 45 47 , radarObjectCamouflage_(0.0f) 46 48 , radarObjectShape_(Dot) … … 50 52 51 53 this->uniqueId_=getUniqueNumberString(); 54 this->creator_->getScene()->getRadar()->addRadarObject(this); 55 this->bInitialized_ = true; 52 56 } 53 57 … … 55 59 RadarViewable::~RadarViewable() 56 60 { 61 if( this->bInitialized_ ) 62 this->creator_->getScene()->getRadar()->removeRadarObject(this); 57 63 } 58 64 59 void RadarViewable::setRadarObjectDescription(const std::string& str)60 {61 Radar* radar = this->getWorldEntity()->getScene()->getRadar();62 if (radar)63 this->radarObjectShape_ = radar->addObjectDescription(str);64 else65 {66 CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;67 }68 this->radarObjectDescription_ = str;69 }65 // void RadarViewable::setRadarObjectDescription(const std::string& str) 66 // { 67 // Radar* radar = this->getWorldEntity()->getScene()->getRadar(); 68 // if (radar) 69 // this->radarObjectShape_ = radar->addObjectDescription(str); 70 // else 71 // { 72 // CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl; 73 // } 74 // this->radarObjectDescription_ = str; 75 // } 70 76 71 77 const Vector3& RadarViewable::getRVWorldPosition() const … … 91 97 } 92 98 } 99 100 void RadarViewable::settingsChanged() 101 { 102 this->creator_->getScene()->getRadar()->radarObjectChanged(this); 103 } 93 104 } -
code/branches/hudelements/src/orxonox/interfaces/RadarViewable.h
r6717 r6727 40 40 namespace orxonox 41 41 { 42 class BaseObject; 43 42 44 /** 43 45 @brief Interface for receiving window events. … … 55 57 56 58 public: 57 RadarViewable( );59 RadarViewable(BaseObject* creator); 58 60 virtual ~RadarViewable(); 59 61 60 62 inline void setRadarObjectCamouflage(float camouflage) 61 { this->radarObjectCamouflage_ = camouflage; } 63 { 64 if( this->radarObjectCamouflage_ != camouflage ) 65 { 66 this->radarObjectCamouflage_ = camouflage; 67 this->settingsChanged(); 68 } 69 } 62 70 inline float getRadarObjectCamouflage() const 63 71 { return this->radarObjectCamouflage_; } 64 72 65 73 inline void setRadarObjectColour(const ColourValue& colour) 66 { this->radarObjectColour_ = colour; } 74 { 75 if(this->radarObjectColour_ != colour) 76 { 77 this->radarObjectColour_ = colour; 78 this->settingsChanged(); 79 } 80 } 67 81 inline const ColourValue& getRadarObjectColour() const 68 82 { return this->radarObjectColour_; } 69 83 70 void setRadarObjectDescription(const std::string& str);71 inline const std::string& getRadarObjectDescription() const72 { return this->radarObjectDescription_; }84 // void setRadarObjectDescription(const std::string& str); 85 // inline const std::string& getRadarObjectDescription() const 86 // { return this->radarObjectDescription_; } 73 87 74 88 inline void setRadarVisibility(bool b) 75 { this->bVisibility_ = b; } 89 { 90 if(b!=this->bVisibility_) 91 { 92 this->bVisibility_ = b; 93 this->settingsChanged(); 94 } 95 } 76 96 inline bool getRadarVisibility() const 77 97 { return this->bVisibility_; } … … 83 103 84 104 inline void setRadarObjectShape(Shape shape) 85 { this->radarObjectShape_ = shape; } 105 { 106 if( this->radarObjectShape_ != shape ) 107 { 108 this->radarObjectShape_ = shape; 109 this->settingsChanged(); 110 } 111 } 86 112 inline Shape getRadarObjectShape() const 87 113 { return this->radarObjectShape_; } 114 void settingsChanged(); 88 115 89 116 … … 98 125 void validate(const WorldEntity* object) const; 99 126 bool bVisibility_; 127 bool bInitialized_; 100 128 //Map 101 129 std::string uniqueId_; 130 BaseObject* creator_; 102 131 103 132 -
code/branches/hudelements/src/orxonox/worldentities/pawns/Pawn.cc
r6540 r6727 53 53 CreateFactory(Pawn); 54 54 55 Pawn::Pawn(BaseObject* creator) : ControllableEntity(creator) 55 Pawn::Pawn(BaseObject* creator) 56 : ControllableEntity(creator) 57 , RadarViewable(creator) 56 58 { 57 59 RegisterObject(Pawn);
Note: See TracChangeset
for help on using the changeset viewer.