From John Vidar Larring, "Added vertical scale as a property of osgTerrain::Terrain. Lets you configure vertical scale when initializing the terrain model. E.g:

osgTerrain::Terrain* terrain = findTopMostNodeOfType<osgTerrain::Terrain>(model.get());
  if (!terrain)
  {
      terrain = new osgTerrain::Terrain;
      terrain->addChild(model.get());
      terrain->setVerticalScale(2.0f);
      model = terrain;
  }
  viewerWindow->setSceneData(model.get());
"
This commit is contained in:
Robert Osfield 2008-05-27 13:11:47 +00:00
parent b41404546e
commit 1519d0d546
3 changed files with 45 additions and 7 deletions

View File

@ -38,12 +38,26 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
/** Set the sample ratio hint that TerrainTile should use when building geometry.
* Defaults to 1.0, which means use all original sample points.*/
void setSampleRatio(float ratio) { _sampleRatio = ratio; }
void setSampleRatio(float ratio)
{
_sampleRatio = ratio;
dirtyRegisteredTiles();
}
/** Get the sample ratio hint.*/
float getSampleRatio() const { return _sampleRatio; }
/** Set the vertical scale hint.*/
void setVerticalScale(float scale)
{
_verticalScale = scale;
dirtyRegisteredTiles();
}
/** Get the vertical scale hint.*/
float getVerticalScale() const { return _verticalScale; }
/** Get the TerrainTile for a given TileID.*/
TerrainTile* getTile(const TileID& tileID);
@ -56,6 +70,8 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
friend class TerrainTile;
void dirtyRegisteredTiles();
void registerTerrainTile(TerrainTile* tile);
void unregisterTerrainTile(TerrainTile* tile);
@ -63,6 +79,7 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
typedef std::set< TerrainTile* > TerrainTileSet;
float _sampleRatio;
float _verticalScale;
mutable OpenThreads::Mutex _mutex;
TerrainTileSet _terrainTileSet;

View File

@ -278,7 +278,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
float minHeight = 0.0;
float scaleHeight = 1.0;
float scaleHeight = _terrainTile->getTerrain() ? _terrainTile->getTerrain()->getVerticalScale() : 1.0f;
// allocate and assign tex coords
typedef std::pair< osg::ref_ptr<osg::Vec2Array>, Locator* > TexCoordLocatorPair;
@ -341,7 +341,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
float value = 0.0f;
validValue = elevationLayer->getValidValue(i_equiv,j_equiv, value);
// osg::notify(osg::INFO)<<"i="<<i<<" j="<<j<<" z="<<value<<std::endl;
ndc.z() = value;
ndc.z() = value*scaleHeight;
}
if (validValue)
@ -373,7 +373,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
if (elevations.valid())
{
(*elevations).push_back((ndc.z()-minHeight)*scaleHeight);
(*elevations).push_back(ndc.z());
}
// compute the local normal

View File

@ -18,13 +18,15 @@ using namespace osg;
using namespace osgTerrain;
Terrain::Terrain():
_sampleRatio(1.0)
_sampleRatio(1.0),
_verticalScale(1.0)
{
}
Terrain::Terrain(const Terrain& ts, const osg::CopyOp& copyop):
osg::Group(ts,copyop),
_sampleRatio(ts._sampleRatio)
_sampleRatio(ts._sampleRatio),
_verticalScale(ts._verticalScale)
{
}
@ -69,6 +71,25 @@ const TerrainTile* Terrain::getTile(const TileID& tileID) const
return itr->second;
}
void Terrain::dirtyRegisteredTiles()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
for(TerrainTileSet::iterator itr = _terrainTileSet.begin();
itr != _terrainTileSet.end();
++itr)
{
TerrainTechnique* tt = const_cast<TerrainTile*>(*itr)->getTerrainTechnique();
if(tt)
{
tt->dirty();
// Force recreation of Geometry
// const_cast<TerrainTile*>(*itr)->init();
}
}
}
static unsigned int s_maxNumTiles = 0;
void Terrain::registerTerrainTile(TerrainTile* tile)
{