TextHUD.h
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2013 University of Jaume-I.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the GNU Public License v3.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.gnu.org/licenses/gpl.html
00007  * 
00008  * Contributors:
00009  *     Mario Prats
00010  *     Javier Perez
00011  */
00012 
00013 // ----------------------------------------------------
00014 //                  Text HUD Class
00015 // ----------------------------------------------------
00016 #include <osg/PositionAttitudeTransform>
00017 
00018 class TextHUD : public osg::Referenced
00019 {
00020 private:
00021   osg::ref_ptr<osg::Camera> _camera;
00022   osg::ref_ptr<osgText::Text> _modeText;
00023   osg::ref_ptr<osgText::Text> _cameraModeText;
00024 
00025 public:
00026   TextHUD(void)
00027   {
00028     _camera = createCamera();
00029     _camera->addChild(createText());
00030   }
00031 
00032   osg::Camera* createCamera(void)
00033   {
00034     osg::ref_ptr<osg::Camera> camera = new osg::Camera;
00035 
00036     camera->setViewport(0, 0, 1024, 768);
00037     camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
00038     camera->setProjectionMatrixAsOrtho2D(0, 1024, 0, 768);
00039     camera->setRenderOrder(osg::Camera::POST_RENDER);
00040     camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
00041     camera->setClearMask(GL_DEPTH_BUFFER_BIT);
00042 //      camera->setProjectionResizePolicy(osg::Camera::VERTICAL);
00043 
00044     return camera.release();
00045   }
00046 
00047   osg::Node* createText(void)
00048   {
00049     osg::Geode* textGeode = new osg::Geode;
00050 
00051     osgText::Text* title = new osgText::Text;
00052     //title->setFont("fonts/arial.ttf");
00053     title->setCharacterSize(24);
00054     title->setLineSpacing(0.4f);
00055 
00056     std::string versionText = std::string("\nPress 'h' for options");
00057 
00058     title->setText(versionText);
00059     textGeode->addDrawable(title);
00060 
00061     _modeText = new osgText::Text;
00062     //_modeText->setFont("fonts/arial.ttf");
00063     _modeText->setCharacterSize(24);
00064     _modeText->setPosition(osg::Vec3f(0.f, -40.f, 0.f));
00065     _modeText->setDataVariance(osg::Object::DYNAMIC);
00066     textGeode->addDrawable(_modeText.get());
00067 
00068     _cameraModeText = new osgText::Text;
00069     //_cameraModeText->setFont("fonts/arial.ttf");
00070     _cameraModeText->setCharacterSize(24);
00071     _cameraModeText->setPosition(osg::Vec3f(0.f, -60.f, 0.f));
00072     _cameraModeText->setDataVariance(osg::Object::DYNAMIC);
00073     //textGeode->addDrawable( _cameraModeText.get() );
00074 
00075     osg::PositionAttitudeTransform* titlePAT = new osg::PositionAttitudeTransform;
00076     titlePAT->setPosition(osg::Vec3f(10, 70, 0.f));
00077     //titlePAT->addChild(textGeode);
00078 
00079     return titlePAT;
00080   }
00081 
00082   void setSceneText(const std::string& preset)
00083   {
00084     _modeText->setText("\nWeather: " + preset + "\n");
00085   }
00086 
00087   void setCameraText(const std::string& mode)
00088   {
00089     _cameraModeText->setText("Camera: " + mode);
00090   }
00091 
00092   osg::Camera* getHudCamera(void)
00093   {
00094     return _camera.get();
00095   }
00096 };


uwsim
Author(s): Mario Prats , Javier Perez
autogenerated on Fri Aug 28 2015 13:28:58