From 1cdda0654fbd056e676b802c43e728049d0020a0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 26 Mar 2007 15:52:22 +0000 Subject: [PATCH] Added Locator and layer setting to osgterrain example --- examples/osgterrain/osgterrain.cpp | 113 +++++++++++++++++++++++++++-- include/osgTerrain/Layer | 3 + include/osgTerrain/Locator | 6 +- src/osgViewer/CMakeLists.txt | 10 +-- 4 files changed, 118 insertions(+), 14 deletions(-) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 3d4d66e88..f1a37c65a 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -22,6 +22,43 @@ #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); @@ -35,6 +72,8 @@ int main(int argc, char** argv) 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 @@ -42,21 +81,79 @@ int main(int argc, char** argv) readParameter = false; std::string filename; - if (arguments.read("-x",x)) readParameter = true; - if (arguments.read("-y",y)) readParameter = true; - if (arguments.read("-w",w)) readParameter = true; - if (arguments.read("-h",h)) readParameter = true; + if (arguments.read("-l",x,y,w,h)) + { + locator = new MyLocator(x,y,w,h); + readParameter = true; + } - if (arguments.read("--dem",filename)) + if (arguments.read("--hf",filename)) { readParameter = true; - osg::notify(osg::NOTICE)<<"--dem "<setTerrainTechnique(geometryTechnique.get()); if (!terrain) return 0; + + return 0; // add a viewport to the viewer and attach the scene graph. viewer.setSceneData(terrain.get()); diff --git a/include/osgTerrain/Layer b/include/osgTerrain/Layer index 0a2111c53..39bf2ae92 100644 --- a/include/osgTerrain/Layer +++ b/include/osgTerrain/Layer @@ -31,6 +31,9 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ Layer(const Layer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); + META_Object(osgTerrain, Layer); + + void setLocator(Locator* locator) { _locator = locator; } Locator* getLocator() { return _locator.get(); } diff --git a/include/osgTerrain/Locator b/include/osgTerrain/Locator index d7dadc02a..6f88e188d 100644 --- a/include/osgTerrain/Locator +++ b/include/osgTerrain/Locator @@ -30,8 +30,10 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ Locator(const Locator&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); - virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) = 0; - virtual bool convertModelToWorld(const osg::Vec3d& local, osg::Vec3d& world) = 0; + META_Object(osgTerrain, Locator); + + virtual bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) {}; + virtual bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) {}; protected: diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 65990ae45..1fce66f32 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -79,12 +79,12 @@ LINK_INTERNAL(${LIB_NAME} osgUtil osg ) + LINK_CORELIB_DEFAULT(${LIB_NAME}) -IF(MINGW) - LINK_EXTERNAL(${LIB_NAME} - gdi32 - ) -ENDIF(MINGW) +IF(MINGW OR CYGWIN) + LINK_EXTERNAL(${LIB_NAME} gdi32 ) +ENDIF(MINGW OR CYGWIN) + INCLUDE(ModuleInstall OPTIONAL)