forked from dardok/eqEarth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.h
81 lines (63 loc) · 2 KB
/
callbacks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#pragma once
#include <osg/NodeCallback>
#include <osgEarthUtil/Sky>
#include "view.h"
#include "controls.h"
namespace eqEarth
{
// ----------------------------------------------------------------------------
struct SkyUpdateCallback : public osg::NodeCallback
{
SkyUpdateCallback( ) : _lastSec( -1 ) { }
void operator( )( osg::Node* node, osg::NodeVisitor* nv )
{
if( osg::NodeVisitor::UPDATE_VISITOR == nv->getVisitorType( ))
{
osg::ref_ptr< const osg::FrameStamp > fs = nv->getFrameStamp( );
struct tm now;
fs->getCalendarTime( now );
if( _lastSec != now.tm_sec )
{
static_cast< osgEarth::Util::SkyNode* >( node )->setDateTime(
osgEarth::Util::DateTime( now.tm_year + 1900, now.tm_mon + 1, now.tm_mday,
now.tm_hour + ( now.tm_min / 60.0 ) + ( now.tm_sec / 3600.0 )));
_lastSec = now.tm_sec;
}
}
traverse( node, nv );
}
private:
int _lastSec;
};
// ----------------------------------------------------------------------------
struct ControlUpdateCallback : public osg::NodeCallback
{
ControlUpdateCallback( View* view, LonLatLabelControl* ll )
: _view( view ), _ll( ll ), _last_lat( 0. ), _last_lon( 0. ) { }
void operator( )( osg::Node* node, osg::NodeVisitor* nv )
{
lunchbox::ScopedWrite _mutex( _update_lock );
if( osg::NodeVisitor::UPDATE_VISITOR == nv->getVisitorType( ))
{
#if 0
osgEarth::Util::Controls::ControlCanvas* cc =
static_cast< osgEarth::Util::Controls::ControlCanvas* >( node );
#endif
double lat, lon;
_view->getLatLon( lat, lon );
if(( _last_lat != lat ) || ( _last_lon != lon ))
{
_ll->updateLonLat( lon, lat );
_last_lat = lat; _last_lon = lon;
}
}
traverse( node, nv );
}
private:
View* _view;
osg::ref_ptr< LonLatLabelControl > _ll;
double _last_lat, _last_lon;
static lunchbox::Lock _update_lock;
};
lunchbox::Lock ControlUpdateCallback::_update_lock;
};