1 | |
---|
2 | /* |
---|
3 | HeadsUpDisplay class for orthographic foreground display of text |
---|
4 | |
---|
5 | An OpenSceneGraph viewer for pyVolution SWW files. |
---|
6 | copyright (C) 2004 Geoscience Australia |
---|
7 | */ |
---|
8 | |
---|
9 | |
---|
10 | #include <osg/Geode> |
---|
11 | #include <osg/Geometry> |
---|
12 | #include <osg/Group> |
---|
13 | #include <osg/MatrixTransform> |
---|
14 | #include <osg/StateSet> |
---|
15 | #include <hud.h> |
---|
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 | |
---|
21 | |
---|
22 | // constructor |
---|
23 | HeadsUpDisplay::HeadsUpDisplay() |
---|
24 | { |
---|
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) ); |
---|
28 | |
---|
29 | // font |
---|
30 | osgText::Font* font = osgText::readFontFile("fonts/arial.ttf"); |
---|
31 | |
---|
32 | // title text |
---|
33 | _title = new osgText::Text; |
---|
34 | _title->setFont(font); |
---|
35 | _title->setColor(osg::Vec4(DEF_HUD_COLOUR) ); |
---|
36 | _title->setCharacterSize(20); |
---|
37 | _title->setPosition(osg::Vec3(20,20,0)); |
---|
38 | _title->setFontResolution(40,40); |
---|
39 | |
---|
40 | // timer text |
---|
41 | _time = new osgText::Text; |
---|
42 | _time->setFont(font); |
---|
43 | _time->setColor(osg::Vec4(DEF_HUD_COLOUR) ); |
---|
44 | _time->setCharacterSize(30); |
---|
45 | _time->setPosition(osg::Vec3(1100,20,0)); |
---|
46 | _time->setFontResolution(40,40); |
---|
47 | _time->setText("t = 0.0"); |
---|
48 | |
---|
49 | // state |
---|
50 | osg::StateSet *state = _projection->getOrCreateStateSet(); |
---|
51 | state->setRenderBinDetails(12, "RenderBin"); |
---|
52 | state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
---|
53 | state->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); |
---|
54 | |
---|
55 | // scenegraph |
---|
56 | osg::MatrixTransform* xfm = new osg::MatrixTransform; |
---|
57 | xfm->setReferenceFrame(osg::Transform::ABSOLUTE_RF); |
---|
58 | xfm->setMatrix(osg::Matrix::identity()); |
---|
59 | osg::Geode* textnode = new osg::Geode; |
---|
60 | textnode->addDrawable( _title ); |
---|
61 | textnode->addDrawable( _time ); |
---|
62 | xfm->addChild( textnode ); |
---|
63 | _projection->addChild( xfm ); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | HeadsUpDisplay::~HeadsUpDisplay() |
---|
68 | { |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | void HeadsUpDisplay::setTime( float t ) |
---|
74 | { |
---|
75 | char timestr[20]; |
---|
76 | sprintf(timestr, "t = %-7.2f", t); |
---|
77 | _time->setText(timestr); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void HeadsUpDisplay::setTitle( char *s ) |
---|
82 | { |
---|
83 | _title->setText(s); |
---|
84 | } |
---|
85 | |
---|