From 2d72bf4308f14c8f8125d10442cf30957e0fe201 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Sun, 20 Jan 2013 15:33:25 +0100 Subject: [PATCH] spt: Put the sea level textured tiles also under a transform node. --- simgear/scene/tgdb/ReaderWriterSPT.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/simgear/scene/tgdb/ReaderWriterSPT.cxx b/simgear/scene/tgdb/ReaderWriterSPT.cxx index e5e41a4a..2c0faba7 100644 --- a/simgear/scene/tgdb/ReaderWriterSPT.cxx +++ b/simgear/scene/tgdb/ReaderWriterSPT.cxx @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -269,6 +270,10 @@ ReaderWriterSPT::createSeaLevelTile(const BucketBox& bucketBox, const osgDB::Opt if (options->getPluginStringData("SimGear::FG_EARTH") != "ON") return 0; + SGSpheref sphere = bucketBox.getBoundingSphere(); + osg::Matrixd transform; + transform.makeTranslate(toOsg(-sphere.getCenter())); + osg::Vec3Array* vertices = new osg::Vec3Array; osg::Vec3Array* normals = new osg::Vec3Array; osg::Vec2Array* texCoords = new osg::Vec2Array; @@ -286,7 +291,7 @@ ReaderWriterSPT::createSeaLevelTile(const BucketBox& bucketBox, const osgDB::Opt SGVec2f t[6]; unsigned num = bucketBox.getTileTriangles(i, j, incx, incy, v, n, t); for (unsigned k = 0; k < num; ++k) { - vertices->push_back(toOsg(v[k])); + vertices->push_back(transform.preMult(toOsg(v[k]))); normals->push_back(toOsg(n[k])); texCoords->push_back(toOsg(t[k])); } @@ -308,14 +313,22 @@ ReaderWriterSPT::createSeaLevelTile(const BucketBox& bucketBox, const osgDB::Opt geometry->setColorBinding(osg::Geometry::BIND_OVERALL); geometry->setTexCoordArray(0, texCoords); - geometry->addPrimitiveSet(new osg::DrawArrays(osg::DrawArrays::TRIANGLES, 0, vertices->size())); + osg::DrawArrays* drawArrays = new osg::DrawArrays(osg::DrawArrays::TRIANGLES, 0, vertices->size()); + drawArrays->setDataVariance(osg::Object::STATIC); + geometry->addPrimitiveSet(drawArrays); osg::Geode* geode = new osg::Geode; + geode->setDataVariance(osg::Object::STATIC); geode->addDrawable(geometry); osg::ref_ptr stateSet = getLowLODStateSet(options); geode->setStateSet(stateSet.get()); - return geode; + transform.makeTranslate(toOsg(sphere.getCenter())); + osg::MatrixTransform* matrixTransform = new osg::MatrixTransform(transform); + matrixTransform->setDataVariance(osg::Object::STATIC); + matrixTransform->addChild(geode); + + return matrixTransform; } osg::ref_ptr