35
35
#include < osgGA/StateSetManipulator>
36
36
#include < osgGA/GUIEventHandler>
37
37
38
+ #include < osg/MatrixTransform>
39
+ #include < osg/ShapeDrawable>
38
40
#include < osgViewer/Viewer>
39
41
#include < osgViewer/ViewerEventHandlers>
40
42
#include < osgEarth/Notify>
41
43
#include < osgEarth/Map>
42
44
#include < osgEarth/MapNode>
43
45
#include < osgEarthUtil/EarthManipulator>
46
+ #include < osgEarthUtil/ElevationManager>
47
+ #include < osgEarthUtil/ObjectPlacer>
44
48
#include < osgEarth/TileSource>
45
49
#include < osgEarthDrivers/gdal/GDALOptions>
46
50
#include < osgEarthDrivers/tms/TMSOptions>
@@ -62,7 +66,9 @@ GlobePlugin::GlobePlugin( QgisInterface* theQgisInterface )
62
66
mQActionPointer( NULL ),
63
67
viewer(),
64
68
mQDockWidget( tr( " Globe" ) ),
65
- mTileSource(0 )
69
+ mTileSource(0 ),
70
+ mElevationManager( NULL ),
71
+ mObjectPlacer( NULL )
66
72
{
67
73
}
68
74
@@ -149,6 +155,52 @@ void GlobePlugin::run()
149
155
ControlCanvas* cs = new ControlCanvas ( &viewer );
150
156
root->addChild ( cs );
151
157
158
+ // model placement utils
159
+ mElevationManager = new osgEarthUtil::ElevationManager ( mMapNode ->getMap () );
160
+ mElevationManager ->setTechnique ( osgEarthUtil::ElevationManager::TECHNIQUE_GEOMETRIC );
161
+ mElevationManager ->setMaxTilesToCache ( 50 );
162
+
163
+ mObjectPlacer = new osgEarthUtil::ObjectPlacer ( mMapNode );
164
+
165
+ #if 0
166
+ // model placement test
167
+
168
+ // create simple tree model from primitives
169
+ osg::TessellationHints* hints = new osg::TessellationHints();
170
+ hints->setDetailRatio(0.1);
171
+
172
+ osg::Cylinder* cylinder = new osg::Cylinder( osg::Vec3(0 ,0, 5), 0.5, 10 );
173
+ osg::ShapeDrawable* cylinderDrawable = new osg::ShapeDrawable( cylinder, hints );
174
+ cylinderDrawable->setColor( osg::Vec4( 0.5, 0.25, 0.125, 1.0 ) );
175
+ osg::Geode* cylinderGeode = new osg::Geode();
176
+ cylinderGeode->addDrawable( cylinderDrawable );
177
+
178
+ osg::Cone* cone = new osg::Cone( osg::Vec3(0 ,0, 10), 4, 10 );
179
+ osg::ShapeDrawable* coneDrawable = new osg::ShapeDrawable( cone, hints );
180
+ coneDrawable->setColor( osg::Vec4( 0.0, 0.5, 0.0, 1.0 ) );
181
+ osg::Geode* coneGeode = new osg::Geode();
182
+ coneGeode->addDrawable( coneDrawable );
183
+
184
+ osg::Group* model = new osg::Group();
185
+ model->addChild( cylinderGeode );
186
+ model->addChild( coneGeode );
187
+
188
+ // place models on jittered grid
189
+ srand( 23 );
190
+ double lat = 47.235;
191
+ double lon = 9.36;
192
+ double gridSize = 0.001;
193
+ for( int i=0; i<10; i++ )
194
+ {
195
+ for( int j=0; j<10; j++ )
196
+ {
197
+ double dx = gridSize * ( rand()/( (double)RAND_MAX + 1.0 ) - 0.5 );
198
+ double dy = gridSize * ( rand()/( (double)RAND_MAX + 1.0 ) - 0.5 );
199
+ placeNode( root, model, lat + i * gridSize + dx, lon + j * gridSize + dy );
200
+ }
201
+ }
202
+ #endif
203
+
152
204
viewer.setSceneData ( root );
153
205
154
206
// Set a home viewpoint
@@ -265,6 +317,21 @@ void GlobePlugin::help()
265
317
{
266
318
}
267
319
320
+ void GlobePlugin::placeNode ( osg::Group* root, osg::Node* node, double lat, double lon, double alt /* = 0.0*/ )
321
+ {
322
+ // get elevation
323
+ double elevation = 0.0 ;
324
+ double resolution = 0.0 ;
325
+ mElevationManager ->getElevation ( lon, lat, 0 , NULL , elevation, resolution );
326
+
327
+ // place model
328
+ osg::Matrix mat;
329
+ mObjectPlacer ->createPlacerMatrix ( lat, lon, elevation + alt, mat );
330
+
331
+ osg::MatrixTransform* mt = new osg::MatrixTransform ( mat );
332
+ mt->addChild ( node );
333
+ root->addChild ( mt );
334
+ }
268
335
269
336
bool FlyToExtentHandler::handle ( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
270
337
{
0 commit comments