[Orxonox-commit 4609] r9280 - code/branches/presentation2012merge/src/modules/overlays/hud
landauf at orxonox.net
landauf at orxonox.net
Tue Jun 5 22:29:18 CEST 2012
Author: landauf
Date: 2012-06-05 22:29:17 +0200 (Tue, 05 Jun 2012)
New Revision: 9280
Modified:
code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.cc
code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.h
Log:
reformatted HUDNavigation... wtf happened here? do people know we have a style-guide?
no functional changes in code
Modified: code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.cc
===================================================================
--- code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.cc 2012-06-04 20:50:28 UTC (rev 9279)
+++ code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.cc 2012-06-05 20:29:17 UTC (rev 9280)
@@ -54,395 +54,374 @@
namespace orxonox
{
-bool compareDistance ( std::pair<RadarViewable*, unsigned int > a, std::pair<RadarViewable*, unsigned int > b )
-{
- return a.second<b.second;
+ bool compareDistance(std::pair<RadarViewable*, unsigned int> a, std::pair<RadarViewable*, unsigned int> b)
+ {
+ return a.second < b.second;
+ }
-}
+ CreateFactory ( HUDNavigation );
-void HUDNavigation::setConfigValues()
-{
- SetConfigValue(markerLimit_, 3);
- SetConfigValue(showDistance, false);
-}
+ HUDNavigation::HUDNavigation(BaseObject* creator) : OrxonoxOverlay(creator)
+ {
+ RegisterObject(HUDNavigation);
+ this->setConfigValues();
-CreateFactory ( HUDNavigation );
+ // Set default values
+ this->setFont("Monofur");
+ this->setTextSize(0.05f);
+ this->setNavMarkerSize(0.05f);
+ this->setDetectionLimit(10000.0f);
+ }
-HUDNavigation::HUDNavigation ( BaseObject* creator )
- : OrxonoxOverlay ( creator )
-{
- RegisterObject ( HUDNavigation );
- this->setConfigValues();
+ HUDNavigation::~HUDNavigation()
+ {
+ if (this->isInitialized())
+ {
+ for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end();)
+ removeObject((it++)->first);
+ }
+ this->sortedObjectList_.clear();
+ }
- // Set default values
- this->setFont ( "Monofur" );
- this->setTextSize ( 0.05f );
- this->setNavMarkerSize ( 0.05f );
- this->setDetectionLimit( 10000.0f );
-}
+ void HUDNavigation::setConfigValues()
+ {
+ SetConfigValue(markerLimit_, 3);
+ SetConfigValue(showDistance_, false);
+ }
-HUDNavigation::~HUDNavigation()
-{
- if ( this->isInitialized() )
+ void HUDNavigation::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
- for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); )
- removeObject ( ( it++ )->first );
+ SUPER(HUDNavigation, XMLPort, xmlelement, mode);
+ XMLPortParam(HUDNavigation, "font", setFont, getFont, xmlelement, mode);
+ XMLPortParam(HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode);
+ XMLPortParam(HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode);
+ XMLPortParam(HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode);
}
- sortedObjectList_.clear();
-}
+ void HUDNavigation::setFont(const std::string& font)
+ {
+ const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font);
+ if (fontPtr.isNull())
+ {
+ orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
+ return;
+ }
+ this->fontName_ = font;
+ for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
+ {
+ if (it->second.text_ != NULL)
+ it->second.text_->setFontName(this->fontName_);
+ }
+ }
-void HUDNavigation::XMLPort ( Element& xmlelement, XMLPort::Mode mode )
-{
- SUPER ( HUDNavigation, XMLPort, xmlelement, mode );
-
- XMLPortParam ( HUDNavigation, "font", setFont, getFont, xmlelement, mode );
- XMLPortParam ( HUDNavigation, "textSize", setTextSize, getTextSize, xmlelement, mode );
- XMLPortParam ( HUDNavigation, "navMarkerSize", setNavMarkerSize, getNavMarkerSize, xmlelement, mode );
- XMLPortParam ( HUDNavigation, "detectionLimit", setDetectionLimit, getDetectionLimit, xmlelement, mode );
-}
-
-void HUDNavigation::setFont ( const std::string& font )
-{
- const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName ( font );
- if ( fontPtr.isNull() )
+ const std::string& HUDNavigation::getFont() const
{
- orxout(internal_warning) << "HUDNavigation: Font '" << font << "' not found" << endl;
- return;
+ return this->fontName_;
}
- fontName_ = font;
- for ( ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it )
+
+ void HUDNavigation::setTextSize(float size)
{
- if ( it->second.text_ != NULL )
- it->second.text_->setFontName ( fontName_ );
+ if (size <= 0.0f)
+ {
+ orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
+ return;
+ }
+ this->textSize_ = size;
+ for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it!=this->activeObjectList_.end(); ++it)
+ {
+ if (it->second.text_)
+ it->second.text_->setCharHeight(size);
+ }
}
-}
-const std::string& HUDNavigation::getFont() const
-{
- return fontName_;
-}
-
-void HUDNavigation::setTextSize ( float size )
-{
- if ( size <= 0.0f )
+ float HUDNavigation::getTextSize() const
{
- orxout(internal_warning) << "HUDNavigation: Negative font size not allowed" << endl;
- return;
+ return this->textSize_;
}
- textSize_ = size;
- for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
+
+ float HUDNavigation::getArrowSizeX(int dist) const
{
- if ( it->second.text_ )
- it->second.text_->setCharHeight ( size );
+ if (dist < 600)
+ dist = 600;
+ return this->getActualSize().x * 900 * this->navMarkerSize_ / dist;
}
-}
-float HUDNavigation::getTextSize() const
-{
- return textSize_;
-}
-
-float HUDNavigation::getArrowSizeX(int dist)
-{
- if (dist < 600)
- dist = 600;
- return this->getActualSize().x * 900 * navMarkerSize_ / dist;
-}
-
-float HUDNavigation::getArrowSizeY(int dist)
-{
- if (dist < 600)
- dist = 600;
- return this->getActualSize().y * 900 * navMarkerSize_ / dist;
-}
-
-void HUDNavigation::tick ( float dt )
-{
- SUPER ( HUDNavigation, tick, dt );
-
- Camera* cam = CameraManager::getInstance().getActiveCamera();
- if ( cam == NULL )
- return;
- const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
-
-
- for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
+ float HUDNavigation::getArrowSizeY(int dist) const
{
- listIt->second = ( int ) ( ( listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition() ).length() + 0.5f );
+ if (dist < 600)
+ dist = 600;
+ return this->getActualSize().y * 900 * this->navMarkerSize_ / dist;
}
- sortedObjectList_.sort ( compareDistance );
-
- unsigned int markerCount_ = 0;
- bool closeEnough_ = false; //only display objects that are close enough to be relevant for the player
-
-// for (ObjectMap::iterator it = activeObjectList_.begin(); it != activeObjectList_.end(); ++it)
- for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++markerCount_, ++listIt )
+ void HUDNavigation::tick(float dt)
{
- ObjectMap::iterator it = activeObjectList_.find ( listIt->first );
- closeEnough_ = listIt->second < detectionLimit_ ;
- // display radarviewables on HUD if the marker limit and max-distance is not exceeded
- if ( markerCount_ < markerLimit_ && (closeEnough_ || detectionLimit_ < 0) )
- {
+ SUPER(HUDNavigation, tick, dt);
+ Camera* cam = CameraManager::getInstance().getActiveCamera();
+ if (cam == NULL)
+ return;
+ const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix();
- // Get Distance to HumanController and save it in the TextAreaOverlayElement.
- int dist = listIt->second;
- float textLength = 0.0f;
- //display distance next to cursor
- if (showDistance){
- it->second.text_->setCaption ( multi_cast<std::string> ( dist ) );
- textLength = multi_cast<std::string> ( dist ).size() * it->second.text_->getCharHeight() * 0.3f;
- }
+ for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
+ listIt->second = (int)((listIt->first->getRVWorldPosition() - HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition()).length() + 0.5f);
- //display name next to cursor
- else{
- it->second.text_->setCaption(it->first->getRadarName());
- textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
- }
+ this->sortedObjectList_.sort(compareDistance);
- // Transform to screen coordinates
- Vector3 pos = camTransform * it->first->getRVWorldPosition();
+ unsigned int markerCount = 0;
+ bool closeEnough = false; // only display objects that are close enough to be relevant for the player
- bool outOfView = true;
- if ( pos.z > 1.0 )
+ for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++markerCount, ++listIt)
+ {
+ std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(listIt->first);
+ closeEnough = listIt->second < this->detectionLimit_;
+ // display radarviewables on HUD if the marker limit and max-distance is not exceeded
+ if (markerCount < this->markerLimit_ && (closeEnough || this->detectionLimit_ < 0))
{
- // z > 1.0 means that the object is behind the camera
- outOfView = true;
- // we have to switch all coordinates (if you don't know why,
- // try linear algebra lectures, because I can't explain..)
- pos.x = -pos.x;
- pos.y = -pos.y;
- }
- else
- outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
+ // Get Distance to HumanController and save it in the TextAreaOverlayElement.
+ int dist = listIt->second;
+ float textLength = 0.0f;
- if ( outOfView )
- {
- // Object is not in view
-
- // Change material only if outOfView changed
- if ( !it->second.wasOutOfView_ )
+ if (this->showDistance_)
{
- it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "arrows.png", it->first->getRadarObjectColour()) );
- it->second.wasOutOfView_ = true;
+ //display distance next to cursor
+ it->second.text_->setCaption(multi_cast<std::string>(dist));
+ textLength = multi_cast<std::string>(dist).size() * it->second.text_->getCharHeight() * 0.3f;
}
+ else
+ {
+ //display name next to cursor
+ it->second.text_->setCaption(it->first->getRadarName());
+ textLength = it->first->getRadarName().size() * it->second.text_->getCharHeight() * 0.3f;
+ }
- //float xDistScale = this->getActualSize().x * 1000.0f * navMarkerSize_ / dist;
- //float yDistScale = this->getActualSize().y * 1000.0f * navMarkerSize_ / dist;
+ // Transform to screen coordinates
+ Vector3 pos = camTransform * it->first->getRVWorldPosition();
- // Adjust Arrowsize according to distance
- it->second.panel_->setDimensions(getArrowSizeX(dist),getArrowSizeY(dist));
+ bool outOfView = true;
+ if (pos.z > 1.0)
+ {
+ // z > 1.0 means that the object is behind the camera
+ outOfView = true;
+ // we have to switch all coordinates (if you don't know why,
+ // try linear algebra lectures, because I can't explain..)
+ pos.x = -pos.x;
+ pos.y = -pos.y;
+ }
+ else
+ outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0;
- // Switch between top, bottom, left and right position of the arrow at the screen border
- if ( pos.x < pos.y )
+ if (outOfView)
{
- if ( pos.y > -pos.x )
+ // Object is not in view
+
+ // Change material only if outOfView changed
+ if (!it->second.wasOutOfView_)
{
- // Top
- float position = pos.x / pos.y + 1.0f;
- it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 0.0f );
- it->second.panel_->setUV ( 0.5f, 0.0f, 1.0f, 0.5f );
- it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
- it->second.text_->setTop ( it->second.panel_->getHeight() );
+ it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("arrows.png", it->first->getRadarObjectColour()));
+ it->second.wasOutOfView_ = true;
}
+
+ //float xDistScale = this->getActualSize().x * 1000.0f * this->navMarkerSize_ / dist;
+ //float yDistScale = this->getActualSize().y * 1000.0f * this->navMarkerSize_ / dist;
+
+ // Adjust Arrowsize according to distance
+ it->second.panel_->setDimensions(getArrowSizeX(dist), getArrowSizeY(dist));
+
+ // Switch between top, bottom, left and right position of the arrow at the screen border
+ if (pos.x < pos.y)
+ {
+ if (pos.y > -pos.x)
+ {
+ // Top
+ float position = pos.x / pos.y + 1.0f;
+ it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 0.0f);
+ it->second.panel_->setUV(0.5f, 0.0f, 1.0f, 0.5f);
+ it->second.text_->setLeft((position - textLength) * 0.5f);
+ it->second.text_->setTop(it->second.panel_->getHeight());
+ }
+ else
+ {
+ // Left
+ float position = pos.y / pos.x + 1.0f;
+ it->second.panel_->setPosition(0.0f, (position - it->second.panel_->getWidth()) * 0.5f);
+ it->second.panel_->setUV(0.0f, 0.0f, 0.5f, 0.5f);
+ it->second.text_->setLeft(it->second.panel_->getWidth() + 0.01f);
+ it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f);
+ }
+ }
else
{
- // Left
- float position = pos.y / pos.x + 1.0f;
- it->second.panel_->setPosition ( 0.0f, ( position - it->second.panel_->getWidth() ) * 0.5f );
- it->second.panel_->setUV ( 0.0f, 0.0f, 0.5f, 0.5f );
- it->second.text_->setLeft ( it->second.panel_->getWidth() + 0.01f );
- it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
+ if (pos.y < -pos.x)
+ {
+ // Bottom
+ float position = -pos.x / pos.y + 1.0f;
+ it->second.panel_->setPosition((position - it->second.panel_->getWidth()) * 0.5f, 1.0f - it->second.panel_->getHeight());
+ it->second.panel_->setUV(0.0f, 0.5f, 0.5f, 1.0f );
+ it->second.text_->setLeft((position - textLength) * 0.5f);
+ it->second.text_->setTop(1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight());
+ }
+ else
+ {
+ // Right
+ float position = -pos.y / pos.x + 1.0f;
+ it->second.panel_->setPosition(1.0f - it->second.panel_->getWidth(), (position - it->second.panel_->getHeight()) * 0.5f);
+ it->second.panel_->setUV(0.5f, 0.5f, 1.0f, 1.0f);
+ it->second.text_->setLeft(1.0f - it->second.panel_->getWidth() - textLength - 0.01f);
+ it->second.text_->setTop((position - it->second.text_->getCharHeight()) * 0.5f);
+ }
}
}
-
else
{
+ // Object is in view
- if ( pos.y < -pos.x )
+ // Change material only if outOfView changed
+ if (it->second.wasOutOfView_)
{
- // Bottom
- float position = -pos.x / pos.y + 1.0f;
- it->second.panel_->setPosition ( ( position - it->second.panel_->getWidth() ) * 0.5f, 1.0f - it->second.panel_->getHeight() );
- it->second.panel_->setUV ( 0.0f, 0.5f, 0.5f, 1.0f );
- it->second.text_->setLeft ( ( position - textLength ) * 0.5f );
- it->second.text_->setTop ( 1.0f - it->second.panel_->getHeight() - it->second.text_->getCharHeight() );
+ //it->second.panel_->setMaterialName("Orxonox/NavTDC");
+ it->second.panel_->setMaterialName(TextureGenerator::getMaterialName("tdc.png", it->first->getRadarObjectColour()));
+ it->second.panel_->setDimensions(this->navMarkerSize_ * this->getActualSize().x, this->navMarkerSize_ * this->getActualSize().y);
+ it->second.wasOutOfView_ = false;
}
- else
- {
- // Right
- float position = -pos.y / pos.x + 1.0f;
- it->second.panel_->setPosition ( 1.0f - it->second.panel_->getWidth(), ( position - it->second.panel_->getHeight() ) * 0.5f );
- it->second.panel_->setUV ( 0.5f, 0.5f, 1.0f, 1.0f );
- it->second.text_->setLeft ( 1.0f - it->second.panel_->getWidth() - textLength - 0.01f );
- it->second.text_->setTop ( ( position - it->second.text_->getCharHeight() ) * 0.5f );
- }
- }
- }
- else
- {
- // Object is in view
- // Change material only if outOfView changed
- if ( it->second.wasOutOfView_ )
- {
- //it->second.panel_->setMaterialName ( "Orxonox/NavTDC" );
- it->second.panel_->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", it->first->getRadarObjectColour()) );
- it->second.panel_->setDimensions ( navMarkerSize_ * this->getActualSize().x, navMarkerSize_ * this->getActualSize().y );
- it->second.wasOutOfView_ = false;
+ // Position marker
+ it->second.panel_->setUV(0.0f, 0.0f, 1.0f, 1.0f);
+ it->second.panel_->setLeft((pos.x + 1.0f - it->second.panel_->getWidth()) * 0.5f);
+ it->second.panel_->setTop((-pos.y + 1.0f - it->second.panel_->getHeight()) * 0.5f);
+
+ // Position text
+ it->second.text_->setLeft((pos.x + 1.0f + it->second.panel_->getWidth()) * 0.5f);
+ it->second.text_->setTop((-pos.y + 1.0f + it->second.panel_->getHeight()) * 0.5f);
}
- // Position marker
- it->second.panel_->setUV ( 0.0f, 0.0f, 1.0f, 1.0f );
- it->second.panel_->setLeft ( ( pos.x + 1.0f - it->second.panel_->getWidth() ) * 0.5f );
- it->second.panel_->setTop ( ( -pos.y + 1.0f - it->second.panel_->getHeight() ) * 0.5f );
-
- // Position text
- it->second.text_->setLeft ( ( pos.x + 1.0f + it->second.panel_->getWidth() ) * 0.5f );
- it->second.text_->setTop ( ( -pos.y + 1.0f + it->second.panel_->getHeight() ) * 0.5f );
+ // Make sure the overlays are shown
+ it->second.panel_->show();
+ it->second.text_->show();
}
-
- // Make sure the overlays are shown
- it->second.panel_->show();
- it->second.text_->show();
+ else // do not display on HUD
+ {
+ it->second.panel_->hide();
+ it->second.text_->hide();
+ }
}
- else // do not display on HUD
- {
- it->second.panel_->hide();
- it->second.text_->hide();
- }
-
}
-}
-
-/** Overridden method of OrxonoxOverlay.
- at details
- Usually the entire overlay scales with scale().
- Here we obviously have to adjust this.
-*/
-void HUDNavigation::sizeChanged()
-{
- // Use size to compensate for aspect ratio if enabled.
- float xScale = this->getActualSize().x;
- float yScale = this->getActualSize().y;
-
- for ( ObjectMap::iterator it = activeObjectList_.begin(); it!=activeObjectList_.end(); ++it )
+ /** Overridden method of OrxonoxOverlay.
+ @details
+ Usually the entire overlay scales with scale().
+ Here we obviously have to adjust this.
+ */
+ void HUDNavigation::sizeChanged()
{
- if ( it->second.panel_ != NULL )
- it->second.panel_->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
- if ( it->second.text_ != NULL )
- it->second.text_->setCharHeight ( it->second.text_->getCharHeight() * yScale );
+ // Use size to compensate for aspect ratio if enabled.
+ float xScale = this->getActualSize().x;
+ float yScale = this->getActualSize().y;
+
+ for (std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.begin(); it != this->activeObjectList_.end(); ++it)
+ {
+ if (it->second.panel_ != NULL)
+ it->second.panel_->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
+ if (it->second.text_ != NULL)
+ it->second.text_->setCharHeight(it->second.text_->getCharHeight() * yScale);
+ }
}
-}
-void HUDNavigation::addObject ( RadarViewable* object )
-{
- if( showObject(object)==false )
- return;
-
- if ( activeObjectList_.size() >= markerLimit_ )
- if ( object == NULL )
+ void HUDNavigation::addObject(RadarViewable* object)
+ {
+ if (showObject(object) == false)
return;
- // Object hasn't been added yet (we know that)
- assert ( this->activeObjectList_.find ( object ) == this->activeObjectList_.end() );
+ if (this->activeObjectList_.size() >= this->markerLimit_)
+ if (object == NULL)
+ return;
- // Scales used for dimensions and text size
- float xScale = this->getActualSize().x;
- float yScale = this->getActualSize().y;
+ // Object hasn't been added yet (we know that)
+ assert(this->activeObjectList_.find(object) == this->activeObjectList_.end());
- // Create everything needed to display the object on the radar and add it to the map
+ // Scales used for dimensions and text size
+ float xScale = this->getActualSize().x;
+ float yScale = this->getActualSize().y;
- // Create arrow/marker
- Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*> ( Ogre::OverlayManager::getSingleton()
- .createOverlayElement ( "Panel", "HUDNavigation_navMarker_" + getUniqueNumberString() ) );
-// panel->setMaterialName ( "Orxonox/NavTDC" );
- panel->setMaterialName( TextureGenerator::getMaterialName( "tdc.png", object->getRadarObjectColour()) );
- panel->setDimensions ( navMarkerSize_ * xScale, navMarkerSize_ * yScale );
-// panel->setColour( object->getRadarObjectColour() );
+ // Create everything needed to display the object on the radar and add it to the map
- Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*> ( Ogre::OverlayManager::getSingleton()
- .createOverlayElement ( "TextArea", "HUDNavigation_navText_" + getUniqueNumberString() ) );
- text->setFontName ( this->fontName_ );
- text->setCharHeight ( text->getCharHeight() * yScale );
- text->setColour( object->getRadarObjectColour() );
+ // Create arrow/marker
+ Ogre::PanelOverlayElement* panel = static_cast<Ogre::PanelOverlayElement*>( Ogre::OverlayManager::getSingleton()
+ .createOverlayElement("Panel", "HUDNavigation_navMarker_" + getUniqueNumberString()));
+ //panel->setMaterialName("Orxonox/NavTDC");
+ panel->setMaterialName(TextureGenerator::getMaterialName("tdc.png", object->getRadarObjectColour()));
+ panel->setDimensions(this->navMarkerSize_ * xScale, this->navMarkerSize_ * yScale);
+ //panel->setColour(object->getRadarObjectColour());
- panel->hide();
- text->hide();
+ Ogre::TextAreaOverlayElement* text = static_cast<Ogre::TextAreaOverlayElement*>( Ogre::OverlayManager::getSingleton()
+ .createOverlayElement("TextArea", "HUDNavigation_navText_" + getUniqueNumberString()));
+ text->setFontName(this->fontName_);
+ text->setCharHeight(text->getCharHeight() * yScale);
+ text->setColour(object->getRadarObjectColour());
- ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};
- activeObjectList_[object] = tempStruct;
+ panel->hide();
+ text->hide();
- this->background_->addChild ( panel );
- this->background_->addChild ( text );
+ ObjectInfo tempStruct = {panel, text, false /*, TODO: initialize wasOutOfView_ */};
+ this->activeObjectList_[object] = tempStruct;
- sortedObjectList_.push_front ( std::make_pair ( object, ( unsigned int ) 0 ) );
+ this->background_->addChild(panel);
+ this->background_->addChild(text);
+ this->sortedObjectList_.push_front(std::make_pair(object, (unsigned int)0));
+ }
-}
-
-void HUDNavigation::removeObject ( RadarViewable* viewable )
-{
- ObjectMap::iterator it = activeObjectList_.find ( viewable );
-
- if ( activeObjectList_.find ( viewable ) != activeObjectList_.end() )
+ void HUDNavigation::removeObject(RadarViewable* viewable)
{
- // Detach overlays
- this->background_->removeChild ( it->second.panel_->getName() );
- this->background_->removeChild ( it->second.text_->getName() );
- // Properly destroy the overlay elements (do not use delete!)
- Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.panel_ );
- Ogre::OverlayManager::getSingleton().destroyOverlayElement ( it->second.text_ );
- // Remove from the list
- activeObjectList_.erase ( viewable );
+ std::map<RadarViewable*, ObjectInfo>::iterator it = this->activeObjectList_.find(viewable);
+ if (this->activeObjectList_.find(viewable) != this->activeObjectList_.end())
+ {
+ // Detach overlays
+ this->background_->removeChild(it->second.panel_->getName());
+ this->background_->removeChild(it->second.text_->getName());
+ // Properly destroy the overlay elements (do not use delete!)
+ Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.panel_);
+ Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_);
+ // Remove from the list
+ this->activeObjectList_.erase(viewable);
+ }
+ for (std::list<std::pair<RadarViewable*, unsigned int> >::iterator listIt = this->sortedObjectList_.begin(); listIt != this->sortedObjectList_.end(); ++listIt)
+ {
+ if ((listIt->first) == viewable)
+ {
+ this->sortedObjectList_.erase(listIt);
+ break;
+ }
+ }
}
- for ( sortedList::iterator listIt = sortedObjectList_.begin(); listIt != sortedObjectList_.end(); ++listIt )
+ void HUDNavigation::objectChanged(RadarViewable* viewable)
{
- if ( (listIt->first) == viewable )
- {
- sortedObjectList_.erase ( listIt );
- break;
- }
+ // TODO: niceification neccessary ;)
+ removeObject(viewable);
+ addObject(viewable);
+ }
+ bool HUDNavigation::showObject(RadarViewable* rv)
+ {
+ if (rv == orxonox_cast<RadarViewable*>(this->getOwner()))
+ return false;
+ assert(rv->getWorldEntity());
+ if (rv->getWorldEntity()->isVisible() == false || rv->getRadarVisibility() == false)
+ return false;
+ return true;
}
-}
-
-void HUDNavigation::objectChanged(RadarViewable* viewable)
-{
- // TODO: niceification neccessary ;)
- removeObject(viewable);
- addObject(viewable);
-}
-
-
-bool HUDNavigation::showObject(RadarViewable* rv)
-{
- if ( rv == orxonox_cast<RadarViewable*> ( this->getOwner() ) )
- return false;
- assert( rv->getWorldEntity() );
- if ( rv->getWorldEntity()->isVisible()==false || rv->getRadarVisibility()==false )
- return false;
- return true;
-}
-
-void HUDNavigation::changedOwner()
-{
-
- const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
- for ( std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it )
+ void HUDNavigation::changedOwner()
{
- if ( ! ( *it )->isHumanShip_ )
- this->addObject ( *it );
+ const std::set<RadarViewable*>& respawnObjects = this->getOwner()->getScene()->getRadar()->getRadarObjects();
+ for (std::set<RadarViewable*>::const_iterator it = respawnObjects.begin(); it != respawnObjects.end(); ++it)
+ {
+ if (!(*it)->isHumanShip_)
+ this->addObject(*it);
+ }
}
}
-
-}
Modified: code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.h
===================================================================
--- code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.h 2012-06-04 20:50:28 UTC (rev 9279)
+++ code/branches/presentation2012merge/src/modules/overlays/hud/HUDNavigation.h 2012-06-05 20:29:17 UTC (rev 9280)
@@ -35,7 +35,6 @@
#include <map>
#include <string>
-
#include "util/OgreForwardRefs.h"
#include "tools/interfaces/Tickable.h"
#include "interfaces/RadarListener.h"
@@ -43,79 +42,78 @@
namespace orxonox
{
-class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener
-{
-public:
- HUDNavigation ( BaseObject* creator );
- virtual ~HUDNavigation();
+ class _OverlaysExport HUDNavigation : public OrxonoxOverlay, public Tickable, public RadarListener
+ {
+ public:
+ HUDNavigation(BaseObject* creator);
+ virtual ~HUDNavigation();
- void setConfigValues();
+ void setConfigValues();
- virtual void XMLPort ( Element& xmlelement, XMLPort::Mode mode );
- virtual void tick ( float dt );
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void tick(float dt);
- // RadarListener interface
- virtual void addObject ( RadarViewable* object );
- virtual void removeObject ( RadarViewable* viewable );
- virtual void objectChanged ( RadarViewable* viewable );
+ // RadarListener interface
+ virtual void addObject(RadarViewable* object);
+ virtual void removeObject(RadarViewable* viewable);
+ virtual void objectChanged(RadarViewable* viewable);
- virtual void changedOwner();
- virtual void sizeChanged();
- virtual void angleChanged() { }
- virtual void positionChanged() { }
- virtual void radarTick ( float dt ) {}
+ virtual void changedOwner();
+ virtual void sizeChanged();
+ virtual void angleChanged() { }
+ virtual void positionChanged() { }
+ virtual void radarTick(float dt) {}
- inline float getRadarSensitivity() const
- { return 1.0f; }
+ inline float getRadarSensitivity() const
+ { return 1.0f; }
- unsigned int getMarkerLimit() { return this->markerLimit_; }
+ inline unsigned int getMarkerLimit() const
+ { return this->markerLimit_; }
-private:
- struct ObjectInfo
- {
- Ogre::PanelOverlayElement* panel_;
- Ogre::TextAreaOverlayElement* text_;
- bool outOfView_;
- bool wasOutOfView_;
+ private:
+ struct ObjectInfo
+ {
+ Ogre::PanelOverlayElement* panel_;
+ Ogre::TextAreaOverlayElement* text_;
+ bool outOfView_;
+ bool wasOutOfView_;
+ };
- };
+ bool showObject(RadarViewable* rv);
- bool showObject( RadarViewable* rv );
+ // XMLPort accessors
+ inline void setNavMarkerSize(float size)
+ {
+ navMarkerSize_ = size;
+ this->sizeChanged();
+ }
+ inline float getNavMarkerSize() const
+ { return navMarkerSize_; }
+ inline void setDetectionLimit(float limit)
+ { this->detectionLimit_ = limit; }
+ inline float getDetectionLimit() const
+ { return this->detectionLimit_; }
- // XMLPort accessors
- void setNavMarkerSize ( float size )
- { navMarkerSize_ = size; this->sizeChanged(); }
- float getNavMarkerSize() const
- { return navMarkerSize_; }
- void setDetectionLimit( float limit )
- { this->detectionLimit_ = limit; }
- float getDetectionLimit() const
- { return this->detectionLimit_; }
+ void setTextSize(float size);
+ float getTextSize() const;
- void setTextSize ( float size );
- float getTextSize() const;
+ void setFont(const std::string& font);
+ const std::string& getFont() const;
- void setFont ( const std::string& font );
- const std::string& getFont() const;
+ float getArrowSizeX(int dist) const;
+ float getArrowSizeY(int dist) const;
- typedef std::map<RadarViewable*, ObjectInfo > ObjectMap;
- ObjectMap activeObjectList_;
+ std::map<RadarViewable*, ObjectInfo> activeObjectList_;
+ std::list<std::pair<RadarViewable*, unsigned int> > sortedObjectList_;
- typedef std::list < std::pair<RadarViewable*, unsigned int > > sortedList;
- sortedList sortedObjectList_;
+ float navMarkerSize_;
+ std::string fontName_;
+ float textSize_;
+ bool showDistance_;
- float getArrowSizeX(int dist);
- float getArrowSizeY(int dist);
-
- float navMarkerSize_;
- std::string fontName_;
- float textSize_;
- bool showDistance;
-
- unsigned int markerLimit_;
- float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
-
-};
+ unsigned int markerLimit_;
+ float detectionLimit_; //!< Objects that are more far away than detectionLimit_ are not displayed on the HUD. 10000.0f is the default value.
+ };
}
#endif /* _HUDNavigation_H__ */
More information about the Orxonox-commit
mailing list