Changeset 1590 for code/branches
- Timestamp:
- Jun 12, 2008, 12:57:45 AM (16 years ago)
- Location:
- code/branches/hud
- Files:
-
- 2 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/hud/bin/hud/hud.oxh
r1588 r1590 2 2 <HUDSpeedBar name ="SpeedBar1" scale=0.35,0.2 scroll=-0.6,-1.0 value=0 /> 3 3 <HUDFPSText name="FPSText" scale = 0.043,0.043 scroll=-0.93,0.9 font="Monofur" caption="Frames per second: " /> 4 <HUDRTRText name="RTRText" visible=false scale = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " /> 4 <HUDRTRText name="RTRText" scale = 0.043,0.043 scroll=-0.93,0.8 font="Monofur" caption="Render time ratio: " /> 5 <Navigation name="Navigation" font="Monofur" navmarkersize=0.03,0.03 /> 5 6 </HUD> -
code/branches/hud/src/network/GameStateClient.cc
r1534 r1590 34 34 #include "core/BaseObject.h" 35 35 #include "Synchronisable.h" 36 #include "objects/SpaceShip.h" 36 37 37 38 -
code/branches/hud/src/network/GameStateClient.h
r1505 r1590 44 44 // 45 45 #include "NetworkPrereqs.h" 46 #include "OrxonoxPrereqs.h" 46 47 #include "core/CorePrereqs.h" 47 48 #include "PacketTypes.h" 48 #include " objects/SpaceShip.h"49 #include "Synchronisable.h" 49 50 50 51 51 52 #define GAMESTATEID_INITIAL -1 53 52 54 53 55 namespace network -
code/branches/hud/src/orxonox/CMakeLists.txt
r1555 r1590 18 18 tools/ParticleInterface.cc 19 19 tools/Timer.cc 20 tools/WindowEventListener.cc 20 21 21 22 objects/Ambient.cc -
code/branches/hud/src/orxonox/GraphicsEngine.cc
r1564 r1590 50 50 #include "core/CommandExecutor.h" 51 51 #include "core/ConsoleCommand.h" 52 #include "core/input/InputManager.h"53 52 54 53 #include "console/InGameConsole.h" … … 56 55 #include "tools/ParticleInterface.h" 57 56 #include "Settings.h" 58 59 60 namespace orxonox { 57 #include "tools/WindowEventListener.h" 58 59 60 namespace orxonox 61 { 61 62 /** 62 63 @brief Returns the singleton instance and creates it the first time. … … 435 436 436 437 /** 437 * Window has resized.438 * Window has moved. 438 439 * @param rw The render window it occured in 439 440 */ 440 441 void GraphicsEngine::windowMoved(Ogre::RenderWindow *rw) 441 442 { 442 // note: this doesn't change the window extents 443 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 444 it->windowMoved(); 443 445 } 444 446 … … 451 453 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 452 454 { 453 // change the mouse clipping size for absolute mouse movements 454 int w = rw->getWidth(); 455 int h = rw->getHeight(); 456 InputManager::setWindowExtents(w, h); 457 InGameConsole::getInstance().resize(); 458 HUD::getSingleton().resize(); 459 } 460 461 /** 462 * Window has resized. 455 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 456 it->windowResized(this->renderWindow_->getWidth(), this->renderWindow_->getHeight()); 457 } 458 459 /** 460 * Window has changed Focus. 463 461 * @param rw The render window it occured in 464 462 */ 465 463 void GraphicsEngine::windowFocusChanged(Ogre::RenderWindow *rw) 466 464 { 467 // note: this doesn't change the window extents 468 } 469 470 /** 471 * Window has resized. 465 for (Iterator<orxonox::WindowEventListener> it = ObjectList<orxonox::WindowEventListener>::start(); it; ++it) 466 it->windowFocusChanged(); 467 } 468 469 /** 470 * Window was closed. 472 471 * @param rw The render window it occured in 473 472 */ 474 473 void GraphicsEngine::windowClosed(Ogre::RenderWindow *rw) 475 474 { 476 // using CommandExecutor in order to avoid depending on Orxonox class.475 // using CommandExecutor in order to avoid depending on Orxonox.h. 477 476 CommandExecutor::execute("exit", false); 478 477 } -
code/branches/hud/src/orxonox/GraphicsEngine.h
r1588 r1590 47 47 48 48 49 namespace orxonox {50 49 namespace orxonox 50 { 51 51 /** 52 52 @brief Graphics engine manager class -
code/branches/hud/src/orxonox/console/InGameConsole.cc
r1578 r1590 170 170 this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_); 171 171 172 this-> resize();172 this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight()); 173 173 174 174 // move overlay "above" the top edge of the screen … … 370 370 @brief Resizes the console elements. Call if window size changes. 371 371 */ 372 void InGameConsole:: resize()373 { 374 this->windowW_ = GraphicsEngine::getSingleton().getWindowWidth();375 this->windowH_ = GraphicsEngine::getSingleton().getWindowHeight();372 void InGameConsole::windowResized(int newWidth, int newHeight) 373 { 374 this->windowW_ = newWidth; 375 this->windowH_ = newHeight; 376 376 this->consoleOverlayBorder_->setWidth((int) this->windowW_* this->relativeWidth); 377 377 this->consoleOverlayBorder_->setHeight((int) this->windowH_ * this->relativeHeight); … … 468 468 Shell::getInstance().registerListener(this); 469 469 470 this-> resize();470 this->windowResized(this->windowW_, this->windowH_); 471 471 this->linesChanged(); 472 472 this->cursorChanged(); -
code/branches/hud/src/orxonox/console/InGameConsole.h
r1578 r1590 38 38 #include "core/Shell.h" 39 39 #include "objects/Tickable.h" 40 #include "tools/WindowEventListener.h" 40 41 41 42 42 43 namespace orxonox 43 44 { 44 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener 45 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener, public WindowEventListener 45 46 { 46 47 public: // functions … … 50 51 51 52 void tick(float dt); 52 void resize();53 53 54 54 static InGameConsole& getInstance(); … … 76 76 void setCursorPosition(unsigned int pos); 77 77 void print(const std::string& text, int index, bool alwaysShift = false); 78 79 void windowResized(int newWidth, int newHeight); 78 80 79 81 static Ogre::UTFString convert2UTF(std::string s); -
code/branches/hud/src/orxonox/hud/HUD.cc
r1588 r1590 107 107 Ogre::OverlayManager::getSingleton().destroy(this->orxonoxHUD_); 108 108 this->orxonoxHUD_ = 0; 109 110 if (this->nav_)111 delete this->nav_;112 this->nav_ = 0;113 109 } 114 110 … … 143 139 radar_->init(0.5, 0.9, 0.2, container_); 144 140 145 // create Navigation146 nav_ = new Navigation(container_);147 148 141 WorldEntity* object; 149 142 object = new WorldEntity(); … … 189 182 { 190 183 radar_->update(); 191 nav_->update(); 192 } 193 194 void HUD::resize() 184 } 185 186 void HUD::windowResized(int newWidth, int newHeight) 195 187 { 196 188 this->radar_->resize(); … … 215 207 if ((*it)->getObject() == object) 216 208 { 217 if (this->nav_ && this->nav_->getFocus() == (*it))218 this->nav_->releaseFocus(); 209 /*if (this->nav_ && this->nav_->getFocus() == (*it)) 210 this->nav_->releaseFocus();*/ 219 211 220 212 delete (*it); … … 243 235 } 244 236 245 /*static*/ void HUD::cycleNavigationFocus(){ 246 HUD::getSingleton().nav_->cycleFocus(); 237 /*static*/ void HUD::cycleNavigationFocus() 238 { 239 if (HUD::getSingleton().hudElements_.find("Navigation") != HUD::getSingleton().hudElements_.end()) 240 { 241 Navigation* navi = dynamic_cast<Navigation*>(HUD::getSingleton().hudElements_["Navigation"]); 242 navi->cycleFocus(); 243 } 247 244 } 248 245 249 246 /*static*/ void HUD::releaseNavigationFocus(){ 250 HUD::getSingleton().nav_->releaseFocus();247 //HUD::getSingleton().nav_->releaseFocus(); 251 248 } 252 249 } -
code/branches/hud/src/orxonox/hud/HUD.h
r1588 r1590 39 39 #include "util/Math.h" 40 40 #include "OverlayElementFactories.h" 41 #include "tools/WindowEventListener.h" 41 42 42 43 namespace orxonox … … 45 46 class HUDOverlay; 46 47 47 class _OrxonoxExport HUD : public BaseObject, public TickableReal 48 class _OrxonoxExport HUD : public BaseObject, public TickableReal, public WindowEventListener 48 49 { 49 50 public: … … 76 77 HUDOverlay* getHUDElement(unsigned int index); 77 78 79 void windowResized(int newWidth, int newHeight); 80 78 81 std::map<std::string, HUDOverlay*> hudElements_; 79 82 -
code/branches/hud/src/orxonox/hud/HUDBar.cc
r1588 r1590 75 75 HUDOverlay::XMLPort(xmlElement, mode); 76 76 77 // create background 78 this->background_ = static_cast<PanelOverlayElement*>( 79 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 80 this->background_->setMaterialName("Orxonox/BarBackground"); 81 this->background_->setMetricsMode(GMM_RELATIVE); 82 this->background_->setDimensions(1.0f, 0.3f); 83 this->background_->setPosition(0.0f, 0.0f); 84 this->overlay_->add2D(this->background_); 77 if (mode == XMLPort::LoadObject) 78 { 79 // create background 80 this->background_ = static_cast<PanelOverlayElement*>( 81 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 82 this->background_->setMaterialName("Orxonox/BarBackground"); 83 this->background_->setMetricsMode(GMM_RELATIVE); 84 this->background_->setDimensions(1.0f, 0.3f); 85 this->background_->setPosition(0.0f, 0.0f); 86 this->overlay_->add2D(this->background_); 85 87 86 // create new material87 std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++);88 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General");89 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);90 this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState();91 this->textureUnitState_->setTextureName("bar2.tga");92 // use the default colour93 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2));88 // create new material 89 std::string materialname = "barmaterial" + getConvertedValue<unsigned int, std::string>(materialcount_s++); 90 Ogre::MaterialPtr material = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().create(materialname, "General"); 91 material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); 92 this->textureUnitState_ = material->getTechnique(0)->getPass(0)->createTextureUnitState(); 93 this->textureUnitState_->setTextureName("bar2.tga"); 94 // use the default colour 95 this->textureUnitState_->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, ColourValue(0.2, 0.7, 0.2)); 94 96 95 // create bar 96 this->bar_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "Bar")); 97 this->bar_->setMaterialName(materialname); 98 this->bar_->setMetricsMode(GMM_RELATIVE); 99 this->background_->addChild(bar_); 97 // create bar 98 this->bar_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "Bar")); 99 this->bar_->setMaterialName(materialname); 100 this->bar_->setMetricsMode(GMM_RELATIVE); 101 this->background_->addChild(bar_); 102 } 100 103 101 104 XMLPortParamLoadOnly(HUDBar, "value", setValue, xmlElement, mode); 102 105 103 this->addColour(0.7, ColourValue(0.2, 0.7, 0.2)); 104 this->addColour(0.4, ColourValue(0.7, 0.5, 0.2)); 105 this->addColour(0.1, ColourValue(0.7, 0.2, 0.2)); 106 if (mode == XMLPort::LoadObject) 107 { 108 this->addColour(0.7, ColourValue(0.2, 0.7, 0.2)); 109 this->addColour(0.4, ColourValue(0.7, 0.5, 0.2)); 110 this->addColour(0.1, ColourValue(0.7, 0.2, 0.2)); 111 } 106 112 } 107 113 -
code/branches/hud/src/orxonox/hud/HUDBar.h
r1588 r1590 42 42 namespace orxonox 43 43 { 44 class _OrxonoxExport HUDBar : public HUDOverlay , public TickableReal44 class _OrxonoxExport HUDBar : public HUDOverlay 45 45 { 46 46 public: … … 49 49 50 50 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 51 52 //virtual void tick(float dt) { }53 51 54 52 void setValue(float value); -
code/branches/hud/src/orxonox/hud/HUDFPSText.h
r1588 r1590 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport HUDFPSText : public HUDText 38 class _OrxonoxExport HUDFPSText : public HUDText, public Tickable 39 39 { 40 40 public: -
code/branches/hud/src/orxonox/hud/HUDOverlay.cc
r1588 r1590 33 33 #include "util/Convert.h" 34 34 #include "core/CoreIncludes.h" 35 #include "GraphicsEngine.h" 35 36 36 37 namespace orxonox 37 38 { 38 CreateFactory(HUDOverlay);39 39 unsigned int HUDOverlay::hudOverlayCounter_s = 0; 40 40 … … 49 49 BaseObject::XMLPort(xmlElement, mode); 50 50 51 overlay_ = Ogre::OverlayManager::getSingleton().create("HUDOverlay" 52 + convertToString(hudOverlayCounter_s++) + "_" + this->getName()); 51 if (mode == XMLPort::LoadObject) 52 { 53 overlay_ = Ogre::OverlayManager::getSingleton().create("HUDOverlay" 54 + convertToString(hudOverlayCounter_s++) + "_" + this->getName()); 55 56 this->windowWidth_ = GraphicsEngine::getSingleton().getWindowWidth(); 57 this->windowHeight_ = GraphicsEngine::getSingleton().getWindowHeight(); 58 this->windowAspectRatio_ = windowWidth_/(float)windowHeight_; 59 } 53 60 54 61 XMLPortParam(HUDOverlay, "scale", setScale, getScale, xmlElement, mode); … … 56 63 XMLPortParam(HUDOverlay, "rotation", setRotation, getRotation, xmlElement, mode); 57 64 58 this->overlay_->show(); 59 if (!this->isVisible()) 60 this->overlay_->hide(); 65 if (mode == XMLPort::LoadObject) 66 { 67 this->overlay_->show(); 68 if (!this->isVisible()) 69 this->overlay_->hide(); 70 } 61 71 } 62 72 … … 76 86 } 77 87 88 void HUDOverlay::windowResized(int newWidth, int newHeight) 89 { 90 this->windowWidth_ = newWidth; 91 this->windowHeight_ = newHeight; 92 this->windowAspectRatio_ = windowWidth_/(float)windowHeight_; 93 } 94 78 95 } -
code/branches/hud/src/orxonox/hud/HUDOverlay.h
r1588 r1590 33 33 34 34 #include <OgrePrerequisites.h> 35 #include "tools/WindowEventListener.h" 35 36 #include "util/Math.h" 36 37 #include "core/BaseObject.h" … … 38 39 namespace orxonox 39 40 { 40 class _OrxonoxExport HUDOverlay : public BaseObject 41 class _OrxonoxExport HUDOverlay : public BaseObject, public WindowEventListener 41 42 { 42 43 public: … … 76 77 77 78 protected: 79 virtual void windowResized(int newWidth, int newHeight); 80 78 81 Ogre::Overlay* overlay_; 82 float windowAspectRatio_; 83 int windowWidth_; 84 int windowHeight_; 79 85 80 private:81 static unsigned int hudOverlayCounter_s;86 private: 87 static unsigned int hudOverlayCounter_s; 82 88 83 89 }; -
code/branches/hud/src/orxonox/hud/HUDRTRText.h
r1588 r1590 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport HUDRTRText : public HUDText 38 class _OrxonoxExport HUDRTRText : public HUDText, public Tickable 39 39 { 40 40 public: -
code/branches/hud/src/orxonox/hud/HUDSpeedBar.h
r1588 r1590 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport HUDSpeedBar : public HUDBar 38 class _OrxonoxExport HUDSpeedBar : public HUDBar, public Tickable 39 39 { 40 40 public: -
code/branches/hud/src/orxonox/hud/HUDText.cc
r1588 r1590 62 62 HUDOverlay::XMLPort(xmlElement, mode); 63 63 64 // create background 65 this->background_ = static_cast<PanelOverlayElement*>( 66 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 67 this->background_->setMetricsMode(GMM_RELATIVE); 68 this->background_->setDimensions(1.0f, 1.0f); 69 this->background_->setPosition(0.0f, 0.0f); 64 if (mode == XMLPort::LoadObject) 65 { 66 // create background 67 this->background_ = static_cast<PanelOverlayElement*>( 68 OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_Background")); 69 this->background_->setMetricsMode(GMM_RELATIVE); 70 this->background_->setDimensions(1.0f, 1.0f); 71 this->background_->setPosition(0.0f, 0.0f); 70 72 71 this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text"));72 this->text_->setMetricsMode(Ogre::GMM_RELATIVE);73 this->text_->setDimensions(1.0f, 1.0f);74 this->text_->setPosition(0.0f, 0.0f);75 this->text_->setCharHeight(1.0f);73 this->text_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_Text")); 74 this->text_->setMetricsMode(Ogre::GMM_RELATIVE); 75 this->text_->setPosition(0.0f, 0.0f); 76 this->text_->setCharHeight(1.0f); 77 this->text_->setFontName("Monofur"); 76 78 77 this->overlay_->add2D(this->background_); 78 this->background_->addChild(this->text_); 79 this->overlay_->add2D(this->background_); 80 this->background_->addChild(this->text_); 81 } 79 82 80 83 XMLPortParam(HUDText, "material", setBackgroundMaterial, getBackgroundMaterial, xmlElement, mode); … … 82 85 XMLPortParam(HUDText, "caption", setCaption, getCaption, xmlElement, mode); 83 86 84 this->text_->setCaption(this->caption_); 87 if (mode == XMLPort::LoadObject) 88 { 89 this->text_->setCaption(this->caption_); 90 } 85 91 } 86 92 -
code/branches/hud/src/orxonox/hud/HUDText.h
r1588 r1590 41 41 namespace orxonox 42 42 { 43 class _OrxonoxExport HUDText : public HUDOverlay , public TickableReal43 class _OrxonoxExport HUDText : public HUDOverlay 44 44 { 45 45 public: … … 48 48 49 49 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 50 51 virtual void tick(float dt) { }52 50 53 51 protected: -
code/branches/hud/src/orxonox/hud/Navigation.cc
r1580 r1590 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 33 33 #include <OgreStringConverter.h> 34 34 35 #include "GraphicsEngine.h"35 //#include "GraphicsEngine.h" 36 36 // TODO: remove the SpaceShip and CameraHandler dependencies 37 37 #include "objects/SpaceShip.h" 38 38 #include "objects/Projectile.h" 39 39 #include "objects/CameraHandler.h" 40 #include "HUD.h" 40 41 #include "RadarObject.h" 41 42 #include "RadarOverlayElement.h" 42 #include "HUD.h"43 43 #include "core/Debug.h" 44 #include " util/Math.h"44 #include "core/CoreIncludes.h" 45 45 46 46 namespace orxonox 47 47 { 48 CreateFactory(Navigation); 49 48 50 using namespace Ogre; 49 51 50 Navigation::Navigation(OverlayContainer* container) 51 { 52 container_ = container; 53 focus_ = NULL; 54 init(); 52 Navigation::Navigation() 53 : container_(0) 54 , navMarker_(0) 55 , aimMarker_(0) 56 , focus_(0) 57 { 58 RegisterObject(Navigation); 55 59 } 56 60 57 61 Navigation::~Navigation() 58 62 { 59 OverlayManager::getSingleton().destroyOverlayElement(this->navText_); 60 OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_); 61 OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 62 } 63 64 void Navigation::init() 65 { 66 // create nav text 67 navText_ = static_cast<TextAreaOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("TextArea", "navText")); 68 navText_->show(); 69 navText_->setMetricsMode(Ogre::GMM_PIXELS); 70 navText_->setDimensions(0.001, 0.001); 71 navText_->setPosition(0.02, 0.02); 72 navText_->setFontName("Console"); 73 navText_->setCharHeight(20); 74 navText_->setCaption(""); 75 navText_->hide(); 76 container_->addChild(navText_); 77 78 79 // create nav marker ... 80 navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", "NavMarker")); 81 aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", "aimMarker")); 82 navMarker_->setMetricsMode(GMM_PIXELS); 83 aimMarker_->setMetricsMode(GMM_PIXELS); 84 navMarker_->hide(); 85 aimMarker_->hide(); 86 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 87 aimMarker_->setDimensions(20, 20); 88 aimMarker_->setUV(0.0, 0.0, 1.0, 1.0); 89 container_->addChild(navMarker_); 90 container_->addChild(aimMarker_); 91 } 92 93 void Navigation::update() 63 if (this->isInitialized()) 64 { 65 if (this->container_) 66 OverlayManager::getSingleton().destroyOverlayElement(this->container_); 67 if (this->navMarker_) 68 OverlayManager::getSingleton().destroyOverlayElement(this->navMarker_); 69 if (this->navText_) 70 OverlayManager::getSingleton().destroyOverlayElement(this->navText_); 71 if (this->aimMarker_) 72 OverlayManager::getSingleton().destroyOverlayElement(this->aimMarker_); 73 } 74 } 75 76 void Navigation::XMLPort(Element& xmlElement, XMLPort::Mode mode) 77 { 78 HUDOverlay::XMLPort(xmlElement, mode); 79 80 if (mode == XMLPort::LoadObject) 81 { 82 // create container 83 this->container_ = static_cast<OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navContainer")); 84 this->container_->setMetricsMode(Ogre::GMM_RELATIVE); 85 this->container_->setLeft(0.0); 86 this->container_->setTop(0.0); 87 this->container_->setWidth(1.0); 88 this->container_->setHeight(1.0); 89 90 // create nav text 91 this->navText_ = static_cast<TextAreaOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", getName() + "_navText")); 92 this->navText_->setMetricsMode(Ogre::GMM_RELATIVE); 93 this->navText_->setPosition(0.0f, 0.0f); 94 this->navText_->setCharHeight(0.05f); 95 this->navText_->setFontName("Monofur"); 96 97 // create nav marker 98 navMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_navMarker")); 99 navMarker_->setMetricsMode(GMM_RELATIVE); 100 navMarker_->setDimensions(0.05f, 0.05f); 101 navMarker_->setMaterialName("Orxonox/NavArrows"); 102 this->wasOutOfView_ = true; // just a to ensure the material is changed right the first time.. 103 104 // create aim marker 105 aimMarker_ = static_cast<PanelOverlayElement*>(OverlayManager::getSingleton().createOverlayElement("Panel", getName() + "_aimMarker")); 106 aimMarker_->setMetricsMode(GMM_RELATIVE); 107 aimMarker_->setDimensions(0.05f, 0.05f); 108 aimMarker_->setMaterialName("Orxonox/NavCrosshair"); 109 110 container_->addChild(navMarker_); 111 container_->addChild(aimMarker_); 112 container_->addChild(navText_); 113 container_->show(); 114 115 this->overlay_->add2D(container_); 116 this->overlay_->hide(); 117 } 118 119 XMLPortParam(Navigation, "font", setFont, getFont, xmlElement, mode); 120 XMLPortParam(Navigation, "textsize", setTextSize, getTextSize, xmlElement, mode); 121 XMLPortParam(Navigation, "navmarkersize", setNavMarkerSize, getNavMarkerSize, xmlElement, mode); 122 XMLPortParam(Navigation, "aimmarkersize", setAimMarkerSize, getAimMarkerSize, xmlElement, mode); 123 } 124 125 void Navigation::setNavMarkerSize(Vector2 size) 126 { 127 if (this->navMarker_ && size.squaredLength() >= 0.0f) 128 this->navMarker_->setDimensions(size.x, size.y); 129 } 130 131 Vector2 Navigation::getNavMarkerSize() const 132 { 133 if (this->navMarker_) 134 return Vector2(navMarker_->getWidth(), navMarker_->getHeight()); 135 else 136 return Vector2::ZERO; 137 } 138 139 void Navigation::setAimMarkerSize(Vector2 size) 140 { 141 if (this->aimMarker_ && size.squaredLength() >= 0.0f) 142 this->aimMarker_->setDimensions(size.x, size.y); 143 } 144 145 Vector2 Navigation::getAimMarkerSize() const 146 { 147 if (this->aimMarker_) 148 return Vector2(aimMarker_->getWidth(), aimMarker_->getHeight()); 149 else 150 return Vector2::ZERO; 151 } 152 153 void Navigation::setFont(const std::string& font) 154 { 155 if (this->navText_ && font != "") 156 this->navText_->setFontName(font); 157 } 158 159 std::string Navigation::getFont() const 160 { 161 if (this->navText_) 162 return this->navText_->getFontName(); 163 else 164 return ""; 165 } 166 167 void Navigation::setTextSize(float size) 168 { 169 if (this->navText_ && size >= 0.0f) 170 this->navText_->setCharHeight(size); 171 } 172 173 float Navigation::getTextSize() const 174 { 175 if (this->navText_) 176 return this->navText_->getCharHeight(); 177 else 178 return 0.0f; 179 } 180 181 void Navigation::tick(float dt) 94 182 { 95 183 if (!focus_) … … 101 189 void Navigation::updateMarker() 102 190 { 103 int windowW = GraphicsEngine::getSingleton().getWindowWidth();104 int windowH = GraphicsEngine::getSingleton().getWindowHeight();105 106 191 // set text 107 int dist = (int) getDist2Focus()/100; 108 navText_->setCaption(Ogre::StringConverter::toString(dist)); 192 int dist = (int) getDist2Focus()/100.0f; 193 navText_->setCaption(convertToString(dist)); 194 float textLength = convertToString(dist).size() * navText_->getCharHeight() * 0.3; 109 195 110 196 Ogre::Camera* navCam = SpaceShip::getLocalShip()->getCamera()->cam_; 197 Matrix4 transformationMatrix = navCam->getProjectionMatrix() * navCam->getViewMatrix(); 111 198 // transform to screen coordinates 112 Vector3 pos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * focus_->getPosition(); 113 Vector3 aimpos = navCam->getProjectionMatrix() * navCam->getViewMatrix() * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity()); 114 115 float xPosRel = 0.5*pos.x+0.5; 116 float yPosRel = 1-(0.5*pos.y+0.5); 117 float xAimPosRel = 0.5*aimpos.x+0.5; 118 float yAimPosRel = 1-(0.5*aimpos.y+0.5); 119 int xPos = (int) (xPosRel*windowW); 120 int yPos = (int) (yPosRel*windowH); 121 int xAimPos = (int) (xAimPosRel*windowW); 122 int yAimPos = (int) (yAimPosRel*windowH); 123 int xFromCenter = xPos-windowW/2; 124 int yFromCenter = yPos-windowH/2; 125 126 // is object in view? 127 Vector3 navCamPos = SpaceShip::getLocalShip()->getPosition(); 128 Vector3 currentDir = SpaceShip::getLocalShip()->getDir(); 129 Vector3 currentOrth = SpaceShip::getLocalShip()->getOrth(); 130 float radius = getAngle(navCamPos, currentDir, focus_->getPosition()); 131 bool isRight = (currentDir.crossProduct(currentOrth)).dotProduct(focus_->getPosition() - navCamPos)>0; 132 bool isAbove = currentOrth.dotProduct(focus_->getPosition() - navCamPos)>0; 133 bool outOfView = (xPosRel<0 || xPosRel>1 || yPosRel<0 || yPosRel>1); 134 135 // if object is behind us, it is out of view anyway: 136 if (!outOfView && radius > Ogre::Math::PI / 2) 199 Vector3 pos = transformationMatrix * focus_->getPosition(); 200 201 bool outOfView; 202 if (pos.z > 1.0) 203 { 204 // z > 1.0 means that the object is behind the camera 137 205 outOfView = true; 206 // we have to switch all coordinates (if you don't know why, 207 // try linear algebra lectures, because I can't explain..) 208 pos.x = -pos.x; 209 pos.y = -pos.y; 210 pos.z = -pos.z; 211 } 212 else 213 outOfView = pos.x < -1.0 || pos.x > 1.0 || pos.y < -1.0 || pos.y > 1.0; 138 214 139 215 if (outOfView) 140 216 { 141 217 // object is not in view 142 navMarker_->setMaterialName("Orxonox/NavArrows");143 navMarker_->setDimensions(16,16);144 218 aimMarker_->hide(); 145 float phiUpperCorner = atan((float)(windowW)/(float)(windowH)); 146 // from the angle we find out on which edge to draw the marker 147 // and which of the four arrows to take 148 float phiNav = atan((float) xFromCenter / (float) yFromCenter); 149 150 if (isAbove && isRight) 151 { 152 // top right quadrant 153 if (-phiNav < phiUpperCorner) 154 { 155 //COUT(3) << "arrow up\n"; 156 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); 219 220 if (!wasOutOfView_) 221 { 222 navMarker_->setMaterialName("Orxonox/NavArrows"); 223 wasOutOfView_ = true; 224 } 225 226 if (pos.x < pos.y) 227 { 228 if (pos.y > -pos.x) 229 { 230 // up 231 float position = pos.x / pos.y + 1.0; 232 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5, 0.0); 157 233 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 158 navText_->setLeft( navMarker_->getLeft()+navMarker_->getWidth());234 navText_->setLeft((position - textLength) * 0.5); 159 235 navText_->setTop(navMarker_->getHeight()); 160 236 } 161 237 else 162 238 { 163 //COUT(3) << "arrow right\n"; 164 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 239 // left 240 float position = pos.y / pos.x + 1.0; 241 navMarker_->setPosition(0.0, (position - navMarker_->getWidth()) * 0.5); 242 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 243 navText_->setLeft(navMarker_->getWidth() + 0.01); 244 navText_->setTop((position - navText_->getCharHeight()) * 0.5); 245 } 246 } 247 else 248 { 249 if (pos.y < -pos.x) 250 { 251 // down 252 float position = -pos.x / pos.y + 1.0; 253 navMarker_->setPosition((position - navMarker_->getWidth()) * 0.5, 1.0 - navMarker_->getHeight()); 254 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 255 navText_->setLeft((position - textLength) * 0.5); 256 navText_->setTop(1.0 - navMarker_->getHeight() - navText_->getCharHeight()); 257 } 258 else 259 { 260 // right 261 float position = -pos.y / pos.x + 1.0; 262 navMarker_->setPosition(1.0 - navMarker_->getWidth(), (position - navMarker_->getHeight()) * 0.5); 165 263 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 166 navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth()); 167 navText_->setTop(navMarker_->getTop()+navMarker_->getHeight()); 168 } 169 } 170 if (!isAbove && isRight) 171 { 172 // bottom right quadrant 173 if (phiNav < phiUpperCorner) 174 { 175 //COUT(3) << "arrow down\n"; 176 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); 177 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 178 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); 179 navText_->setTop(navMarker_->getTop()-navMarker_->getHeight()); 180 } 181 else 182 { 183 //COUT(3) << "arrow right\n"; 184 navMarker_->setPosition(windowW-16, tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 185 navMarker_->setUV(0.5, 0.5, 1.0, 1.0); 186 navText_->setLeft(navMarker_->getLeft()-navMarker_->getWidth()); 187 navText_->setTop(navMarker_->getTop()+navMarker_->getHeight()); 188 } 189 } 190 if (isAbove && !isRight) 191 { 192 // top left quadrant 193 if (phiNav<phiUpperCorner) 194 { 195 //COUT(3) << "arrow up\n"; 196 navMarker_->setPosition(-tan(phiNav)*windowH/2+windowW/2, 0); 197 navMarker_->setUV(0.5, 0.0, 1.0, 0.5); 198 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); 199 navText_->setTop(navMarker_->getHeight()); 200 } 201 else 202 { 203 //COUT(3) << "arrow left\n"; 204 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 205 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 206 navText_->setLeft(navMarker_->getWidth()); 207 navText_->setTop(navMarker_->getTop()+navMarker_->getHeight()); 208 } 209 } 210 if (!isAbove && !isRight) 211 { 212 // bottom left quadrant 213 if (phiNav>-phiUpperCorner) 214 { 215 //COUT(3) << "arrow down\n"; 216 navMarker_->setPosition(tan(phiNav)*windowH/2+windowW/2, windowH-16); 217 navMarker_->setUV(0.0, 0.5, 0.5, 1.0); 218 navText_->setLeft(navMarker_->getLeft()+navMarker_->getWidth()); 219 navText_->setTop(navMarker_->getTop()-navMarker_->getHeight()); 220 } 221 else 222 { 223 //COUT(3) << "arrow left\n"; 224 navMarker_->setPosition(0, -tan((3.14-2*phiNav)/2)*windowW/2+windowH/2); 225 navMarker_->setUV(0.0, 0.0, 0.5, 0.5); 226 navText_->setLeft(navMarker_->getWidth()); 227 navText_->setTop(navMarker_->getTop()+navMarker_->getHeight()); 264 navText_->setLeft(1.0 - navMarker_->getWidth() - textLength - 0.01); 265 navText_->setTop((position - navText_->getCharHeight()) * 0.5); 228 266 } 229 267 } … … 232 270 { 233 271 // object is in view 234 navMarker_->setMaterialName("Orxonox/NavTDC"); 235 navMarker_->setDimensions(35, 35); 272 273 Vector3 aimpos = transformationMatrix * getPredictedPosition(SpaceShip::getLocalShip()->getPosition(), 274 Projectile::getSpeed(), focus_->getPosition(), focus_->getOrientedVelocity()); 275 276 if (wasOutOfView_) 277 { 278 navMarker_->setMaterialName("Orxonox/NavTDC"); 279 wasOutOfView_ = false; 280 } 281 282 // object is in view 236 283 navMarker_->setUV(0.0, 0.0, 1.0, 1.0); 237 navMarker_->setPosition(xPos-navMarker_->getWidth()/2, yPos-navMarker_->getHeight()/2); 284 navMarker_->setLeft((pos.x + 1.0 - navMarker_->getWidth()) * 0.5); 285 navMarker_->setTop((-pos.y + 1.0 - navMarker_->getHeight()) * 0.5); 238 286 239 287 aimMarker_->show(); 240 aimMarker_->setPosition(xAimPos-aimMarker_->getWidth()/2, yAimPos-aimMarker_->getHeight()/2); 241 242 navText_->setPosition(xPos+navMarker_->getWidth()/2, yPos+navMarker_->getHeight()/2); 288 aimMarker_->setLeft((aimpos.x + 1.0 - aimMarker_->getWidth()) * 0.5); 289 aimMarker_->setTop((-aimpos.y + 1.0 - aimMarker_->getHeight()) * 0.5); 290 291 navText_->setLeft((pos.x + 1.0 + navMarker_->getWidth()) * 0.5); 292 navText_->setTop((-pos.y + 1.0 + navMarker_->getHeight()) * 0.5); 243 293 } 244 294 } … … 293 343 if (focus_) 294 344 { 295 navMarker_->show(); 296 navText_->show(); 345 overlay_->show(); 297 346 focus_->setColour(ColourValue::White); 298 347 } 299 348 else 300 349 { 301 navMarker_->hide(); 302 aimMarker_->hide(); 303 navText_->hide(); 350 overlay_->hide(); 304 351 } 305 352 } … … 318 365 return 0; 319 366 } 367 368 void Navigation::windowResized(int newWidth, int newHeight) 369 { 370 HUDOverlay::windowResized(newWidth, newHeight); 371 372 //if (this->navMarker_) 373 // navMarker_->setDimensions(0.05, 0.05); 374 375 } 320 376 } -
code/branches/hud/src/orxonox/hud/Navigation.h
r1580 r1590 23 23 * Felix Schulthess 24 24 * Co-authors: 25 * ...25 * Reto Grieder 26 26 * 27 27 */ … … 35 35 #include <OgreTextAreaOverlayElement.h> 36 36 #include <OgrePanelOverlayElement.h> 37 #include "HUDOverlay.h" 38 #include "util/Math.h" 37 39 38 40 namespace orxonox 39 41 { 40 class _OrxonoxExport Navigation 42 class _OrxonoxExport Navigation : public HUDOverlay, public Tickable 41 43 { 42 44 public: 43 Navigation( Ogre::OverlayContainer* container);44 ~Navigation();45 Navigation(); 46 virtual ~Navigation(); 45 47 46 void update(); 48 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 49 50 virtual void tick(float dt); 51 47 52 void cycleFocus(); 48 53 float getDist2Focus() const; … … 52 57 void releaseFocus(); 53 58 59 protected: 60 virtual void windowResized(int newWidth, int newHeight); 61 54 62 private: 55 63 void init(); … … 57 65 void updateFocus(); 58 66 59 Ogre::OverlayContainer* container_; 67 void setNavMarkerSize(Vector2 size); 68 Vector2 getNavMarkerSize() const; 69 void setAimMarkerSize(Vector2 size); 70 Vector2 getAimMarkerSize() const; 71 void setTextSize(float size); 72 float getTextSize() const; 73 void setFont(const std::string& font); 74 std::string getFont() const; 75 76 Ogre::OverlayContainer* container_; //!< Container that holds the navigation elements 60 77 Ogre::PanelOverlayElement* navMarker_; // the panel used to show the arrow 61 78 Ogre::PanelOverlayElement* aimMarker_; … … 63 80 std::list<RadarObject*>::iterator it_; 64 81 RadarObject* focus_; // next pointer of linked list 82 bool wasOutOfView_; 65 83 }; 66 84 } -
code/branches/hud/src/orxonox/objects/SpaceShip.cc
r1564 r1590 369 369 370 370 std::string SpaceShip::whereAmI() { 371 372 373 371 return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x) 372 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y) 373 + " " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z); 374 374 } 375 375 … … 380 380 381 381 currentDir_ = getOrientation()*initialDir_; 382 382 currentOrth_ = getOrientation()*initialOrth_; 383 383 384 384 if (this->cam_) -
code/branches/hud/visual_studio/vc8/orxonox.vcproj
r1588 r1590 222 222 RelativePath="..\..\src\orxonox\hud\Navigation.cc" 223 223 > 224 <FileConfiguration 225 Name="Debug|Win32" 226 > 227 <Tool 228 Name="VCCLCompilerTool" 229 /> 230 </FileConfiguration> 224 231 </File> 225 232 <File … … 441 448 <File 442 449 RelativePath="..\..\src\orxonox\tools\Timer.cc" 450 > 451 </File> 452 <File 453 RelativePath="..\..\src\orxonox\tools\WindowEventListener.cc" 443 454 > 444 455 </File> … … 663 674 <File 664 675 RelativePath="..\..\src\orxonox\tools\Timer.h" 676 > 677 </File> 678 <File 679 RelativePath="..\..\src\orxonox\tools\WindowEventListener.h" 665 680 > 666 681 </File>
Note: See TracChangeset
for help on using the changeset viewer.