source: osgVisual/src/draw2D/visual_debug_hud.cpp @ 87

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

Introductes VS 2008 Memory Leak Debugging.
Todo: Compile on Linux and compare with Valgrind, VS 2008 seems to be awkward in leak debugging

File size: 4.8 KB
Line 
1/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 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        #include <leakDetection.h>
24}
25
26visual_debug_hud::~visual_debug_hud(void)
27{
28}
29
30bool visual_debug_hud::init( osgViewer::Viewer *viewer_, osg::CoordinateSystemNode* rootNode_  )
31{       
32
33
34
35    screen_width = viewer_->getCamera()->getViewport()->width();
36    screen_height = viewer_->getCamera()->getViewport()->height();
37       
38        visual_draw2D::getInstance()->addDrawContent( addContent(), "HUD" );
39
40        // Set callback.
41        updateCallback = new HudUpdateCallback( rootNode_, viewer_->getCamera() );
42        this->setEventCallback( updateCallback );
43
44        isInitialized = true;
45
46        return true;
47}
48
49void visual_debug_hud::shutdown()
50{
51        if (isInitialized)
52        {       
53                // Remove Draw Content
54                visual_draw2D::getInstance()->removeDrawContent("HUD");
55
56                // Remove updatecallback
57                this->removeEventCallback( updateCallback );
58                updateCallback = NULL;
59        }
60}
61
62osg::ref_ptr<osg::Geode> visual_debug_hud::addContent()
63{
64        osg::ref_ptr<osg::Geode> hudGeode = this;
65
66        // turn lighting off
67        osg::ref_ptr<osg::StateSet> stateset = hudGeode->getOrCreateStateSet();
68    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
69
70
71   
72        // Add Text:
73        osg::Vec3 position(screen_width-180.0f,120.0f,0.0f);
74        osg::Vec3 delta(0.0f,-25.0f,0.0f);
75        std::string timesFont("fonts/arial.ttf");
76        {
77                textLat = new osgText::Text;
78                hudGeode->addDrawable( textLat );
79                textLat->setFont(timesFont);
80                textLat->setPosition(position);
81                textLat->setCharacterSize(21);
82                textLat->setDataVariance(osg::Object::DYNAMIC); 
83
84                position += delta;
85
86                textLon = new osgText::Text;
87                hudGeode->addDrawable( textLon );
88                textLon->setFont(timesFont);
89                textLon->setPosition(position);
90                textLon->setCharacterSize(21);
91                textLon->setDataVariance(osg::Object::DYNAMIC); 
92
93                position += delta;
94
95                textAlt = new osgText::Text;
96                hudGeode->addDrawable( textAlt );
97                textAlt->setFont(timesFont);
98                textAlt->setPosition(position);
99                textAlt->setCharacterSize(21);
100                textAlt->setDataVariance(osg::Object::DYNAMIC); 
101
102                position += delta;
103
104                textHat = new osgText::Text;
105                hudGeode->addDrawable( textHat );
106                textHat->setFont(timesFont);
107                textHat->setPosition(position);
108                textHat->setCharacterSize(21);
109                textHat->setDataVariance(osg::Object::DYNAMIC); 
110
111                position += delta;
112
113                textHot = new osgText::Text;
114                hudGeode->addDrawable( textHot );
115                textHot->setFont(timesFont);
116                textHot->setPosition(position);
117                textHot->setCharacterSize(21);
118                textHot->setDataVariance(osg::Object::DYNAMIC); 
119
120                position += delta;
121        }
122
123        return hudGeode.get();
124}
125
126void visual_debug_hud::HudUpdateCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
127{
128        visual_debug_hud* hud = dynamic_cast<visual_debug_hud*>(node);
129        if ( !hud )
130        {
131                OSG_NOTIFY(osg::FATAL) << "ERROR : No object found. Unable to apply this callback!" << std::endl;
132                return;
133        }
134
135        // Retrieving new HUD values
136
137        double lat = 0;
138        double lon = 0;
139        double hat = 0;
140        double hot = 0;
141        double alt = 0;
142
143        util::getWGS84ofCamera( sceneCamera, csn, lat, lon, alt ); 
144        util::queryHeightAboveTerrainInWGS84(hat, csn, lat, lon, alt);
145        util::queryHeightOfTerrain(hot, csn, lat, lon);
146
147
148        // Updating Display Elements:
149        std::ostringstream valuestring;
150       
151        valuestring.str("");
152        valuestring << osg::RadiansToDegrees( lat );
153        hud->textLat->setText("LAT: "+valuestring.str());
154
155        valuestring.str("");
156        valuestring << osg::RadiansToDegrees( lon );
157        hud->textLon->setText("LON: "+valuestring.str());
158
159        valuestring << std::fixed;
160        valuestring.precision(2);
161        valuestring.fill('0');
162
163        valuestring.width(8);
164        valuestring.str("");
165        valuestring << alt;
166        hud->textAlt->setText("ALT: "+valuestring.str());
167
168
169        valuestring.width(8);
170        valuestring.str("");
171        valuestring << hat;
172        hud->textHat->setText("HAT: "+valuestring.str());
173
174        valuestring.width(8);
175        valuestring.str("");
176        valuestring << hot;
177        hud->textHot->setText("HOT: "+valuestring.str());
178}
Note: See TracBrowser for help on using the repository browser.