Added a MatrixTransform set up to provide a local origin for better precision.

This commit is contained in:
Robert Osfield 2007-04-29 20:10:43 +00:00
parent 921eb0fdd0
commit aa56bddefc
2 changed files with 19 additions and 6 deletions

View File

@ -14,6 +14,7 @@
#ifndef OSGTERRAIN_GEOMETRYTECHNIQUE
#define OSGTERRAIN_GEOMETRYTECHNIQUE 1
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/Geometry>
@ -110,10 +111,11 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
virtual ~GeometryTechnique();
osg::ref_ptr<osg::Geode> _geode;
osg::ref_ptr<osg::MatrixTransform> _transform;
osg::ref_ptr<osg::Geode> _geode;
osg::ref_ptr<TerrainGeometry> _terrainGeometry;
osg::ref_ptr<osg::Geometry> _geometry;
osg::ref_ptr<TerrainGeometry> _terrainGeometry;
osg::ref_ptr<osg::Geometry> _geometry;
};
}

View File

@ -107,8 +107,19 @@ void GeometryTechnique::init()
osg::notify(osg::NOTICE)<<"bottomLeftNDC = "<<bottomLeftNDC<<std::endl;
osg::notify(osg::NOTICE)<<"topRightNDC = "<<topRightNDC<<std::endl;
_geode = new osg::Geode;
_transform = new osg::MatrixTransform;
_transform->addChild(_geode.get());
osg::Vec3d centerNDC = (bottomLeftNDC + topRightNDC)*0.5;
osg::Vec3d centerModel = (bottomLeftNDC + topRightNDC)*0.5;
masterLocator->convertLocalToModel(centerNDC, centerModel);
_transform->setMatrix(osg::Matrix::translate(centerModel));
_terrainGeometry = 0; // new osgTerrain::TerrainGeometry;
if (_terrainGeometry.valid()) _geode->addDrawable(_terrainGeometry.get());
@ -213,7 +224,7 @@ void GeometryTechnique::init()
osg::Vec3d model;
masterLocator->convertLocalToModel(ndc, model);
(*_vertices)[iv] = model;
(*_vertices)[iv] = model - centerModel;
if (colorLayer)
{
@ -363,9 +374,9 @@ void GeometryTechnique::update(osgUtil::UpdateVisitor* nv)
void GeometryTechnique::cull(osgUtil::CullVisitor* nv)
{
if (_geode.valid())
if (_transform.valid())
{
_geode->accept(*nv);
_transform->accept(*nv);
}
}