dded osg::ClipNode class for managing OpenGL clipping planes, and osgclip demo.

This commit is contained in:
Robert Osfield
2002-05-02 00:14:40 +00:00
parent 3c25b7ab7c
commit ae8076f83b
20 changed files with 610 additions and 35 deletions

78
include/osg/ClipNode Normal file
View File

@@ -0,0 +1,78 @@
//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_CLIPNODE
#define OSG_CLIPNODE 1
#include <osg/Group>
#include <osg/ClipPlane>
namespace osg {
/** Leaf Node for defining the position of ClipPlanes in the scene.*/
class SG_EXPORT ClipNode : public Group
{
public:
typedef std::vector<ref_ptr<ClipPlane> > ClipPlaneList;
ClipNode();
ClipNode(const ClipNode& es, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(ClipNode);
/** Create a 6 clip planes to create a clip box.*/
void createClipBox(const BoundingBox& bb,unsigned int clipPlaneNumberBase=0);
/** Add a ClipPlane to a ClipNode. Return true if plane is added,
* return false if plane already exists in ClipNode, or clipplane is false.*/
const bool addClipPlane(ClipPlane* clipplane);
/** Remove ClipPlane from a ClipNode. Return true if plane is removed,
* return false if plane does not exists in ClipNode.*/
const bool removeClipPlane(ClipPlane* clipplane);
/** Remove ClipPlane, at specified index, from a ClipNode. Return true if plane is removed,
* return false if plane does not exists in ClipNode.*/
const bool removeClipPlane(unsigned int pos);
/** return the number of ClipPlanes.*/
inline const unsigned int getNumClipPlanes() const { return _planes.size(); }
/** Get ClipPlane at specificed index position.*/
inline ClipPlane* getClipPlane(unsigned int pos) { return _planes[pos].get(); }
/** Get const ClipPlane at specificed index position.*/
inline const ClipPlane* getClipPlane(unsigned int pos) const { return _planes[pos].get(); }
/** Get the ClipPlaneList.*/
inline ClipPlaneList& getClipPlaneList() { return _planes; }
/** Get the const ClipPlaneList.*/
inline const ClipPlaneList& getClipPlaneList() const { return _planes; }
/** Set the GLModes on StateSet associated with the ClipPlanes.*/
void setStateSetModes(StateSet&,const StateAttribute::GLModeValue) const;
/** Set up the local StateSet */
void setLocalStateSetModes(const StateAttribute::GLModeValue=StateAttribute::ON);
protected:
virtual ~ClipNode();
virtual const bool computeBound() const;
StateAttribute::GLModeValue _value;
ClipPlaneList _planes;
};
}
#endif

View File

@@ -17,6 +17,9 @@ class SG_EXPORT ClipPlane : public StateAttribute
public :
ClipPlane();
inline ClipPlane(unsigned int no,const Vec4& plane) { setClipPlaneNum(no); setClipPlane(plane); }
inline ClipPlane(unsigned int no,const Plane& plane) { setClipPlaneNum(no); setClipPlane(plane); }
inline ClipPlane(unsigned int no,const double a,const double b,const double c,const double d) { setClipPlaneNum(no); setClipPlane(a,b,c,d); }
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ClipPlane(const ClipPlane& cp,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
@@ -63,6 +66,12 @@ class SG_EXPORT ClipPlane : public StateAttribute
/** Set the clip plane, using a double[4] to define plane. */
void setClipPlane(const double* plane);
/** Set the clip plane, using a a to define plane. */
void setClipPlane(const double a,const double b,const double c,const double d)
{
_clipPlane[0]=a;_clipPlane[1]=b;_clipPlane[2]=c;_clipPlane[3]=d;
}
/** Get the clip plane, values entered into a Vec4 passed to the getClipPlane. */
void getClipPlane(Vec4& plane) const;

View File

@@ -60,13 +60,13 @@ class SG_EXPORT Matrix : public Object
inline Matrix& operator = (const Matrix& other)
{
if( &other == this ) return *this;
set((float const * const)(other._mat));
std::copy((const float*)other._mat,(const float*)other._mat+16,(float*)(_mat));
return *this;
}
inline void set(const Matrix& other)
{
set((float const * const)(other._mat));
std::copy((const float*)other._mat,(const float*)other._mat+16,(float*)(_mat));
}
inline void set(float const * const ptr)

View File

@@ -14,6 +14,7 @@ namespace osg {
class Geode;
class Billboard;
class LightSource;
class ClipNode;
class Group;
class Transform;
class Projection;
@@ -164,19 +165,20 @@ class SG_EXPORT NodeVisitor : public Referenced
const bool getWorldToLocalMatrix(Matrix& matrix, Node* node);
virtual void apply(Node& node) { traverse(node);}
virtual void apply(Node& node) { traverse(node);}
virtual void apply(Geode& node) { apply((Node&)node); }
virtual void apply(Billboard& node) { apply((Geode&)node); }
virtual void apply(LightSource& node){ apply((Node&)node); }
virtual void apply(Geode& node) { apply((Node&)node); }
virtual void apply(Billboard& node) { apply((Geode&)node); }
virtual void apply(LightSource& node) { apply((Node&)node); }
virtual void apply(ClipNode& node) { apply((Node&)node); }
virtual void apply(Group& node) { apply((Node&)node); }
virtual void apply(Projection& node) { apply((Group&)node); }
virtual void apply(Transform& node) { apply((Group&)node); }
virtual void apply(Switch& node) { apply((Group&)node); }
virtual void apply(LOD& node) { apply((Group&)node); }
virtual void apply(Impostor& node) { apply((LOD&)node); }
virtual void apply(EarthSky& node) { apply((Group&)node); }
virtual void apply(Group& node) { apply((Node&)node); }
virtual void apply(Projection& node) { apply((Group&)node); }
virtual void apply(Transform& node) { apply((Group&)node); }
virtual void apply(Switch& node) { apply((Group&)node); }
virtual void apply(LOD& node) { apply((Group&)node); }
virtual void apply(Impostor& node) { apply((LOD&)node); }
virtual void apply(EarthSky& node) { apply((Group&)node); }
protected:

View File

@@ -66,6 +66,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
virtual void apply(osg::Geode& node);
virtual void apply(osg::Billboard& node);
virtual void apply(osg::LightSource& node);
virtual void apply(osg::ClipNode& node);
virtual void apply(osg::Group& node);
virtual void apply(osg::Transform& node);
@@ -288,12 +289,13 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,_projectionStack.back().get(),matrix,depth));
}
/** Add a light to current render graph.*/
inline void addLight(osg::Light* light,osg::Matrix* matrix)
/** Add an attribute which is positioned related to the modelview matrix.*/
inline void addPositionedAttribute(osg::Matrix* matrix,const osg::StateAttribute* attr)
{
_currentRenderBin->_stage->addLight(light,matrix);
_currentRenderBin->_stage->addPositionedAttribute(matrix,attr);
}
/** create an impostor sprite by setting up a pre-rendering stage
* to generate the impostor texture. */
osg::ImpostorSprite* createImpostorSprite(osg::Impostor& node);

