例子学习第一天
今天是2019年2.26,接下来的一段时间开始研究关于在osgEarth中地形整(压平)的事儿,最后的应用就是开路,在osgEarth地球的表面,比如山上能自动生成道路之类的。
首先看下例子的效果介绍
还是很酷炫的,羡慕啊,开始干吧。
好久没摸oe了,只能一点一点来,在vs2010中随便选了个例子cpp,这里选择的是
但是里面有好多用不上的代码(应该吧),先注销掉。上面一堆包含都没管,菜鸟一只,也分辨不出来,啥Handler都留着,没管。
#include <osgGA/StateSetManipulator>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgUtil/LineSegmentIntersector>
#include <osgEarth/MapNode>
#include <osgEarth/TerrainEngineNode>
#include <osgEarth/ElevationQuery>
#include <osgEarth/StringUtils>
#include <osgEarth/Terrain>
#include <osgEarth/VerticalDatum>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/Controls>
#include <osgEarthUtil/LatLongFormatter>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthAnnotation/PlaceNode>
#include <iomanip>
using namespace osgEarth;
using namespace osgEarth::Util;
using namespace osgEarth::Util::Controls;
using namespace osgEarth::Annotation;
static MapNode* s_mapNode = 0L;
static LabelControl* s_posLabel = 0L;
static LabelControl* s_vdaLabel = 0L;
static LabelControl* s_mslLabel = 0L;
static LabelControl* s_haeLabel = 0L;
static LabelControl* s_egm96Label = 0L;
static LabelControl* s_mapLabel = 0L;
static LabelControl* s_resLabel = 0L;
static PlaceNode* s_marker = 0L;
// An event handler that will print out the elevation at the clicked point
struct QueryElevationHandler : public osgGA::GUIEventHandler
{
QueryElevationHandler()
: _mouseDown( false ),
_terrain ( s_mapNode->getTerrain() ),
_query ( s_mapNode->getMap() )
{
_map = s_mapNode->getMap();
_query.setMaxTilesToCache(10);
_query.setFallBackOnNoData( false );
_path.push_back( s_mapNode->getTerrainEngine() );
}
void update( float x, float y, osgViewer::View* view )
{
bool yes = false;
// look under the mouse:
osg::Vec3d world;
osgUtil::LineSegmentIntersector::Intersections hits;
if ( view->computeIntersections(x, y, hits) )
{
world = hits.begin()->getWorldIntersectPoint();
// convert to map coords:
GeoPoint mapPoint;
mapPoint.fromWorld( _terrain->getSRS(), world );
// do an elevation query:
double query_resolution = 0; // max.
double out_hamsl = 0.0;
double out_resolution = 0.0;
bool ok = _query.getElevation(
mapPoint,
out_hamsl,
query_resolution,
&out_resolution );
if ( ok )
{
// convert to geodetic to get the HAE:
mapPoint.z() = out_hamsl;
GeoPoint mapPointGeodetic( s_mapNode->getMapSRS()->