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

Last change on this file since 426 was 305, checked in by Torben Dannhauer, 13 years ago
File size: 5.1 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#include <terrainQuery.h>
19
20using namespace osgVisual;
21
22visual_debug_hud::visual_debug_hud(void)
23{
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        /*double x = 0;
148        double y = 0;
149        double z = 0;
150
151        util::getXYZofCamera( sceneCamera, x, y, z );
152        hat = terrainQuery::computeHeightAboveTerrain(csn, osg::Vec3d(x,y,z), terrainQuery::PAGE_HIGHEST_LOD);
153        hot = terrainQuery::computeHeightOfTerrain(csn, osg::Vec3d(x,y,z), terrainQuery::PAGE_HIGHEST_LOD);*/
154
155
156        // Updating Display Elements:
157        std::ostringstream valuestring;
158       
159        valuestring.str("");
160        valuestring << osg::RadiansToDegrees( lat );
161        hud->textLat->setText("LAT: "+valuestring.str());
162
163        valuestring.str("");
164        valuestring << osg::RadiansToDegrees( lon );
165        hud->textLon->setText("LON: "+valuestring.str());
166
167        valuestring << std::fixed;
168        valuestring.precision(2);
169        valuestring.fill('0');
170
171        valuestring.width(8);
172        valuestring.str("");
173        valuestring << alt;
174        hud->textAlt->setText("ALT: "+valuestring.str());
175
176
177        valuestring.width(8);
178        valuestring.str("");
179        valuestring << hat;
180        hud->textHat->setText("HAT: "+valuestring.str());
181
182        valuestring.width(8);
183        valuestring.str("");
184        valuestring << hot;
185        hud->textHot->setText("HOT: "+valuestring.str());
186}
Note: See TracBrowser for help on using the repository browser.