Changeset 5775 for geovis/trunk/Renderer.cpp
- Timestamp:
- Jul 24, 2015, 5:37:02 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/Renderer.cpp
r5152 r5775 47 47 #include <osgEarth/ModelLayer> 48 48 #include <osgEarth/DateTime> 49 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0) 50 #include <osgEarth/IntersectionPicker> 51 #else 49 52 #include <osgEarth/Pickers> 53 #endif 50 54 #include <osgEarthFeatures/Feature> 51 55 #include <osgEarthSymbology/Color> … … 88 92 #include "FileUtil.h" 89 93 #include "Trace.h" 94 95 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 6, 1) 96 #define NEW_VIEWPOINT_API 97 #endif 90 98 91 99 #define MSECS_ELAPSED(t1, t2) \ … … 452 460 void Renderer::setAttribution(const std::string& attrib) 453 461 { 462 TRACE("Setting map attribution: '%s'", attrib.c_str()); 454 463 _attribution = attrib; 455 464 if (_copyrightLabel.valid()) { … … 1000 1009 if (_manipulator.valid()) { 1001 1010 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 1003 1020 _manipulator->setViewpoint(v, durationSecs); 1004 1021 _needsRedraw = true; … … 1614 1631 initAnnotations(); 1615 1632 1616 const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS();1633 const osgEarth::SpatialReference *geoSRS = _mapNode->getMapSRS()->getGeographicSRS(); 1617 1634 1618 1635 osgEarth::Symbology::Style pin; … … 1682 1699 } 1683 1700 #endif 1701 #if OSGEARTH_MIN_VERSION_REQUIRED(2, 7, 0) 1684 1702 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1685 1703 { … … 1688 1706 return; 1689 1707 } 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 1750 void 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 1792 void Renderer::hoverPlaceNode(int x, int y, bool invertY) 1793 { 1794 if (!_placeNodes.valid()) { 1795 TRACE("No place nodes"); 1796 return; 1797 } 1798 1690 1799 osgEarth::Picker picker(_viewer.get(), _sceneRoot.get());//_placeNodes.get()); 1691 1800 osgEarth::Picker::Hits hits; … … 1770 1879 #endif 1771 1880 } 1772 1881 #endif 1773 1882 void Renderer::addModelLayer(const char *name, osgEarth::ModelSourceOptions& opts) 1774 1883 {
Note: See TracChangeset
for help on using the changeset viewer.