void TerrainProfileCalculator::computeTerrainProfile( osgEarth::MapNode* mapNode, const GeoPoint& start, const GeoPoint& end, unsigned int numSamples, TerrainProfile& profile) { GeoPoint geoStart(start); geoStart.makeGeographic(); GeoPoint geoEnd(end); geoEnd.makeGeographic(); double startXRad = osg::DegreesToRadians( geoStart.x() ); double startYRad = osg::DegreesToRadians( geoStart.y() ); double endXRad = osg::DegreesToRadians( geoEnd.x() ); double endYRad = osg::DegreesToRadians( geoEnd.y() ); double distance = osgEarth::GeoMath::distance(startYRad, startXRad, endYRad, endXRad ); double spacing = distance / ((double)numSamples - 1.0); profile.clear(); for (unsigned int i = 0; i < numSamples; i++) { double t = (double)i / (double)numSamples; double lat, lon; GeoMath::interpolate( startYRad, startXRad, endYRad, endXRad, t, lat, lon ); double hamsl; mapNode->getTerrain()->getHeight( osg::RadiansToDegrees(lon), osg::RadiansToDegrees(lat), &hamsl ); profile.addElevation( spacing * (double)i, hamsl ); } }
void TerrainProfileCalculator::computeTerrainProfile( osgEarth::MapNode* mapNode, const GeoPoint& start, const GeoPoint& end, TerrainProfile& profile) { osg::Vec3d startvec, endvec; start.toWorld( startvec, mapNode->getTerrain() ); end.toWorld( endvec, mapNode->getTerrain() ); osgSim::ElevationSlice slice; slice.setStartPoint( startvec ); slice.setEndPoint( endvec ); slice.setDatabaseCacheReadCallback( 0 ); slice.computeIntersections( mapNode->getTerrainEngine()); profile.clear(); for (unsigned int i = 0; i < slice.getDistanceHeightIntersections().size(); i++) { profile.addElevation( slice.getDistanceHeightIntersections()[i].first, slice.getDistanceHeightIntersections()[i].second); } }