#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class MyLocator : public osgTerrain::Locator { public: MyLocator(double x, double y, double width, double height): _x(x), _y(y), _width(width), _height(height) {} bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) { world.x() = _x + local.x()*_width; world.y() = _y + local.y()*_height; world.z() = _z + local.z(); return true; } bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) { local.x() = (world.x()- _x) / _width; local.y() = (world.y() - _y) / _height; local.z() = world.z() - _z; return true; } double _x; double _y; double _z; double _width; double _height; }; int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); // construct the viewer. osgViewer::Viewer viewer; double x = 0.0; double y = 0.0; double w = 1.0; double h = 1.0; osg::ref_ptr terrain = new osgTerrain::TerrainNode; osg::ref_ptr locator = new MyLocator(0.0, 0.0, 1.0, 1.0); bool readParameter = false; do { readParameter = false; std::string filename; if (arguments.read("-l",x,y,w,h)) { locator = new MyLocator(x,y,w,h); readParameter = true; } if (arguments.read("--hf",filename)) { readParameter = true; osg::notify(osg::NOTICE)<<"--hf "< geometryTechnique = new osgTerrain::GeometryTechnique; terrain->setTerrainTechnique(geometryTechnique.get()); if (!terrain) return 0; return 0; // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(terrain.get()); return viewer.run(); }