Introduce TerrainSystem node which decorates a complete terrain model made up of Terrain tiles.
This commit is contained in:
@@ -23,6 +23,37 @@
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
class TerrainSystem;
|
||||
|
||||
class TileID
|
||||
{
|
||||
public:
|
||||
|
||||
TileID():
|
||||
layer(-1),
|
||||
x(-1),
|
||||
y(-1) {}
|
||||
|
||||
TileID(int in_layer, int in_x, int in_y):
|
||||
layer(in_layer),
|
||||
x(in_x),
|
||||
y(in_y) {}
|
||||
|
||||
bool operator < (const TileID& rhs) const
|
||||
{
|
||||
if (layer<rhs.layer) return true;
|
||||
if (layer>rhs.layer) return false;
|
||||
if (x<rhs.x) return true;
|
||||
if (x>rhs.x) return false;
|
||||
return y<rhs.y;
|
||||
}
|
||||
|
||||
int layer;
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
|
||||
/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
|
||||
* This allows TerrainTechnique's to be plugged in at runtime.*/
|
||||
class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
@@ -41,8 +72,25 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
/** Call init on any attached TerrainTechnique.*/
|
||||
void init();
|
||||
|
||||
|
||||
/** Set the TerrainSystem that this Terrain tile is a member of.*/
|
||||
void setTerrainSystem(TerrainSystem* ts) { _terrainSystem = ts; }
|
||||
|
||||
/** Get the TerrainSystem that this Terrain tile is a member of.*/
|
||||
TerrainSystem* getTerrainSystem() { return _terrainSystem; }
|
||||
|
||||
/** Get the const TerrainSystem that this Terrain tile is a member of.*/
|
||||
const TerrainSystem* getTerrainSystem() const { return _terrainSystem; }
|
||||
|
||||
|
||||
void setTileID(const TileID& tileID) { _tileID = tileID; }
|
||||
|
||||
const TileID& getTileID() const { return _tileID; }
|
||||
|
||||
|
||||
|
||||
/** Set the TerrainTechnique*/
|
||||
void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique);
|
||||
void setTerrainTechnique(TerrainTechnique* TerrainTechnique);
|
||||
|
||||
/** Get the TerrainTechnique*/
|
||||
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
|
||||
@@ -98,15 +146,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
bool getTreatBoundariesToValidDataAsDefaultValue() const { return _treatBoundariesToValidDataAsDefaultValue; }
|
||||
|
||||
|
||||
/** Set an OperationQueue to do an data initialization and update work.*/
|
||||
void setOperationQueue(osg::OperationQueue* operations) { _operationQueue = operations; }
|
||||
|
||||
/** Get the OperationsQueue if one is attached, return NULL otherwise.*/
|
||||
osg::OperationQueue* getOperationQueue() { return _operationQueue.get(); }
|
||||
|
||||
/** Get the const OperationsQueue if one is attached, return NULL otherwise.*/
|
||||
const osg::OperationQueue* getOperationsQueue() const { return _operationQueue.get(); }
|
||||
|
||||
/** Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers.*/
|
||||
virtual osg::BoundingSphere computeBound() const;
|
||||
|
||||
@@ -116,6 +155,13 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
|
||||
typedef std::vector< osg::ref_ptr<Layer> > Layers;
|
||||
|
||||
|
||||
TerrainSystem* _terrainSystem;
|
||||
|
||||
bool _hasBeenTraversal;
|
||||
|
||||
TileID _tileID;
|
||||
|
||||
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
||||
osg::ref_ptr<Locator> _locator;
|
||||
|
||||
@@ -125,8 +171,6 @@ class OSGTERRAIN_EXPORT Terrain : public osg::Group
|
||||
|
||||
bool _requiresNormals;
|
||||
bool _treatBoundariesToValidDataAsDefaultValue;
|
||||
|
||||
osg::ref_ptr<osg::OperationQueue> _operationQueue;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
67
include/osgTerrain/TerrainSystem
Normal file
67
include/osgTerrain/TerrainSystem
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 OSGTERRAINSYSTEM
|
||||
#define OSGTERRAINSYSTEM 1
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
/** TerrainSystem provides a framework for loosely coupling height field data with height rendering algorithms.
|
||||
* This allows TerrainTechnique's to be plugged in at runtime.*/
|
||||
class OSGTERRAIN_EXPORT TerrainSystem : public osg::Group
|
||||
{
|
||||
public:
|
||||
|
||||
TerrainSystem();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
TerrainSystem(const TerrainSystem&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Node(osgTerrain, TerrainSystem);
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
/** Set the TerrainTechnique that is used as the prototype for all Terrain below the TerrainSystem. */
|
||||
void setTerrainTechnique(osgTerrain::TerrainTechnique* TerrainTechnique);
|
||||
|
||||
/** Get the TerrainTechnique*/
|
||||
TerrainTechnique* getTerrainTechnique() { return _terrainTechnique.get(); }
|
||||
|
||||
/** Get the const TerrainTechnique*/
|
||||
const TerrainTechnique* getTerrainTechnique() const { return _terrainTechnique.get(); }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TerrainSystem();
|
||||
|
||||
friend class TerrainManager;
|
||||
|
||||
void registerPotentialMember(Terrain* terrain);
|
||||
|
||||
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
||||
|
||||
typedef std::list< osg::observer_ptr<Terrain> > TerrainList;
|
||||
TerrainList _incomingTerrain;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -14,13 +14,13 @@
|
||||
#ifndef OSGTERRAIN_TILESYSTEM
|
||||
#define OSGTERRAIN_TILESYSTEM 1
|
||||
|
||||
#include <osgTerrain/Export>
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/observer_ptr>
|
||||
|
||||
namespace osgTerrain {
|
||||
|
||||
|
||||
/** TileSystem provides the mechanism for computing the position in space of tiles.*/
|
||||
class OSGTERRAIN_EXPORT TileSystem : public osg::Object
|
||||
{
|
||||
@@ -35,26 +35,10 @@ class OSGTERRAIN_EXPORT TileSystem : public osg::Object
|
||||
protected:
|
||||
|
||||
virtual ~TileSystem();
|
||||
};
|
||||
|
||||
class OSGTERRAIN_EXPORT TileID : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
TileID();
|
||||
|
||||
TileID(const TileID&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgTerrain, TileID);
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TileID();
|
||||
|
||||
osg::observer_ptr<TileSystem> _tileSystem;
|
||||
int _layer;
|
||||
int _x;
|
||||
int _y;
|
||||
typedef std::map< TileID, osg::observer_ptr<Terrain> > TileMap;
|
||||
|
||||
TileMap _tileMap;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user