/* HeadsUpDisplay class for orthographic foreground display of text An OpenSceneGraph viewer for pyVolution SWW files. copyright (C) 2004 Geoscience Australia */ #include #include #include #include #include #include #define ORTHO2D_WIDTH 1280 #define ORTHO2D_HEIGHT 1024 #define DEF_HUD_COLOUR 0.8, 0.8, 0.8, 1.0 // constructor HeadsUpDisplay::HeadsUpDisplay() { // a heads-up display requires an orthographic projection _projection = new osg::Projection; _projection->setMatrix( osg::Matrix::ortho2D(0,ORTHO2D_WIDTH,0,ORTHO2D_HEIGHT) ); // font osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); // title text _titletext = new osgText::Text; _titletext->setFont(font); _titletext->setColor(osg::Vec4(DEF_HUD_COLOUR) ); _titletext->setCharacterSize(20); _titletext->setPosition(osg::Vec3(20,20,0)); _titletext->setFontResolution(40,40); _dirtytime = false; // timer text _timetext = new osgText::Text; _timetext->setFont(font); _timetext->setColor(osg::Vec4(DEF_HUD_COLOUR) ); _timetext->setCharacterSize(30); _timetext->setPosition(osg::Vec3(1100,20,0)); _timetext->setFontResolution(40,40); _timevalue = 0.0; _dirtytime = true; // recording mode text _modetext = new osgText::Text; _modetext->setFont(font); _modetext->setColor(osg::Vec4(DEF_HUD_COLOUR) ); _modetext->setCharacterSize(30); _modetext->setPosition(osg::Vec3(600,20,0)); _modetext->setFontResolution(40,40); _modestring = std::string(""); _dirtymode = true; // state osg::StateSet *state = _projection->getOrCreateStateSet(); state->setRenderBinDetails(12, "RenderBin"); state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); state->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); // scenegraph osg::MatrixTransform* xfm = new osg::MatrixTransform; xfm->setReferenceFrame(osg::Transform::ABSOLUTE_RF); xfm->setMatrix(osg::Matrix::identity()); osg::Geode* textnode = new osg::Geode; textnode->addDrawable( _titletext ); textnode->addDrawable( _timetext ); textnode->addDrawable( _modetext ); xfm->addChild( textnode ); _projection->addChild( xfm ); } HeadsUpDisplay::~HeadsUpDisplay() { } void HeadsUpDisplay::setTime( float t ) { if( t != _timevalue ) { _timevalue = t; _dirtytime = true; } } void HeadsUpDisplay::setTitle( char* s ) { std::string tmp = std::string(s); if( tmp != _titlestring ) { _titlestring = tmp; _dirtytitle = true; } } void HeadsUpDisplay::setMode( char* s ) { std::string tmp = std::string(s); if( tmp != _modestring ) { _modestring = tmp; _dirtymode = true; } } void HeadsUpDisplay::update() { if( _dirtytime ) { char timestr[20]; sprintf(timestr, "t = %-7.2f", _timevalue); _timetext->setText(timestr); // hud time now updated ... _dirtytime = false; } if( _dirtymode ) { _modetext->setText(_modestring.c_str()); // hud "recording/playback" text now updated ... _dirtymode = false; } if( _dirtytitle ) { _titletext->setText(_titlestring.c_str()); // hud title text now updated ... _dirtytitle = false; } }