Added new osgcallback demo, and updated small API changes to improve the

flexiblity of callbacks.

Added beginings of convex planer occlusions culling.
This commit is contained in:
Robert Osfield
2002-05-28 23:43:22 +00:00
parent a5a267d305
commit ae5e4f848f
22 changed files with 658 additions and 33 deletions

View File

@@ -83,10 +83,8 @@ class SG_EXPORT Billboard : public Geode
struct ComputeBillboardCallback : public osg::Referenced
{
/** Get the transformation matrix which moves from local coords to world coords.*/
virtual const bool computeMatrix(const Matrix& modelview, const Billboard* billboard, const Vec3& eye_local, const Vec3& pos_local) const;
virtual const bool computeMatrix(Matrix& modelview, const Billboard* billboard, const Vec3& eye_local, const Vec3& pos_local) const = 0;
};
friend struct osg::Billboard::ComputeBillboardCallback;
/** Set the ComputeBillboardCallback which allows users to attach custom computation of the local transformation as
* seen by cull traversers and alike.*/
@@ -107,14 +105,14 @@ class SG_EXPORT Billboard : public Geode
return computeMatrix(modelview,eye_local,pos_local);
}
virtual const bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
protected:
virtual ~Billboard();
virtual const bool computeBound() const;
virtual const bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
enum AxisAligned
{
AXIAL_ROT_X_AXIS=AXIAL_ROT+1,

View File

@@ -0,0 +1,61 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_CONVEXPLANEROCCLUDER
#define OSG_CONVEXPLANEROCCLUDER 1
#include <osg/ConvexPlanerPolygon>
#include <osg/Referenced>
namespace osg {
class OccluderVolume;
/** A ClippingVolume class for representing convex clipping volumes made up.
* When adding planes, their normals should point inwards (into the volume) */
class SG_EXPORT ConvexPlanerOccluder : public Referenced
{
public:
inline ConvexPlanerOccluder() {}
void setOccluder(const ConvexPlanerPolygon& cpp) { _occluder = cpp; }
ConvexPlanerPolygon& getOccluder() { return _occluder; }
const ConvexPlanerPolygon& getOccluder() const { return _occluder; }
typedef std::vector<ConvexPlanerPolygon> HoleList;
void addHole(const ConvexPlanerPolygon& cpp) { _holeList.push_back(cpp); }
HoleList& getHoleList() { return _holeList; }
const HoleList& getHoleList() const { return _holeList; }
void computeAttributes();
void computeBound(BoundingBox& bb) const;
void computeBound(BoundingSphere& bs) const;
protected:
float _area;
Vec3 _center;
Vec3 _normal;
ConvexPlanerPolygon _occluder;
HoleList _holeList;
};
} // end of namespace
#endif

View File

@@ -0,0 +1,57 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_CONVEXPLANERPOLYGON
#define OSG_CONVEXPLANERPOLYGON 1
#include <osg/Plane>
#include <vector>
namespace osg {
class BoundingBox;
class BoundingSphere;
/** A ClippingVolume class for representing convex clipping volumes made up.
* When adding planes, their normals should point inwards (into the volume) */
class SG_EXPORT ConvexPlanerPolygon
{
public:
inline ConvexPlanerPolygon() {}
float area() { return _area; }
const Vec3& center() { return _center; }
const Vec3& normal() { return _normal; }
typedef std::vector<osg::Vec3> VertexList;
void add(const Vec3& v) { _vertexList.push_back(v); }
VertexList& getVertexList() { return _vertexList; }
const VertexList& getVertexList() const { return _vertexList; }
void computeAttributes();
void computeBound(BoundingBox& bb) const;
void computeBound(BoundingSphere& bs) const;
protected:
float _area;
Vec3 _center;
Vec3 _normal;
VertexList _vertexList;
};
} // end of namespace
#endif

View File

@@ -171,8 +171,6 @@ class SG_EXPORT Drawable : public Object
/** do customized draw code.*/
virtual void drawImmediateMode(State& state,osg::Drawable* drawable) const = 0;
};
friend struct osg::Drawable::DrawCallback;
/** Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.*/
void setDrawCallback(DrawCallback* dc) { _drawCallback=dc; dirtyDisplayList(); }
@@ -186,10 +184,8 @@ class SG_EXPORT Drawable : public Object
struct CullCallback : public osg::Referenced
{
/** do customized cull code.*/
virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable) = 0;
virtual bool cull(osg::NodeVisitor *visitor, osg::Drawable* drawable) const = 0;
};
friend struct osg::Drawable::CullCallback;
/** Set the CullCallback which allows users to attach customize the drawing of existing Drawable object.*/
void setCullCallback(CullCallback* cc) { _cullCallback=cc; }

View File

