Removed Terrain.cpp and header from CVS repository.
Added support for setting the maximum visiable distance of top level to osgTerrain::DataSet, and debugging code which insert a axes.osg above each tile.
This commit is contained in:
@@ -844,6 +844,9 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
|
||||
|
||||
void loadSources();
|
||||
|
||||
void setMaximumVisibleDistanceOfTopLevel(float d) { _maximumVisiableDistanceOfTopLevel = d; }
|
||||
float getMaximumVisibleDistanceOfTopLevel() const { return _maximumVisiableDistanceOfTopLevel; }
|
||||
|
||||
void setRadiusToMaxVisibleDistanceRatio(float ratio) { _radiusToMaxVisibleDistanceRatio = ratio; }
|
||||
float getRadiusToMaxVisibleDistanceRatio() const { return _radiusToMaxVisibleDistanceRatio; }
|
||||
|
||||
@@ -954,6 +957,7 @@ class OSGTERRAIN_EXPORT DataSet : public osg::Referenced
|
||||
QuadMap _quadMap;
|
||||
|
||||
|
||||
float _maximumVisiableDistanceOfTopLevel;
|
||||
float _radiusToMaxVisibleDistanceRatio;
|
||||
float _verticalScale;
|
||||
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGTERRAIN_TERRAIN
|
||||
#define OSGTERRAIN_TERRAIN 1
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/Image>
|
||||
|
||||
#include <osgTerrain/Renderer>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
/** Terrain provides a framework for loosly coupling height field data with height rendering algorithms.
|
||||
* This allows renderer's to be pluged in at runtime.*/
|
||||
class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
{
|
||||
public:
|
||||
|
||||
Terrain();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osgTerrain, Terrain);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
/** Set the HeightField for this Terrain.
|
||||
* If a Renderer is attached then this will be notified.*/
|
||||
void setHeightField(osg::HeightField* heightField);
|
||||
|
||||
/** Get the HeightField.*/
|
||||
osg::HeightField* getHeightField() { return _heightField.get(); }
|
||||
|
||||
/** Get the const HeightField.*/
|
||||
const osg::HeightField* getHeightField() const { return _heightField.get(); }
|
||||
|
||||
/** Tell the Renderer that the height field has been modified, so
|
||||
* that any cached data will need updating*/
|
||||
void haveModifiedHeightField();
|
||||
|
||||
/** Set the Renderer*/
|
||||
void setRenderer(osgTerrain::Renderer* renderer);
|
||||
|
||||
/** Get the Renderer*/
|
||||
Renderer* getRenderer() { return _renderer.get(); }
|
||||
|
||||
/** Get the const Renderer*/
|
||||
const Renderer* getRenderer() const { return _renderer.get(); }
|
||||
|
||||
|
||||
void setBaseTextureImage(osg::Image* image) { _baseTextureImage = image; }
|
||||
osg::Image* getBaseTextureImage() { return _baseTextureImage.get(); }
|
||||
const osg::Image* getBaseTextureImage() const { return _baseTextureImage.get(); }
|
||||
|
||||
void setDetailTextureImage(osg::Image* image) { _detailTextureImage = image; }
|
||||
osg::Image* getDetailTextureImage() { return _detailTextureImage.get(); }
|
||||
const osg::Image* getDetailTextureImage() const { return _detailTextureImage.get(); }
|
||||
|
||||
void setCloudShadowTextureImage(osg::Image* image) { _cloudShadowTextureImage = image; }
|
||||
osg::Image* getCloudShadowTextureImage() { return _cloudShadowTextureImage.get(); }
|
||||
const osg::Image* getCloudShadowTextureImage() const { return _cloudShadowTextureImage.get(); }
|
||||
|
||||
void setNormalMapImage(osg::Image* image) { _normalMapImage = image ; }
|
||||
osg::Image* getNormalMapImage() { return _normalMapImage.get(); }
|
||||
const osg::Image* getNormalMapImage() const { return _normalMapImage.get(); }
|
||||
|
||||
void computeNormalMap();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Terrain();
|
||||
|
||||
|
||||
osg::ref_ptr<osg::HeightField> _heightField;
|
||||
osg::ref_ptr<Renderer> _renderer;
|
||||
|
||||
osg::ref_ptr<osg::Image> _baseTextureImage;
|
||||
osg::ref_ptr<osg::Image> _detailTextureImage;
|
||||
osg::ref_ptr<osg::Image> _cloudShadowTextureImage;
|
||||
osg::ref_ptr<osg::Image> _normalMapImage;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2360,6 +2360,17 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
|
||||
osg::MatrixTransform* mt = new osg::MatrixTransform;
|
||||
mt->setMatrix(localToWorld);
|
||||
mt->addChild(geode);
|
||||
|
||||
bool addLocalAxes = false;
|
||||
if (addLocalAxes)
|
||||
{
|
||||
float s = geode->getBound().radius()*0.5f;
|
||||
osg::MatrixTransform* scaleAxis = new osg::MatrixTransform;
|
||||
scaleAxis->setMatrix(osg::Matrix::scale(s,s,s));
|
||||
scaleAxis->addChild(osgDB::readNodeFile("axes.osg"));
|
||||
mt->addChild(scaleAxis);
|
||||
}
|
||||
|
||||
return mt;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
#include <osgTerrain/GeoMipMapRenderer>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
Terrain::Terrain()
|
||||
{
|
||||
setNumChildrenRequiringUpdateTraversal(1);
|
||||
}
|
||||
|
||||
Terrain::Terrain(const Terrain& terrain,const osg::CopyOp& copyop):
|
||||
Group(terrain,copyop),
|
||||
_heightField(terrain._heightField)
|
||||
{
|
||||
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
if (terrain.getRenderer()) setRenderer(dynamic_cast<Renderer*>(terrain.getRenderer()->cloneType()));
|
||||
}
|
||||
|
||||
Terrain::~Terrain()
|
||||
{
|
||||
}
|
||||
|
||||
void Terrain::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
// if app traversal update the frame count.
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
// if no renderer exists that default to using the GeoMipMapRenderer
|
||||
if (!getRenderer()) setRenderer(new GeoMipMapRenderer);
|
||||
|
||||
osgUtil::UpdateVisitor* uv = dynamic_cast<osgUtil::UpdateVisitor*>(&nv);
|
||||
if (getRenderer() && uv)
|
||||
{
|
||||
getRenderer()->update(uv);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR)
|
||||
{
|
||||
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(&nv);
|
||||
if (getRenderer() && cv)
|
||||
{
|
||||
getRenderer()->cull(cv);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise fallback to the Group::traverse()
|
||||
osg::Group::traverse(nv);
|
||||
}
|
||||
|
||||
void Terrain::setHeightField(osg::HeightField* heightField)
|
||||
{
|
||||
_heightField = heightField;
|
||||
if (_renderer.valid()) _renderer->initialize();
|
||||
}
|
||||
|
||||
void Terrain::haveModifiedHeightField()
|
||||
{
|
||||
if (_renderer.valid()) _renderer->terrainHasBeenModified();
|
||||
}
|
||||
|
||||
void Terrain::setRenderer(osgTerrain::Renderer* renderer)
|
||||
{
|
||||
// need to figure out how to ensure that only one renderer is
|
||||
// used between terrain nodes... issue a warning?
|
||||
_renderer = renderer;
|
||||
|
||||
if (_renderer.valid())
|
||||
{
|
||||
_renderer->_terrain = this;
|
||||
_renderer->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void Terrain::computeNormalMap()
|
||||
{
|
||||
if (_heightField.valid())
|
||||
{
|
||||
osg::Image* image = new osg::Image;
|
||||
image->allocateImage(_heightField->getNumColumns(),_heightField->getNumRows(),1,GL_RGB,GL_BYTE);
|
||||
|
||||
char* ptr = (char*) image->data();
|
||||
for(unsigned int r=0;r<_heightField->getNumRows();++r)
|
||||
{
|
||||
for(unsigned int c=0;c<_heightField->getNumColumns();++c)
|
||||
{
|
||||
osg::Vec3 normal = _heightField->getNormal(c,r);
|
||||
(*ptr++) = (char)((normal.x()+1.0)*0.5*255);
|
||||
(*ptr++) = (char)((normal.y()+1.0)*0.5*255);
|
||||
(*ptr++) = (char)((normal.z()+1.0)*0.5*255);
|
||||
}
|
||||
}
|
||||
|
||||
setNormalMapImage(image);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user