View File

@@ -100,11 +100,11 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
return _renderStageLighting.get();
}
virtual void addLight(osg::Light* light,osg::Matrix* matrix)
virtual void addPositionedAttribute(osg::Matrix* matrix,const osg::StateAttribute* attr)
{
getRenderStageLighting()->addLight(light,matrix);
getRenderStageLighting()->addPositionedAttribute(matrix,attr);
}
virtual void draw(osg::State& state,RenderLeaf*& previous);
void addToDependencyList(RenderStage* rs);

View File

@@ -30,19 +30,19 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object
virtual void reset();
typedef std::pair< osg::Light*, osg::ref_ptr<osg::Matrix> > LightMatrixPair;
typedef std::vector< LightMatrixPair > LightList;
typedef std::pair< const osg::StateAttribute*, osg::ref_ptr<osg::Matrix> > AttrMatrixPair;
typedef std::vector< AttrMatrixPair > AttrMatrixList;
virtual void addLight(osg::Light* light,osg::Matrix* matrix)
virtual void addPositionedAttribute(osg::Matrix* matrix,const osg::StateAttribute* attr)
{
_lightList.push_back(LightMatrixPair(light,matrix));
_attrList.push_back(AttrMatrixPair(attr,matrix));
}
virtual void draw(osg::State& state,RenderLeaf*& previous);
public:
LightList _lightList;
AttrMatrixList _attrList;
protected: