source: osgVisual/trunk/src/draw2D/visual_debug_hud.cpp @ 264

Last change on this file since 264 was 221, checked in by Torben Dannhauer, 14 years ago

Updated copyright NOTICE
(No code changes)

File size: 4.7 KB
Line 
1/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer
2 *
3 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
9 * You have to aquire licenses for all used proprietary modules.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * OpenSceneGraph Public License for more details.
15*/
16
17#include <visual_debug_hud.h>
18
19using namespace osgVisual;
20
21visual_debug_hud::visual_debug_hud(void)
22{
23}
24
25visual_debug_hud::~visual_debug_hud(void)
26{
27}
28
29bool visual_debug_hud::init( osgViewer::Viewer *viewer_, osg::CoordinateSystemNode* rootNode_  )
30{       
31
32
33
34    screen_width = viewer_->getCamera()->getViewport()->width();
35    screen_height = viewer_->getCamera()->getViewport()->height();
36       
37        visual_draw2D::getInstance()->addDrawContent( addContent(), "HUD" );
38
39        // Set callback.
40        updateCallback = new HudUpdateCallback( rootNode_, viewer_->getCamera() );
41        this->setEventCallback( updateCallback );
42
43        isInitialized = true;
44
45        return true;
46}
47
48void visual_debug_hud::shutdown()
49{
50        if (isInitialized)
51        {       
52                // Remove Draw Content
53                visual_draw2D::getInstance()->removeDrawContent("HUD");
54
55                // Remove updatecallback
56                this->removeEventCallback( updateCallback );
57                updateCallback = NULL;
58        }
59}
60
61osg::ref_ptr<osg::Geode> visual_debug_hud::addContent()
62{
63        osg::ref_ptr<osg::Geode> hudGeode = this;
64
65        // turn lighting off
66        osg::ref_ptr<osg::StateSet> stateset = hudGeode->getOrCreateStateSet();
67    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
68
69
70   
71        // Add Text:
72        osg::Vec3 position(screen_width-180.0f,120.0f,0.0f);
73        osg::Vec3 delta(0.0f,-25.0f,0.0f);
74        std::string timesFont("fonts/arial.ttf");
75        {
76                textLat = new osgText::Text;
77                hudGeode->addDrawable( textLat );
78                textLat->setFont(timesFont);
79                textLat->setPosition(position);
80                textLat->setCharacterSize(21);
81                textLat->setDataVariance(osg::Object::DYNAMIC); 
82
83                position += delta;
84
85                textLon = new osgText::Text;
86                hudGeode->addDrawable( textLon );
87                textLon->setFont(timesFont);
88                textLon->setPosition(position);
89                textLon->setCharacterSize(21);
90                textLon->setDataVariance(osg::Object::DYNAMIC); 
91
92                position += delta;
93
94                textAlt = new osgText::Text;
95                hudGeode->addDrawable( textAlt );
96                textAlt->setFont(timesFont);
97                textAlt->setPosition(position);
98                textAlt->setCharacterSize(21);
99                textAlt->setDataVariance(osg::Object::DYNAMIC); 
100
101                position += delta;
102
103                textHat = new osgText::Text;
104                hudGeode->addDrawable( textHat );
105                textHat->setFont(timesFont);
106                textHat->setPosition(position);
107                textHat->setCharacterSize(21);
108                textHat->setDataVariance(osg::Object::DYNAMIC); 
109
110                position += delta;
111
112                textHot = new osgText::Text;
113                hudGeode->addDrawable( textHot );
114                textHot->setFont(timesFont);
115                textHot->setPosition(position);
116                textHot->setCharacterSize(21);
117                textHot->setDataVariance(osg::Object::DYNAMIC); 
118
119                position += delta;
120        }
121
122        return hudGeode.get();
123}
124
125void visual_debug_hud::HudUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
126{
127        visual_debug_hud* hud = dynamic_cast<visual_debug_hud*>(node);
128        if ( !hud )
129        {
130                OSG_NOTIFY(osg::FATAL) << "ERROR : No object found. Unable to apply this callback!" << std::endl;
131                return;
132        }
133
134        // Retrieving new HUD values
135
136        double lat = 0;
137        double lon = 0;
138        double hat = 0;
139        double hot = 0;
140        double alt = 0;
141
142        util::getWGS84ofCamera( sceneCamera, csn, lat, lon, alt ); 
143        util::queryHeightAboveTerrainInWGS84(hat, csn, lat, lon, alt);
144        util::queryHeightOfTerrain(hot, csn, lat, lon);
145
146
147        // Updating Display Elements:
148        std::ostringstream valuestring;
149       
150        valuestring.str("");
151        valuestring << osg::RadiansToDegrees( lat );
152        hud->textLat->setText("LAT: "+valuestring.str());
153
154        valuestring.str("");
155        valuestring << osg::RadiansToDegrees( lon );
156        hud->textLon->setText("LON: "+valuestring.str());
157
158        valuestring << std::fixed;
159        valuestring.precision(2);
160        valuestring.fill('0');
161
162        valuestring.width(8);
163        valuestring.str("");
164        valuestring << alt;
165        hud->textAlt->setText("ALT: "+valuestring.str());
166
167
168        valuestring.width(8);
169        valuestring.str("");
170        valuestring << hat;
171        hud->textHat->setText("HAT: "+valuestring.str());
172
173        valuestring.width(8);
174        valuestring.str("");
175        valuestring << hot;
176        hud->textHot->setText("HOT: "+valuestring.str());
177}
Note: See TracBrowser for help on using the repository browser.