Early development work on osgTerrain.
This commit is contained in:
53
src/osgTerrain/CoordinateSystem.cpp
Normal file
53
src/osgTerrain/CoordinateSystem.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*-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/CoordinateSystem>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
CoordinateSystem::CoordinateSystem()
|
||||
{
|
||||
}
|
||||
|
||||
CoordinateSystem::CoordinateSystem(const std::string& projectionRef):
|
||||
_projectionRef(projectionRef)
|
||||
{
|
||||
}
|
||||
|
||||
CoordinateSystem::CoordinateSystem(const CoordinateSystem& cs,const osg::CopyOp& copyop):
|
||||
Object(cs,copyop),
|
||||
_projectionRef(cs._projectionRef)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<CoordinateSystem::CoordinateTransformation>& getCoordinateTransformationPrototypePtr()
|
||||
{
|
||||
static osg::ref_ptr<CoordinateSystem::CoordinateTransformation> s_coordinateSystemPrototype;
|
||||
return s_coordinateSystemPrototype;
|
||||
}
|
||||
|
||||
|
||||
CoordinateSystem::CoordinateTransformation* CoordinateSystem::CoordinateTransformation::createCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination)
|
||||
{
|
||||
if (getCoordinateTransformationPrototypePtr().valid())
|
||||
{
|
||||
getCoordinateTransformationPrototypePtr()->cloneCoordinateTransformation(source, destination);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
void CoordinateSystem::CoordinateTransformation::setCoordinateTransformationPrototpe(CoordinateTransformation* ct)
|
||||
{
|
||||
getCoordinateTransformationPrototypePtr() = ct;
|
||||
}
|
||||
19
src/osgTerrain/GNUmakefile
Normal file
19
src/osgTerrain/GNUmakefile
Normal file
@@ -0,0 +1,19 @@
|
||||
TOPDIR = ../..
|
||||
include $(TOPDIR)/Make/makedefs
|
||||
|
||||
|
||||
CXXFILES = \
|
||||
CoordinateSystem.cpp\
|
||||
Terrain.cpp\
|
||||
Renderer.cpp\
|
||||
GeoMipMapRenderer.cpp\
|
||||
|
||||
|
||||
DEF += -DOSGTERRAIN_LIBRARY
|
||||
|
||||
LIBS += -losgDB -losg $(GL_LIBS) $(OTHER_LIBS)
|
||||
|
||||
TARGET_BASENAME = osgTerrain
|
||||
LIB = $(LIB_PREFIX)$(TARGET_BASENAME).$(LIB_EXT)
|
||||
|
||||
include $(TOPDIR)/Make/makerules
|
||||
49
src/osgTerrain/GeoMipMapRenderer.cpp
Normal file
49
src/osgTerrain/GeoMipMapRenderer.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*-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);
|
||||
}
|
||||
31
src/osgTerrain/Renderer.cpp
Normal file
31
src/osgTerrain/Renderer.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/* -*-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/Renderer>
|
||||
|
||||
using namespace osgTerrain;
|
||||
|
||||
Renderer::Renderer():
|
||||
_terrain(0)
|
||||
{
|
||||
}
|
||||
|
||||
Renderer::Renderer(const Renderer& renderer,const osg::CopyOp& copyop):
|
||||
osg::Object(renderer,copyop),
|
||||
_terrain(0)
|
||||
{
|
||||
}
|
||||
|
||||
Renderer::~Renderer()
|
||||
{
|
||||
}
|
||||
112
src/osgTerrain/Terrain.cpp
Normal file
112
src/osgTerrain/Terrain.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
/* -*-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