Ignore:
Timestamp:
Jul 24, 2015, 5:37:02 PM (9 years ago)
Author:
ldelgass
Message:

Add alignment param for label layer. Fixes for osgearth 2.7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Renderer.cpp

    r5152 r5775  
    4747#include <osgEarth/ModelLayer>
    4848#include <osgEarth/DateTime>
     49#if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0)
     50#include <osgEarth/IntersectionPicker>
     51#else
    4952#include <osgEarth/Pickers>
     53#endif
    5054#include <osgEarthFeatures/Feature>
    5155#include <osgEarthSymbology/Color>
     
    8892#include "FileUtil.h"
    8993#include "Trace.h"
     94
     95#if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1)
     96#define NEW_VIEWPOINT_API
     97#endif
    9098
    9199#define MSECS_ELAPSED(t1, t2) \
     
    452460void Renderer::setAttribution(const std::string& attrib)
    453461{
     462    TRACE("Setting map attribution: '%s'", attrib.c_str());
    454463    _attribution = attrib;
    455464    if (_copyrightLabel.valid()) {
     
    10001009    if (_manipulator.valid()) {
    10011010        TRACE("Setting viewpoint: %g %g %g %g %g %g",
    1002               v.x(), v.y(), v.z(), v.getHeading(), v.getPitch(), v.getRange());
     1011#ifdef NEW_VIEWPOINT_API
     1012              v.focalPoint()->x(), v.focalPoint()->y(), v.focalPoint()->z(),
     1013              v.heading()->as(osgEarth::Units::DEGREES),
     1014              v.pitch()->as(osgEarth::Units::DEGREES),
     1015              v.range()->as(osgEarth::Units::METERS));
     1016#else
     1017              v.x(), v.y(), v.z(),
     1018              v.getHeading(), v.getPitch(), v.getRange());
     1019#endif
    10031020        _manipulator->setViewpoint(v, durationSecs);
    10041021        _needsRedraw = true;
     
    16141631    initAnnotations();
    16151632
    1616     const osgEarth::SpatialReference* geoSRS = _mapNode->getMapSRS()->getGeographicSRS();
     1633    const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS();
    16171634
    16181635    osgEarth::Symbology::Style pin;
     
    16821699}
    16831700#endif
     1701#if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0)
    16841702void Renderer::hoverPlaceNode(int x, int y, bool invertY)
    16851703{
     
    16881706        return;
    16891707    }
     1708
     1709    osgEarth::IntersectionPicker picker(_viewer.get(), _sceneRoot.get());
     1710    osgEarth::IntersectionPicker::Hits hits;
     1711    float mouseX = (float)x;
     1712    float mouseY = (float)y;
     1713    if (invertY) {
     1714        mouseY = ((float)_windowHeight - mouseY);
     1715    }
     1716    std::set<osgEarth::Annotation::AnnotationNode*> toUnHover;
     1717    for (std::set<osgEarth::Annotation::AnnotationNode*>::iterator itr = _hovered.begin();
     1718         itr != _hovered.end(); ++itr) {
     1719        toUnHover.insert(*itr);
     1720    }
     1721    if (picker.pick(mouseX, mouseY, hits)) {
     1722        TRACE("Picker hits: %d", hits.size());
     1723        for (osgEarth::IntersectionPicker::Hits::const_iterator hitr = hits.begin();
     1724             hitr != hits.end(); ++hitr) {
     1725            TRACE("Hit: node %p drawable %p idx %d", picker.getNode<osg::Node>(*hitr), hitr->drawable.get(), hitr->primitiveIndex);
     1726            osgEarth::Annotation::AnnotationNode *anno =
     1727                picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr);
     1728            if (anno != NULL && anno->getDecoration().empty()) {
     1729                TRACE("Hit AnnotationNode: %p", anno);
     1730                if (_hovered.find(anno) == _hovered.end()) {
     1731                    _hovered.insert(anno);
     1732                    anno->setDecoration("hover");
     1733                    _needsRedraw = true;
     1734                }
     1735                toUnHover.erase(anno);
     1736            }
     1737        }
     1738#if 0
     1739        writeScene("/tmp/test.osgt");
     1740#endif
     1741    }
     1742    for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = toUnHover.begin();
     1743         itr != toUnHover.end(); ++itr) {
     1744        _hovered.erase(*itr);
     1745        (*itr)->clearDecoration();
     1746        _needsRedraw = true;
     1747    }
     1748}
     1749
     1750void Renderer::deletePlaceNode(int x, int y, bool invertY)
     1751{
     1752    if (!_placeNodes.valid()) {
     1753        TRACE("No place nodes");
     1754        return;
     1755    }
     1756    osgEarth::IntersectionPicker picker(_viewer.get(), _placeNodes.get());
     1757    osgEarth::IntersectionPicker::Hits hits;
     1758    float mouseX = (float)x;
     1759    float mouseY = (float)y;
     1760    if (invertY) {
     1761        mouseY = ((float)_windowHeight - mouseY);
     1762    }
     1763    if (picker.pick(mouseX, mouseY, hits)) {
     1764        TRACE("Picker hit!");
     1765        // prevent multiple hits on the same instance
     1766        std::set<osgEarth::Annotation::AnnotationNode *> fired;
     1767        for (osgEarth::IntersectionPicker::Hits::const_iterator hitr = hits.begin();
     1768             hitr != hits.end(); ++hitr) {
     1769            osgEarth::Annotation::AnnotationNode *anno =
     1770                picker.getNode<osgEarth::Annotation::AnnotationNode>(*hitr);
     1771            if (anno != NULL && fired.find(anno) == fired.end()) {
     1772                fired.insert(anno);
     1773                _needsRedraw = true;
     1774            }
     1775        }
     1776        for (std::set<osgEarth::Annotation::AnnotationNode *>::iterator itr = fired.begin();
     1777             itr != fired.end(); ++itr) {
     1778            (*itr)->clearDecoration();
     1779            _placeNodes->removeChild(*itr);
     1780            if (_hovered.find(*itr) != _hovered.end()) {
     1781                _hovered.erase(*itr);
     1782            }
     1783        }
     1784    } else {
     1785        TRACE("NO Picker hits");
     1786    }
     1787#if 0
     1788    writeScene("/tmp/test.osg");
     1789#endif
     1790}
     1791#else
     1792void Renderer::hoverPlaceNode(int x, int y, bool invertY)
     1793{
     1794    if (!_placeNodes.valid()) {
     1795        TRACE("No place nodes");
     1796        return;
     1797    }
     1798
    16901799    osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get());
    16911800    osgEarth::Picker::Hits hits;
     
    17701879#endif
    17711880}
    1772 
     1881#endif
    17731882void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts)
    17741883{
Note: See TracChangeset for help on using the changeset viewer.