2007-03-22 00:34:04 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGTERRAIN_GEOMETRYTECHNIQUE
|
|
|
|
#define OSGTERRAIN_GEOMETRYTECHNIQUE 1
|
|
|
|
|
2007-04-30 04:10:43 +08:00
|
|
|
#include <osg/MatrixTransform>
|
2007-03-22 00:34:04 +08:00
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
|
|
|
|
#include <osgTerrain/TerrainTechnique>
|
|
|
|
|
|
|
|
namespace osgTerrain {
|
|
|
|
|
2007-04-12 01:39:13 +08:00
|
|
|
class OSGTERRAIN_EXPORT TerrainGeometry : public osg::Drawable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TerrainGeometry();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
|
|
|
|
TerrainGeometry(const TerrainGeometry& geometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
virtual osg::Object* cloneType() const { return new TerrainGeometry(); }
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new TerrainGeometry(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TerrainGeometry*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osgTerrain"; }
|
|
|
|
virtual const char* className() const { return "TerrainGeometry"; }
|
|
|
|
|
|
|
|
void setVertices(osg::Vec3Array* vertices) { _vertices.first = vertices; }
|
|
|
|
osg::Vec3Array* getVertices() { return _vertices.first.get(); }
|
|
|
|
const osg::Vec3Array* getVertices() const { return _vertices.first.get(); }
|
|
|
|
|
|
|
|
void setNormals(osg::Vec3Array* normals) { _normals.first = normals; }
|
|
|
|
osg::Vec3Array* getNormals() { return _normals.first.get(); }
|
|
|
|
const osg::Vec3Array* getNormals() const { return _normals.first.get(); }
|
|
|
|
|
|
|
|
void setColors(osg::Vec4Array* colors) { _colors.first = colors; }
|
|
|
|
osg::Vec4Array* getColors() { return _colors.first.get(); }
|
|
|
|
const osg::Vec4Array* getColors() const { return _colors.first.get(); }
|
|
|
|
|
|
|
|
void setTexCoords(unsigned int unit, osg::Array* array) { _texcoords.resize(unit+1); _texcoords[unit].first = array; }
|
|
|
|
osg::Array* getTexCoords(unsigned int unit) { return _texcoords[unit].first.get(); }
|
|
|
|
const osg::Array* getTexCoords(unsigned int unit) const { return _texcoords[unit].first.get(); }
|
|
|
|
|
|
|
|
void addPrimitiveSet(osg::PrimitiveSet* primitiveSet) { _primitiveSets.push_back(primitiveSet); }
|
|
|
|
|
|
|
|
osg::PrimitiveSet* getPrimtitiveSet(unsigned int i) { return _primitiveSets[i].get(); }
|
|
|
|
const osg::PrimitiveSet* getPrimtitiveSet(unsigned int i) const { return _primitiveSets[i].get(); }
|
|
|
|
unsigned int getNumPrimitiveSets() const { return _primitiveSets.size(); }
|
|
|
|
|
|
|
|
|
|
|
|
virtual osg::BoundingBox computeBound() const;
|
|
|
|
|
|
|
|
/** Draw Geometry directly ignoring an OpenGL display list which could be attached.
|
|
|
|
* This is the internal draw method which does the drawing itself,
|
|
|
|
* and is the method to override when deriving from Geometry for user-drawn objects.
|
|
|
|
*/
|
|
|
|
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
typedef osg::Geometry::PrimitiveSetList PrimitiveSetList;
|
|
|
|
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::Array>, GLvoid*> ArrayData;
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::FloatArray>, GLvoid*> FloatArrayData;
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::Vec2Array>, GLvoid*> Vec2ArrayData;
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::Vec3Array>, GLvoid*> Vec3ArrayData;
|
|
|
|
typedef std::pair< osg::ref_ptr<osg::Vec4Array>, GLvoid*> Vec4ArrayData;
|
|
|
|
|
|
|
|
typedef std::vector< ArrayData > TexCoordsList;
|
|
|
|
|
|
|
|
Vec3ArrayData _vertices;
|
|
|
|
Vec3ArrayData _normals;
|
|
|
|
Vec4ArrayData _colors;
|
|
|
|
TexCoordsList _texcoords;
|
|
|
|
|
|
|
|
PrimitiveSetList _primitiveSets;
|
2007-03-22 00:34:04 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-04-17 03:34:25 +08:00
|
|
|
class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
GeometryTechnique();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
GeometryTechnique(const GeometryTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
|
|
|
virtual void update(osgUtil::UpdateVisitor* nv);
|
|
|
|
|
|
|
|
virtual void cull(osgUtil::CullVisitor* nv);
|
|
|
|
|
|
|
|
virtual void cleanSceneGraph();
|
|
|
|
|
|
|
|
virtual void dirty();
|
2007-06-18 20:10:46 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2007-06-20 20:00:29 +08:00
|
|
|
void setFilterBias(float filterBias);
|
|
|
|
float getFilterBias() const { return _filterBias; }
|
|
|
|
|
2007-06-18 20:10:46 +08:00
|
|
|
void setFilterWidth(float filterWidth);
|
|
|
|
float getFilterWidth() const { return _filterWidth; }
|
|
|
|
|
|
|
|
void setFilterMatrix(const osg::Matrix3& matrix);
|
|
|
|
osg::Matrix3& getFilterMatrix() { return _filterMatrix; }
|
|
|
|
const osg::Matrix3& getFilterMatrix() const { return _filterMatrix; }
|
|
|
|
|
|
|
|
enum FilterType
|
|
|
|
{
|
|
|
|
GAUSSIAN,
|
|
|
|
SMOOTH,
|
|
|
|
SHARPEN
|
|
|
|
};
|
|
|
|
|
|
|
|
void setFilterMatrixAs(FilterType filterType);
|
|
|
|
|
2007-04-17 03:34:25 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~GeometryTechnique();
|
|
|
|
|
2007-04-30 04:10:43 +08:00
|
|
|
osg::ref_ptr<osg::MatrixTransform> _transform;
|
|
|
|
osg::ref_ptr<osg::Geode> _geode;
|
2007-04-17 03:34:25 +08:00
|
|
|
|
2007-04-30 04:10:43 +08:00
|
|
|
osg::ref_ptr<TerrainGeometry> _terrainGeometry;
|
|
|
|
osg::ref_ptr<osg::Geometry> _geometry;
|
2007-06-18 20:10:46 +08:00
|
|
|
|
2007-06-20 20:00:29 +08:00
|
|
|
float _filterBias;
|
|
|
|
osg::ref_ptr<osg::Uniform> _filterBiasUniform;
|
2007-06-18 20:10:46 +08:00
|
|
|
float _filterWidth;
|
|
|
|
osg::ref_ptr<osg::Uniform> _filterWidthUniform;
|
|
|
|
osg::Matrix3 _filterMatrix;
|
|
|
|
osg::ref_ptr<osg::Uniform> _filterMatrixUniform;
|
2007-04-17 03:34:25 +08:00
|
|
|
};
|
|
|
|
|
2007-03-22 00:34:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|