@@ -8,6 +8,7 @@
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/Drawable>
#include <osg/ConvexPlanerOccluder>
namespace osg {
@@ -107,6 +108,17 @@ class SG_EXPORT Geode : public Node
/** compile OpenGL Display List for each geoset.*/
void compileDrawables(State& state);
/** Attach a ConvexPlanerOccluder to a Geode.*/
void setOccluder(ConvexPlanerOccluder* occluder) { _occluder = occluder; }
/** Get the ConvexPlanerOccluder* attached to a Geode. */
ConvexPlanerOccluder* getOccluder() { return _occluder.get(); }
/** Get the const ConvexPlanerOccluder* attached to a Geode.*/
const ConvexPlanerOccluder* getOccluder() const { return _occluder.get(); }
protected:
@@ -114,7 +126,8 @@ class SG_EXPORT Geode : public Node
virtual const bool computeBound() const;
DrawableList _drawables;
DrawableList _drawables;
ref_ptr<ConvexPlanerOccluder> _occluder;
};

View File

@@ -60,10 +60,8 @@ class SG_EXPORT LOD : public Group
struct EvaluateLODCallback : public osg::Referenced
{
/** Compute the child to select.*/
virtual const int evaluateLODChild(const osg::LOD* lod, const Vec3& eye_local, const float bias) const;
virtual const int evaluateLODChild(const osg::LOD* lod, const Vec3& eye_local, const float bias) const = 0;
};
friend struct osg::LOD::EvaluateLODCallback;
/** Set the EvaluateLODCallback which allows users to attach customize computation of the the selection of LOD children.*/
void setEvaluateLODCallback(EvaluateLODCallback* cbc) { _evaluateLODCallback=cbc; }
@@ -74,8 +72,6 @@ class SG_EXPORT LOD : public Group
/** Get the const ComputeBillboardCallback.*/
const EvaluateLODCallback* getEvaluateLODCallback() const { return _evaluateLODCallback.get(); }
/** return the child to traverse.
Selected by the distance between the eye point in local
coordinates and the LOD center, multiplied by the bias.*/
@@ -88,10 +84,11 @@ class SG_EXPORT LOD : public Group
}
virtual const int evaluateLODChild(const Vec3& eye_local,const float bias) const;
protected :
virtual ~LOD() {}
virtual const int evaluateLODChild(const Vec3& eye_local,const float bias) const;
typedef std::vector<float> RangeList;
RangeList _rangeList;

View File

@@ -36,13 +36,13 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
const Quat& getAttitude() const { return _attitude; }
protected :
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
protected :
Vec3 _position;
Quat _attitude;

View File

@@ -0,0 +1,56 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_SHADOWOCCLUDERVOLUME
#define OSG_SHADOWOCCLUDERVOLUME 1
#include <osg/ref_ptr>
#include <osg/ClippingVolume>
#include <osg/ConvexPlanerOccluder>
namespace osg {
/** ShadowOccluderVolume is a helper class for implementating shadow occlusion culling. */
class SG_EXPORT ShadowOccluderVolume : public Referenced
{
public:
ShadowOccluderVolume(const ShadowOccluderVolume& soc,Matrix& MVP);
ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP);
typedef std::vector<ClippingVolume> ClippingHoleList;
/** Convert shadow occluder into local coords by multiplying the
* clip space occluder by the ModelViewProjectionMatrix.*/
void set(const ShadowOccluderVolume& soc,Matrix& MVP);
/** Initialize a ShadowOccluderVolume to a ConvexPlanerOccluder
* transformed into clipspace.*/
void set(const ConvexPlanerOccluder& occluder,Matrix& MVP);
/** return true if the specified bounding sphere is contaned entirely
* within this shadow occluder volume.*/
bool contains(const BoundingSphere& bs);
/** return true if the specified bounding box is contained entirely
* within this shadow occluder volume.*/
bool contains(const BoundingBox& bs);
protected:
// the original shadow occluder computed in clip space
ref_ptr<ShadowOccluderVolume> _clipSpaceOccluder;
ClippingVolume _occluderVolume;
ClippingHoleList _clippingHoleList;
};
} // end of namespace
#endif

View File

@@ -69,8 +69,6 @@ class SG_EXPORT Transform : public Group
/** Get the transformation matrix which moves from world coords to local coords.*/
virtual const bool computeWorldToLocalMatrix(Matrix& matrix,const Transform* transform, NodeVisitor* nv) const = 0;
};
friend struct osg::Transform::ComputeTransformCallback;
/** Set the ComputerTransfromCallback which allows users to attach custom computation of the local transformation as
* seen by cull traversers and alike.*/
@@ -118,16 +116,6 @@ class SG_EXPORT Transform : public Group
/** postMult transform.*/
void postMult(const Matrix& mat) { _matrix->postMult(mat); _inverseDirty=true; computeInverse(); dirtyBound(); }
protected :
virtual ~Transform();
/** Override's Group's computeBound.
* There is no need to override in subclasses from osg::Transform since this computeBound() uses
* the underlying matrix (calling computeMatrix if required.) */
virtual const bool computeBound() const;
virtual const bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
{
if (_referenceFrame==RELATIVE_TO_PARENTS)
@@ -153,6 +141,16 @@ class SG_EXPORT Transform : public Group
}
return true;
}
protected :
virtual ~Transform();
/** Override's Group's computeBound.
* There is no need to override in subclasses from osg::Transform since this computeBound() uses
* the underlying matrix (calling computeMatrix if required.) */
virtual const bool computeBound() const;
inline void computeInverse() const
{