Cleaned up osgTerrain, renaming the Terrain and Renderer class to
HeightFieldNode and HeightFieldRender to better reflect their function. Removed the GeoMipMapRenderer.cpp stub as the implemention will be left to a plugin. Added Version functions.
This commit is contained in:
@@ -1,49 +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_GEOMIPMAPRENDERER
|
||||
#define OSGTERRAIN_GEOMIPMAPRENDERER 1
|
||||
|
||||
#include <osgTerrain/Renderer>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
class OSGTERRAIN_EXPORT GeoMipMapRenderer : public Renderer
|
||||
{
|
||||
public:
|
||||
|
||||
GeoMipMapRenderer();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
GeoMipMapRenderer(const GeoMipMapRenderer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgTerrain,GeoMipMapRenderer)
|
||||
|
||||
virtual void initialize();
|
||||
|
||||
virtual void terrainHasBeenModified();
|
||||
|
||||
virtual void update(osgUtil::UpdateVisitor* nv);
|
||||
|
||||
virtual void cull(osgUtil::CullVisitor* nv);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~GeoMipMapRenderer();
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
101
include/osgTerrain/HeightFieldNode
Normal file
101
include/osgTerrain/HeightFieldNode
Normal file
@@ -0,0 +1,101 @@
|
||||
/* -*-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_HEIGHTFIELDNODE
|
||||
#define OSGTERRAIN_HEIGHTFIELDNODE 1
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/Image>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
#include <osgTerrain/HeightFieldRenderer>
|
||||
|
||||
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 HeightFieldNode : public osg::Group
|
||||
{
|
||||
public:
|
||||
|
||||
HeightFieldNode();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
HeightFieldNode(const HeightFieldNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osgTerrain, HeightFieldNode);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
/** Set the HeightField for this HeightFieldNode.
|
||||
* 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 heightFieldHasBeenModified();
|
||||
|
||||
/** Set the Renderer*/
|
||||
void setRenderer(osgTerrain::HeightFieldRenderer* renderer);
|
||||
|
||||
/** Get the Renderer*/
|
||||
HeightFieldRenderer* getRenderer() { return _renderer.get(); }
|
||||
|
||||
/** Get the const Renderer*/
|
||||
const HeightFieldRenderer* 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 ~HeightFieldNode();
|
||||
|
||||
|
||||
osg::ref_ptr<osg::HeightField> _heightField;
|
||||
osg::ref_ptr<HeightFieldRenderer> _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
|
||||
@@ -11,8 +11,8 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGTERRAIN_Renderer
|
||||
#define OSGTERRAIN_Renderer 1
|
||||
#ifndef OSGTERRAIN_HEIGHTFIELDHeightFieldRenderer
|
||||
#define OSGTERRAIN_HEIGHTFIELDHeightFieldRenderer 1
|
||||
|
||||
#include <osg/Object>
|
||||
|
||||
@@ -23,23 +23,23 @@
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
class Terrain;
|
||||
class HeightFieldNode;
|
||||
|
||||
class OSGTERRAIN_EXPORT Renderer : public osg::Object
|
||||
class OSGTERRAIN_EXPORT HeightFieldRenderer : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
Renderer();
|
||||
HeightFieldRenderer();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Renderer(const Renderer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
HeightFieldRenderer(const HeightFieldRenderer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
Terrain* getTerrain() { return _terrain; }
|
||||
const Terrain* getTerrain() const { return _terrain; }
|
||||
HeightFieldNode* getHeightFieldNode() { return _heightFieldNode; }
|
||||
const HeightFieldNode* getHeightFieldNode() const { return _heightFieldNode; }
|
||||
|
||||
virtual void initialize() = 0;
|
||||
|
||||
virtual void terrainHasBeenModified() = 0;
|
||||
virtual void heightFieldHasBeenModified() = 0;
|
||||
|
||||
virtual void update(osgUtil::UpdateVisitor* nv) = 0;
|
||||
|
||||
@@ -47,11 +47,11 @@ class OSGTERRAIN_EXPORT Renderer : public osg::Object
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Renderer();
|
||||
virtual ~HeightFieldRenderer();
|
||||
|
||||
friend class osgTerrain::Terrain;
|
||||
friend class osgTerrain::HeightFieldNode;
|
||||
|
||||
Terrain* _terrain;
|
||||
HeightFieldNode* _heightFieldNode;
|
||||
|
||||
};
|
||||
|
||||
46
include/osgTerrain/Version
Normal file
46
include/osgTerrain/Version
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*-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_VERSION
|
||||
#define OSGTERRAIN_VERSION 1
|
||||
|
||||
#include <osgTerrain/Export>
|
||||
|
||||
extern "C" {
|
||||
|
||||
/**
|
||||
* osgTerrainGetVersion() returns the library version number.
|
||||
* Numbering convention : OpenSceneGraph-0.1 will return 0.1 from osgTerraingetVersion.
|
||||
*
|
||||
* This C function can be also used to check for the existence of the OpenSceneGraph
|
||||
* library using autoconf and its m4 macro AC_CHECK_LIB.
|
||||
*
|
||||
* Here is the code to add to your configure.in:
|
||||
\verbatim
|
||||
#
|
||||
# Check for the OpenSceneGraph Terrain library
|
||||
#
|
||||
AC_CHECK_LIB(osg, osgTerrainGetVersion, ,
|
||||
[AC_MSG_ERROR(OpenSceneGraph Terrain library not found. See http://www.openscenegraph.org)],)
|
||||
\endverbatim
|
||||
*/
|
||||
extern OSGTERRAIN_EXPORT const char* osgTerrainGetVersion();
|
||||
|
||||
/**
|
||||
* osgTerrainGetLibraryName() returns the library name in human friendly form.
|
||||
*/
|
||||
extern OSGTERRAIN_EXPORT const char* osgTerrainGetLibraryName();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -4,9 +4,9 @@ include $(TOPDIR)/Make/makedefs
|
||||
|
||||
CXXFILES = \
|
||||
DataSet.cpp\
|
||||
Terrain.cpp\
|
||||
Renderer.cpp\
|
||||
GeoMipMapRenderer.cpp\
|
||||
HeightFieldNode.cpp\
|
||||
HeightFieldRenderer.cpp\
|
||||
Version.cpp\
|
||||
|
||||
|
||||
DEF += -DOSGTERRAIN_LIBRARY
|
||||
|
||||
@@ -1,49 +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/GeoMipMapRenderer>
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
GeoMipMapRenderer::GeoMipMapRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
GeoMipMapRenderer::GeoMipMapRenderer(const GeoMipMapRenderer& renderer,const osg::CopyOp& copyop):
|
||||
Renderer(renderer,copyop)
|
||||
{
|
||||
}
|
||||
|
||||
GeoMipMapRenderer::~GeoMipMapRenderer()
|
||||
{
|
||||
}
|
||||
|
||||
void GeoMipMapRenderer::initialize()
|
||||
{
|
||||
}
|
||||
|
||||
void GeoMipMapRenderer::terrainHasBeenModified()
|
||||
{
|
||||
}
|
||||
|
||||
void GeoMipMapRenderer::update(osgUtil::UpdateVisitor* nv)
|
||||
{
|
||||
if (getTerrain()) nv->traverse(*getTerrain());
|
||||
}
|
||||
|
||||
void GeoMipMapRenderer::cull(osgUtil::CullVisitor* nv)
|
||||
{
|
||||
if (getTerrain()) getTerrain()->osg::Group::traverse(*nv);
|
||||
}
|
||||
108
src/osgTerrain/HeightFieldNode.cpp
Normal file
108
src/osgTerrain/HeightFieldNode.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* -*-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/HeightFieldNode>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
HeightFieldNode::HeightFieldNode()
|
||||
{
|
||||
setNumChildrenRequiringUpdateTraversal(1);
|
||||
}
|
||||
|
||||
HeightFieldNode::HeightFieldNode(const HeightFieldNode& terrain,const osg::CopyOp& copyop):
|
||||
Group(terrain,copyop),
|
||||
_heightField(terrain._heightField)
|
||||
{
|
||||
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||
if (terrain.getRenderer()) setRenderer(dynamic_cast<HeightFieldRenderer*>(terrain.getRenderer()->cloneType()));
|
||||
}
|
||||
|
||||
HeightFieldNode::~HeightFieldNode()
|
||||
{
|
||||
}
|
||||
|
||||
void HeightFieldNode::traverse(osg::NodeVisitor& nv)
|
||||
{
|
||||
// if app traversal update the frame count.
|
||||
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||
{
|
||||
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 HeightFieldNode::setHeightField(osg::HeightField* heightField)
|
||||
{
|
||||
_heightField = heightField;
|
||||
if (_renderer.valid()) _renderer->initialize();
|
||||
}
|
||||
|
||||
void HeightFieldNode::heightFieldHasBeenModified()
|
||||
{
|
||||
if (_renderer.valid()) _renderer->heightFieldHasBeenModified();
|
||||
}
|
||||
|
||||
void HeightFieldNode::setRenderer(osgTerrain::HeightFieldRenderer* 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->_heightFieldNode = this;
|
||||
_renderer->initialize();
|
||||
}
|
||||
}
|
||||
|
||||
void HeightFieldNode::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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,21 +11,21 @@
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osgTerrain/Renderer>
|
||||
#include <osgTerrain/HeightFieldRenderer>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
Renderer::Renderer():
|
||||
_terrain(0)
|
||||
HeightFieldRenderer::HeightFieldRenderer():
|
||||
_heightFieldNode(0)
|
||||
{
|
||||
}
|
||||
|
||||
Renderer::Renderer(const Renderer& renderer,const osg::CopyOp& copyop):
|
||||
osg::Object(renderer,copyop),
|
||||
_terrain(0)
|
||||
HeightFieldRenderer::HeightFieldRenderer(const HeightFieldRenderer& HeightFieldRenderer,const osg::CopyOp& copyop):
|
||||
osg::Object(HeightFieldRenderer,copyop),
|
||||
_heightFieldNode(0)
|
||||
{
|
||||
}
|
||||
|
||||
Renderer::~Renderer()
|
||||
HeightFieldRenderer::~HeightFieldRenderer()
|
||||
{
|
||||
}
|
||||
12
src/osgTerrain/Version.cpp
Normal file
12
src/osgTerrain/Version.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <osgTerrain/Version>
|
||||
|
||||
const char* osgTerrainGetVersion()
|
||||
{
|
||||
return "0.9.6";
|
||||
}
|
||||
|
||||
|
||||
const char* osgTerrainGetLibraryName()
|
||||
{
|
||||
return "Open Scene Graph Terrain Library";
|
||||
}
|
||||
Reference in New Issue
Block a user