OpenSceneGraph/include/osg/ShadowOccluderVolume

95 lines
2.6 KiB
Plaintext
Raw Normal View History

//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/Polytope>
#include <osg/ConvexPlanerOccluder>
namespace osg {
/** ShadowOccluderVolume is a helper class for implementating shadow occlusion culling. */
class SG_EXPORT ShadowOccluderVolume
{
public:
typedef std::vector<Polytope> HoleList;
ShadowOccluderVolume(const ShadowOccluderVolume& soc,Matrix& MVP);
ShadowOccluderVolume(const ConvexPlanerOccluder& occluder,Matrix& MVP);
inline void pushCurrentMask();
inline void popCurrentMask();
/** 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& bound);
/** return true if the specified bounding box is contained entirely
* within this shadow occluder volume.*/
bool contains(const BoundingBox& bound);
inline void transformProvidingInverse(const osg::Matrix& matrix)
{
_occluderVolume.transformProvidingInverse(matrix);
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->transformProvidingInverse(matrix);
}
}
protected:
Polytope _occluderVolume;
HoleList _holeList;
};
inline void ShadowOccluderVolume::pushCurrentMask()
{
_occluderVolume.pushCurrentMask();
if (!_holeList.empty())
{
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->pushCurrentMask();
}
}
}
inline void ShadowOccluderVolume::popCurrentMask()
{
_occluderVolume.popCurrentMask();
if (!_holeList.empty())
{
for(HoleList::iterator itr=_holeList.begin();
itr!=_holeList.end();
++itr)
{
itr->popCurrentMask();
}
}
}
} // end of namespace
#endif