source: Swollen/swollen/hud.cpp @ 2225

Last change on this file since 2225 was 116, checked in by darran, 19 years ago
  • distro20050627
  • functioning record/playback/save. Can't yet replay from movie.swm
  • image capture not yet implemented.
File size: 3.3 KB
RevLine 
[33]1
2/*
[115]3  HeadsUpDisplay class for orthographic foreground display of text
[33]4
[115]5  An OpenSceneGraph viewer for pyVolution SWW files.
6  copyright (C) 2004 Geoscience Australia
[33]7*/
8
9
[6]10#include <osg/Geode>
11#include <osg/Geometry>
12#include <osg/Group>
13#include <osg/MatrixTransform>
[33]14#include <osg/StateSet>
15#include <hud.h>
[6]16
17#define ORTHO2D_WIDTH 1280
18#define ORTHO2D_HEIGHT 1024
19#define DEF_HUD_COLOUR   0.8, 0.8, 0.8, 1.0
20
[33]21
22// constructor
23HeadsUpDisplay::HeadsUpDisplay()
24{
[115]25   // a heads-up display requires an orthographic projection
26   _projection = new osg::Projection;
27   _projection->setMatrix( osg::Matrix::ortho2D(0,ORTHO2D_WIDTH,0,ORTHO2D_HEIGHT) );
[6]28
[115]29   // font
30   osgText::Font* font = osgText::readFontFile("fonts/arial.ttf");
[6]31
[115]32   // title text
33   _titletext = new osgText::Text;
34   _titletext->setFont(font);
35   _titletext->setColor(osg::Vec4(DEF_HUD_COLOUR) );
36   _titletext->setCharacterSize(20);
37   _titletext->setPosition(osg::Vec3(20,20,0));
38   _titletext->setFontResolution(40,40);
39   _dirtytime = false;
[6]40
[115]41   // timer text
42   _timetext = new osgText::Text;
43   _timetext->setFont(font);
44   _timetext->setColor(osg::Vec4(DEF_HUD_COLOUR) );
45   _timetext->setCharacterSize(30);
46   _timetext->setPosition(osg::Vec3(1100,20,0));
47   _timetext->setFontResolution(40,40);
48   _timevalue = 0.0;
49   _dirtytime = true;
[6]50
[115]51   // recording mode text
52   _modetext = new osgText::Text;
53   _modetext->setFont(font);
54   _modetext->setColor(osg::Vec4(DEF_HUD_COLOUR) );
55   _modetext->setCharacterSize(30);
56   _modetext->setPosition(osg::Vec3(600,20,0));
57   _modetext->setFontResolution(40,40);
[116]58   _modestring = std::string("");
[115]59   _dirtymode = true;
[111]60
61
[115]62   // state
63   osg::StateSet *state = _projection->getOrCreateStateSet();
64   state->setRenderBinDetails(12, "RenderBin");
65   state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
66   state->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
[6]67
[115]68   // scenegraph
69   osg::MatrixTransform* xfm = new osg::MatrixTransform;
70   xfm->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
71   xfm->setMatrix(osg::Matrix::identity());
72   osg::Geode* textnode = new osg::Geode;
73   textnode->addDrawable( _titletext );
74   textnode->addDrawable( _timetext );
75   textnode->addDrawable( _modetext );
76   xfm->addChild( textnode );
77   _projection->addChild( xfm );
[33]78}
79
80
[6]81HeadsUpDisplay::~HeadsUpDisplay()
82{
83}
[33]84
85
86
87void HeadsUpDisplay::setTime( float t )
88{
[115]89   if( t != _timevalue )
90   {
91      _timevalue = t;
92      _dirtytime = true;
93   }
[33]94}
95
96
[116]97void HeadsUpDisplay::setTitle( char* s )
[33]98{
[116]99   std::string tmp = std::string(s);
100   if( tmp != _titlestring )
[115]101   {
[116]102      _titlestring = tmp;
[115]103      _dirtytitle = true;
104   }
[33]105}
106
[111]107
[116]108void HeadsUpDisplay::setMode( char* s )
[111]109{
[116]110   std::string tmp = std::string(s);
111   if( tmp != _modestring )
[115]112   {
[116]113      _modestring = tmp;
[115]114      _dirtymode = true;
115   }
[111]116}
117
[115]118
119
120void HeadsUpDisplay::update()
121{
122   
123   if( _dirtytime )
124   {
125      char timestr[20];
126      sprintf(timestr, "t = %-7.2f", _timevalue);
127      _timetext->setText(timestr);
128
129      // hud time now updated ...
130      _dirtytime = false;
131   }
132
133
134   if( _dirtymode )
135   {
[116]136      _modetext->setText(_modestring.c_str());
[115]137
138      // hud "recording/playback" text now updated ...
139      _dirtymode = false;
140   }
141
142
143   if( _dirtytitle )
144   {
[116]145      _titletext->setText(_titlestring.c_str());
[115]146
147      // hud title text now updated ...
148      _dirtytitle = false;
149   }
150}
Note: See TracBrowser for help on using the repository browser.