2008-03-27 04:06:54 +08:00
|
|
|
/* -*-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.
|
|
|
|
*/
|
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
#ifndef OSGTerrain
|
|
|
|
#define OSGTerrain 1
|
2008-03-27 04:06:54 +08:00
|
|
|
|
|
|
|
#include <osg/CoordinateSystemNode>
|
|
|
|
|
2008-03-27 18:55:39 +08:00
|
|
|
#include <osgTerrain/TerrainTile>
|
2008-03-27 04:06:54 +08:00
|
|
|
|
|
|
|
namespace osgTerrain {
|
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
/** Terrain provides a framework for loosely coupling height field data with height rendering algorithms.
|
2009-07-24 22:45:44 +08:00
|
|
|
* This allows TerrainTechniques to be plugged in at runtime.*/
|
2010-04-04 00:21:34 +08:00
|
|
|
class OSGTERRAIN_EXPORT Terrain : public osg::CoordinateSystemNode
|
2008-03-27 04:06:54 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
Terrain();
|
2008-03-27 04:06:54 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
2008-03-27 19:55:03 +08:00
|
|
|
Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
2008-03-27 04:06:54 +08:00
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
META_Node(osgTerrain, Terrain);
|
2008-03-27 04:06:54 +08:00
|
|
|
|
|
|
|
virtual void traverse(osg::NodeVisitor& nv);
|
|
|
|
|
2008-04-22 19:39:47 +08:00
|
|
|
/** Set the sample ratio hint that TerrainTile should use when building geometry.
|
|
|
|
* Defaults to 1.0, which means use all original sample points.*/
|
2010-05-27 21:58:46 +08:00
|
|
|
void setSampleRatio(float ratio);
|
2008-04-22 19:39:47 +08:00
|
|
|
|
|
|
|
/** Get the sample ratio hint.*/
|
|
|
|
float getSampleRatio() const { return _sampleRatio; }
|
2008-05-27 21:11:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Set the vertical scale hint.*/
|
2010-05-27 21:58:46 +08:00
|
|
|
void setVerticalScale(float scale);
|
2010-03-17 02:43:59 +08:00
|
|
|
|
2008-05-27 21:11:47 +08:00
|
|
|
/** Get the vertical scale hint.*/
|
|
|
|
float getVerticalScale() const { return _verticalScale; }
|
2010-03-17 02:43:59 +08:00
|
|
|
|
2010-11-02 20:15:18 +08:00
|
|
|
/** If set to true the boundaries between adjacent tiles should be equalized.
|
|
|
|
* Note, it is only possible to equalizae boundaries when the TerrainTile's contain properly assigned TileID's,
|
|
|
|
* databases built with VirtualPlanetBuilder-0.9.11 and older do not set the TileID, so databases must be
|
|
|
|
* built with later versions of VirtualPlanetBuilder to take advatange of boundary equalization. */
|
|
|
|
void setEqualizeBoundaries(bool equalizeBoundaries);
|
|
|
|
|
|
|
|
/** If true the boundaries between adjacent tiles will be equalized. */
|
|
|
|
bool getEqualizeBoundaries() const { return _equalizeBoundaries; }
|
2010-03-17 02:43:59 +08:00
|
|
|
|
|
|
|
/** Set the default policy to use when deciding whether to enable/disable blending and use of transparent bin.
|
|
|
|
* Note, the Terrain::BlendingPolicy value only sets the value for the TerrainTiles it encloses for the
|
|
|
|
* TerrainTile's that have their policy set to INHERIT. INHERIT is the default BlendingPolicy for both
|
|
|
|
* Terrain and TerrainTile, and if both are left to INERHIT then the policy used is ENABLE_BLENDING_WHEN_ALPHA_PRESENT. */
|
2010-05-27 21:58:46 +08:00
|
|
|
void setBlendingPolicy(TerrainTile::BlendingPolicy policy);
|
2010-03-17 02:43:59 +08:00
|
|
|
|
|
|
|
/** Get the default policy to use when deciding whether to enable/disable blending and use of transparent bin.*/
|
|
|
|
TerrainTile::BlendingPolicy getBlendingPolicy() const { return _blendingPolicy; }
|
|
|
|
|
|
|
|
|
2008-03-27 21:21:36 +08:00
|
|
|
/** Get the TerrainTile for a given TileID.*/
|
|
|
|
TerrainTile* getTile(const TileID& tileID);
|
|
|
|
|
|
|
|
/** Get the const TerrainTile for a given TileID.*/
|
|
|
|
const TerrainTile* getTile(const TileID& tileID) const;
|
2008-12-16 06:18:40 +08:00
|
|
|
|
2009-02-11 18:41:55 +08:00
|
|
|
/** Set the TerrainTechnique prototype from which TerrainTiles can clone the techniques from.*/
|
2009-01-15 04:43:21 +08:00
|
|
|
void setTerrainTechniquePrototype(TerrainTechnique* technique) { _terrainTechnique = technique; }
|
2008-12-16 06:18:40 +08:00
|
|
|
|
|
|
|
/** Get the TerrainTechnique prototype */
|
|
|
|
TerrainTechnique* getTerrainTechniquePrototype() { return _terrainTechnique.get(); }
|
|
|
|
|
|
|
|
/** Get the const TerrainTechnique protype*/
|
|
|
|
const TerrainTechnique* getTerrainTechniquePrototype() const { return _terrainTechnique.get(); }
|
2008-03-27 21:21:36 +08:00
|
|
|
|
2010-04-02 05:06:56 +08:00
|
|
|
/** Tell the Terrain node to call the terrainTile's TerrainTechnique on the next update traversal.*/
|
|
|
|
void updateTerrainTileOnNextFrame(TerrainTile* terrainTile);
|
|
|
|
|
2008-03-27 04:06:54 +08:00
|
|
|
protected:
|
|
|
|
|
2008-03-27 19:55:03 +08:00
|
|
|
virtual ~Terrain();
|
2008-03-27 21:21:36 +08:00
|
|
|
|
|
|
|
friend class TerrainTile;
|
|
|
|
|
2010-05-27 21:58:46 +08:00
|
|
|
void dirtyRegisteredTiles(int dirtyMask = TerrainTile::ALL_DIRTY);
|
2008-05-27 21:11:47 +08:00
|
|
|
|
2008-03-27 21:21:36 +08:00
|
|
|
void registerTerrainTile(TerrainTile* tile);
|
|
|
|
void unregisterTerrainTile(TerrainTile* tile);
|
|
|
|
|
|
|
|
typedef std::map< TileID, TerrainTile* > TerrainTileMap;
|
|
|
|
typedef std::set< TerrainTile* > TerrainTileSet;
|
2008-03-27 04:06:54 +08:00
|
|
|
|
2008-04-22 19:39:47 +08:00
|
|
|
float _sampleRatio;
|
2008-05-27 21:11:47 +08:00
|
|
|
float _verticalScale;
|
2010-03-17 02:43:59 +08:00
|
|
|
TerrainTile::BlendingPolicy _blendingPolicy;
|
2010-11-02 20:15:18 +08:00
|
|
|
bool _equalizeBoundaries;
|
2008-04-22 19:39:47 +08:00
|
|
|
|
2008-03-28 23:31:46 +08:00
|
|
|
mutable OpenThreads::Mutex _mutex;
|
|
|
|
TerrainTileSet _terrainTileSet;
|
|
|
|
TerrainTileMap _terrainTileMap;
|
2010-04-02 05:06:56 +08:00
|
|
|
TerrainTileSet _updateTerrainTileSet;
|
2008-03-27 21:21:36 +08:00
|
|
|
|
2008-12-16 06:18:40 +08:00
|
|
|
osg::ref_ptr<TerrainTechnique> _terrainTechnique;
|
2008-03-27 04:06:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|