/* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * * This HUD is used for the implementation of the campaign map. * So far it can only be used to give names to an object planet. * * Author: * Nikola Bolt * Co-authors: * Claudio Fanconi */ // Header file of this cc file #include "StoryModeHUD.h" // Ogre stuff #include #include #include #include #include // Other stuff #include #include "util/Math.h" #include "util/Convert.h" #include "core/command/ConsoleCommandIncludes.h" #include "core/CoreIncludes.h" #include "core/XMLPort.h" #include "CameraManager.h" #include "Scene.h" #include "Radar.h" #include "graphics/Camera.h" #include "controllers/HumanController.h" #include "worldentities/pawns/Pawn.h" #include "worldentities/WorldEntity.h" #include "core/config/ConfigValueIncludes.h" #include "tools/TextureGenerator.h" namespace orxonox { RegisterClass ( StoryModeHUD ); // Constructor of the StoryMode HUD StoryModeHUD::StoryModeHUD(Context* context) : OrxonoxOverlay(context) { RegisterObject(StoryModeHUD); // Set default values //this->setFont("Monofur"); //this->setTextSize(0.5f); // Scales used for dimensions and text size float xScale = this->getActualSize().x; float yScale = this->getActualSize().y; // Create text text_ = static_cast( Ogre::OverlayManager::getSingleton() .createOverlayElement("TextArea", "StoryModeHUD_navText_" + getUniqueNumberString())); //text->setFontName(this->fontName_); //text->setCharHeight(this->textSize_ * yScale); text_->setDimensions(xScale, yScale); text_->hide(); this->background_->addChild(text_); } // TODO: // Destructor of the StoryMode HUD StoryModeHUD::~StoryModeHUD() { } // Functions of the StoryMode HUD // XML Port for Level construction. void StoryModeHUD::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(StoryModeHUD, XMLPort, xmlelement, mode); XMLPortParam(StoryModeHUD, "font", setFont, getFont, xmlelement, mode); XMLPortParam(StoryModeHUD, "textSize", setTextSize, getTextSize, xmlelement, mode); } // Set the Font size of the Text. void StoryModeHUD::setFont(const std::string& font) { const Ogre::ResourcePtr& fontPtr = Ogre::FontManager::getSingleton().getByName(font); if (fontPtr.isNull()) { orxout(internal_warning) << "StoryModeHUD: Font '" << font << "' not found" << endl; return; } this->fontName_ = font; if(text_ != nullptr) text_->setFontName(this->fontName_); } // Gets the Font of the Text const std::string& StoryModeHUD::getFont() const { return this->fontName_; } // Set the size of the Text void StoryModeHUD::setTextSize(float size) { if (size <= 0.0f) { orxout(internal_warning) << "StoryModeHUD: Negative font size not allowed" << endl; return; } this->textSize_ = size; } // returns the Size of the Text float StoryModeHUD::getTextSize() const { return this->textSize_; } // Tick: this is the most important function. It's recalled every frame and makes sure things happen on the screen. void StoryModeHUD::tick(float dt) { SUPER(StoryModeHUD, tick, dt); // cam is the pointer which represents your camera Camera* cam = CameraManager::getInstance().getActiveCamera(); if (cam == nullptr) return; // camTransform is a Matrix, which converts 3D world of the game into 2D on your screen const Matrix4& camTransform = cam->getOgreCamera()->getProjectionMatrix() * cam->getOgreCamera()->getViewMatrix(); //display name next to cursor //TODO: Planet.getName() text_->setCaption("Was geht ab?"); // Transform to screen coordinates Vector3 pos = camTransform * Vector3(0,0,0); // planet->getRVWorldPosition(); // If you fly passed the description, it gets out of sight if (pos.z > 1.0) return; // Position text text_->setLeft((pos.x+1)/2); // The (0,0) Coordinate is in the upper left corner. text_->setTop((-pos.y+1)/2); // With those two calculations we set the desired positions // Make sure the overlays are shown text_->show(); } //void StoryModeHUD::addObject() /*void StoryModeHUD::removeObject(RadarViewable* viewable) { Ogre::OverlayManager::getSingleton().destroyOverlayElement(it->second.text_); }*/ }