Early development work on osgTerrain.

This commit is contained in:
Robert Osfield
2003-11-25 19:42:35 +00:00
parent a4b399c002
commit 023d2254ab
10 changed files with 618 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
/* -*-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_COORDINATESYSTEM
#define OSGTERRAIN_COORDINATESYSTEM 1
#include <osg/Object>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osgTerrain/Export>
namespace osgTerrain
{
/** CoordinateSystem encapsulate the coordinate system that associated with objects in a scene.*/
class CoordinateSystem : public osg::Object
{
public:
CoordinateSystem();
CoordinateSystem(const std::string& projectionRef);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
CoordinateSystem(const CoordinateSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object(osgTerrain,CoordinateSystem);
inline bool operator == (const CoordinateSystem& cs) const
{
if (this == &cs) return true;
if (_projectionRef == cs._projectionRef) return true;
return false;
}
inline bool operator != (const CoordinateSystem& cs) const
{
return !(*this==cs);
}
/** Set the CoordinateSystem projection reference string, should be stored in OpenGIS Well Know Text form.*/
void setProjectionRef(const std::string& projectionRef) { _projectionRef = projectionRef; }
/** Get the CoordinateSystem projection reference string.*/
const std::string& getProjectionRef() const { return _projectionRef; }
/** CoordinateTransformation is a helper class for transforming between two different CoodinateSystems.
* To use, simply constructor a CoordinateSystem::CoordinateTransformation convertor(sourceCS,destinateCS)
* and then convert indiviual points via v_destination = convert(v_source), or the
* CoordinateTransformation.convert(ptr,num) method when handling arrays of Vec2/Vec3's.*/
class CoordinateTransformation : public osg::Referenced
{
public:
static CoordinateTransformation* createCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination);
static void setCoordinateTransformationPrototpe(CoordinateTransformation* ct);
virtual osg::Vec2 operator () (const osg::Vec2& source) const = 0;
virtual osg::Vec3 operator () (const osg::Vec3& source) const = 0;
virtual bool transform(unsigned int numPoints, osg::Vec2* vec2ptr) const = 0;
virtual bool transform(unsigned int numPoints, osg::Vec3* vec3ptr) const = 0;
protected:
CoordinateTransformation() {}
virtual ~CoordinateTransformation() {}
virtual CoordinateTransformation* cloneCoordinateTransformation(const CoordinateSystem& source, const CoordinateSystem& destination) const = 0;
};
protected:
virtual ~CoordinateSystem() {}
std::string _projectionRef;
};
}
#endif

37
include/osgTerrain/Export Normal file
View File

@@ -0,0 +1,37 @@
/* -*-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_EXPORT_
#define OSGTERRAIN_EXPORT_ 1
#if defined(_MSC_VER)
#pragma warning( disable : 4244 )
#pragma warning( disable : 4251 )
#pragma warning( disable : 4267 )
#pragma warning( disable : 4275 )
#pragma warning( disable : 4290 )
#pragma warning( disable : 4786 )
#pragma warning( disable : 4305 )
#endif
#if defined(_MSC_VER) || defined(__CYGWIN__) || defined(__MINGW32__) || defined( __BCPLUSPLUS__)
# ifdef OSGTERRAIN_LIBRARY
# define OSGTERRAIN_EXPORT __declspec(dllexport)
# else
# define OSGTERRAIN_EXPORT __declspec(dllimport)
# endif /* OSGTERRAIN_LIBRARY */
#else
# define OSGTERRAIN_EXPORT
#endif
#endif

View 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.
*/
#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

View File

@@ -0,0 +1,60 @@
/* -*-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_Renderer
#define OSGTERRAIN_Renderer 1
#include <osg/Object>
#include <osgUtil/UpdateVisitor>
#include <osgUtil/CullVisitor>
#include <osgTerrain/Export>
namespace osgTerrain {
class Terrain;
class OSGTERRAIN_EXPORT Renderer : public osg::Object
{
public:
Renderer();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Renderer(const Renderer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
Terrain* getTerrain() { return _terrain; }
const Terrain* getTerrain() const { return _terrain; }
virtual void initialize() = 0;
virtual void terrainHasBeenModified() = 0;
virtual void update(osgUtil::UpdateVisitor* nv) = 0;
virtual void cull(osgUtil::CullVisitor* nv) = 0;
protected:
virtual ~Renderer();
friend class osgTerrain::Terrain;
Terrain* _terrain;
};
}
#endif

112
include/osgTerrain/Terrain Normal file
View 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.
*/
#ifndef OSGTERRAIN_TERRAIN
#define OSGTERRAIN_TERRAIN 1
#include <osg/Group>
#include <osg/Image>
#include <osgTerrain/Renderer>
#include <osgTerrain/CoordinateSystem>
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 coordinates system associated with this Terrain*/
void setCoordinateSystem(CoordinateSystem* cs) { _coordinateSystem = cs; }
/** Get the coordinates system associated with this Terrain*/
CoordinateSystem* getCoordinateSystem() { return _coordinateSystem.get(); }
/** Get the const coordinates system associated with this Terrain*/
const CoordinateSystem* getCoordinateSystem() const { return _coordinateSystem.get(); }
/** 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<CoordinateSystem> _coordinateSystem;
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