void CBillboardGroupSceneNode::addBillboardWithAxis( const core::vector3df& position, const core::dimension2df& size, const core::vector3df& axis, f32 roll, video::SColor vertexColor )
{
    s32 index = Billboards.size();
    
    addBillboard( position, size, roll, vertexColor );
    
    Billboards[index].HasAxis = true;
    Billboards[index].Axis = axis;
}
Exemple #2
0
void GlobePlugin::run()
{
  if ( mViewerWidget != 0 )
  {
    return;
  }
#ifdef GLOBE_SHOW_TILE_STATS
  QgsGlobeTileStatistics* tileStats = new QgsGlobeTileStatistics();
  connect( tileStats, SIGNAL( changed( int, int ) ), this, SLOT( updateTileStats( int, int ) ) );
#endif
  QSettings settings;

//    osgEarth::setNotifyLevel( osg::DEBUG_INFO );

  mOsgViewer = new osgViewer::Viewer();
  mOsgViewer->setThreadingModel( osgViewer::Viewer::SingleThreaded );
  mOsgViewer->setRunFrameScheme( osgViewer::Viewer::ON_DEMAND );
  // Set camera manipulator with default home position
  osgEarth::Util::EarthManipulator* manip = new osgEarth::Util::EarthManipulator();
  mOsgViewer->setCameraManipulator( manip );
  osgEarth::Util::Viewpoint viewpoint;
  viewpoint.focalPoint() = osgEarth::GeoPoint( osgEarth::SpatialReference::get( "wgs84" ), -90., 0., 0. );
  viewpoint.heading() = 0.;
  viewpoint.pitch() = -90.;
  viewpoint.range() = 2e7;

  manip->setHomeViewpoint( viewpoint, 1. );
  manip->home( 0 );

  setupProxy();

  // Tile stats label
#ifdef GLOBE_SHOW_TILE_STATS
  mStatsLabel = new osgEarth::Util::Controls::LabelControl( "", 10 );
  mStatsLabel->setPosition( 0, 0 );
  osgEarth::Util::Controls::ControlCanvas::get( mOsgViewer )->addControl( mStatsLabel.get() );
#endif

  mDockWidget = new QgsGlobeWidget( mQGisIface, mQGisIface->mainWindow() );
  connect( mDockWidget, SIGNAL( destroyed( QObject* ) ), this, SLOT( reset() ) );
  connect( mDockWidget, SIGNAL( layersChanged() ), this, SLOT( updateLayers() ) );
  connect( mDockWidget, SIGNAL( showSettings() ), this, SLOT( showSettings() ) );
  connect( mDockWidget, SIGNAL( refresh() ), this, SLOT( updateLayers() ) );
  connect( mDockWidget, SIGNAL( syncExtent() ), this, SLOT( syncExtent() ) );
  mQGisIface->addDockWidget( Qt::RightDockWidgetArea, mDockWidget );

  if ( getenv( "GLOBE_MAPXML" ) )
  {
    char* mapxml = getenv( "GLOBE_MAPXML" );
    QgsDebugMsg( mapxml );
    osg::Node* node = osgDB::readNodeFile( mapxml );
    if ( !node )
    {
      QgsDebugMsg( "Failed to load earth file " );
      return;
    }
    mMapNode = osgEarth::MapNode::findMapNode( node );
    mRootNode = new osg::Group();
    mRootNode->addChild( node );
  }
  else
  {
    QString cacheDirectory = settings.value( "cache/directory", QgsApplication::qgisSettingsDirPath() + "cache" ).toString();
    osgEarth::Drivers::FileSystemCacheOptions cacheOptions;
    cacheOptions.rootPath() = cacheDirectory.toStdString();

    osgEarth::MapOptions mapOptions;
    mapOptions.cache() = cacheOptions;
    osgEarth::Map *map = new osgEarth::Map( /*mapOptions*/ );

    // The MapNode will render the Map object in the scene graph.
    osgEarth::MapNodeOptions mapNodeOptions;
    mMapNode = new osgEarth::MapNode( map, mapNodeOptions );

    mRootNode = new osg::Group();
    mRootNode->addChild( mMapNode );

    osgEarth::Registry::instance()->unRefImageDataAfterApply() = false;

    // Add draped layer
    osgEarth::TileSourceOptions opts;
    opts.L2CacheSize() = 0;
    opts.tileSize() = 128;
    mTileSource = new QgsGlobeTileSource( mQGisIface->mapCanvas(), opts );

    osgEarth::ImageLayerOptions options( "QGIS" );
    options.driver()->L2CacheSize() = 0;
    options.cachePolicy() = osgEarth::CachePolicy::USAGE_NO_CACHE;
    mQgisMapLayer = new osgEarth::ImageLayer( options, mTileSource );
    map->addImageLayer( mQgisMapLayer );

    // Add layers to the map
    updateLayers();

    // Create the frustum highlight callback
    mFrustumHighlightCallback = new QgsGlobeFrustumHighlightCallback(
      mOsgViewer, mMapNode->getTerrain(), mQGisIface->mapCanvas(), QColor( 0, 0, 0, 50 ) );
  }

  mRootNode->addChild( osgEarth::Util::Controls::ControlCanvas::get( mOsgViewer ) );

  mAnnotationsGroup = new osg::Group();
  mRootNode->addChild( mAnnotationsGroup );
  foreach ( QgsBillBoardItem* item, QgsProject::instance()->billboardRegistry()->items() )
  {
    addBillboard( item );
  }