From 9f63b89e6a5fb9c8f7d25693fbda587b95910833 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 14 Dec 2007 17:40:11 +0000 Subject: [PATCH] Refectored the loading of Locator out into its own separate file --- src/osgPlugins/osgTerrain/CMakeLists.txt | 1 + src/osgPlugins/osgTerrain/Locator.cpp | 158 +++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 src/osgPlugins/osgTerrain/Locator.cpp diff --git a/src/osgPlugins/osgTerrain/CMakeLists.txt b/src/osgPlugins/osgTerrain/CMakeLists.txt index 5a5d6889bf4..c3d75ad536b 100644 --- a/src/osgPlugins/osgTerrain/CMakeLists.txt +++ b/src/osgPlugins/osgTerrain/CMakeLists.txt @@ -2,6 +2,7 @@ SET(TARGET_SRC + Locator.cpp Terrain.cpp GeometryTechnique.cpp ReaderWriterOsgTerrain.cpp diff --git a/src/osgPlugins/osgTerrain/Locator.cpp b/src/osgPlugins/osgTerrain/Locator.cpp new file mode 100644 index 00000000000..50b056b1fab --- /dev/null +++ b/src/osgPlugins/osgTerrain/Locator.cpp @@ -0,0 +1,158 @@ +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +bool Locator_readLocalData(osg::Object &obj, osgDB::Input &fr); +bool Locator_writeLocalData(const osg::Object &obj, osgDB::Output &fw); + +osgDB::RegisterDotOsgWrapperProxy Locator_Proxy +( + new osgTerrain::Locator, + "Locator", + "Object Locator", + Locator_readLocalData, + Locator_writeLocalData +); + + +bool Locator_readLocalData(osg::Object& obj, osgDB::Input &fr) +{ + osgTerrain::Locator& locator = static_cast(obj); + + bool itrAdvanced = false; + + if (fr.matchSequence("Format %w") || fr.matchSequence("Format %s") ) + { + locator.setFormat(fr[1].getStr()); + + fr += 2; + itrAdvanced = true; + } + + if (fr.matchSequence("CoordinateSystemType %w")) + { + if (fr[1].matchWord("GEOCENTRIC")) locator.setCoordinateSystemType(osgTerrain::Locator::GEOCENTRIC); + else if (fr[1].matchWord("GEOGRAPHIC")) locator.setCoordinateSystemType(osgTerrain::Locator::GEOGRAPHIC); + else locator.setCoordinateSystemType(osgTerrain::Locator::PROJECTED); + + fr += 2; + itrAdvanced = true; + } + + if (fr.matchSequence("CoordinateSystem %w") || fr.matchSequence("CoordinateSystem %s") ) + { + locator.setCoordinateSystem(fr[1].getStr()); + + fr += 2; + itrAdvanced = true; + } + + if (fr.matchSequence("TransformScaledByResolution %w")) + { + locator.setTransformScaledByResolution(fr[1].matchWord("TRUE") || fr[1].matchWord("True") || fr[1].matchWord("true")); + fr += 2; + itrAdvanced = true; + } + + if (fr.matchSequence("Transform {")) + { + int tansform_entry = fr[0].getNoNestedBrackets(); + + fr += 2; + + int row=0; + int col=0; + double v; + osg::Matrixd matrix; + while (!fr.eof() && fr[0].getNoNestedBrackets()>tansform_entry) + { + if (fr[0].getFloat(v)) + { + matrix(row,col)=v; + ++col; + if (col>=4) + { + col = 0; + ++row; + } + ++fr; + } + else fr.advanceOverCurrentFieldOrBlock(); + } + + locator.setTransform(matrix); + + ++fr; + itrAdvanced = true; + } + + + if (fr.matchSequence("Extents %f %f %f %f")) + { + double minX,minY,maxX,maxY; + fr[1].getFloat(minX); + fr[2].getFloat(minY); + fr[3].getFloat(maxX); + fr[4].getFloat(maxY); + + locator.setTransformAsExtents(minX, minY, maxX, maxY); + + fr += 5; + itrAdvanced = true; + } + + return itrAdvanced; +} + +bool Locator_writeLocalData(const osg::Object& obj, osgDB::Output& fw) +{ + const osgTerrain::Locator& locator = static_cast(obj); + + if (!locator.getFormat().empty()) fw.indent()<<"Format "<