OpenSceneGraph/include/osgUtil/CullViewState

89 lines
2.3 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.
2001-09-20 05:19:47 +08:00
#ifndef OSGUTIL_CULLVIEWSTATE
#define OSGUTIL_CULLVIEWSTATE 1
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/Matrix>
#include <osg/ClippingVolume>
#include <osgUtil/Export>
namespace osgUtil {
/** Container class for encapsulating the viewing state in local
coordinates, during the cull traversal.
*/
class OSGUTIL_EXPORT CullViewState : public osg::Referenced
{
public:
CullViewState();
osg::ref_ptr<osg::Matrix> _matrix;
osg::ref_ptr<osg::Matrix> _inverse;
osg::Vec3 _eyePoint;
osg::Vec3 _centerPoint;
osg::Vec3 _lookVector;
osg::Vec3 _upVector;
unsigned int _bbCornerFar;
unsigned int _bbCornerNear;
float _ratio2;
osg::ClippingVolume _clippingVolume;
enum
{
NO_CULLING = 0x00,
FRUSTUM_LEFT_CULLING = 0x01,
FRUSTUM_RIGHT_CULLING = 0x02,
FRUSTUM_BOTTOM_CULLING = 0x04,
FRUSTUM_TOP_CULLING = 0x08,
FRUSTUM_NEAR_CULLING = 0x10,
FRUSTUM_FAR_CULLING = 0x20,
VIEW_FRUSTUM_CULLING = 0x3F,
SMALL_FEATURE_CULLING = 0x40,
ENABLE_ALL_CULLING = 0x7F
2001-09-20 05:19:47 +08:00
};
typedef unsigned int CullingMode;
inline bool isCulled(const osg::BoundingSphere& sp,CullingMode& mode) const
{
if (!sp.isValid()) return true;
if (!_clippingVolume.contains(sp,mode)) return true;
if (mode&SMALL_FEATURE_CULLING)
{
osg::Vec3 delta(sp._center-_eyePoint);
if (sp.radius2()<delta.length2()*_ratio2)
{
return true;
}
}
return false;
}
inline bool isCulled(const osg::BoundingBox& bb,CullingMode mode) const
{
if (!bb.isValid()) return true;
return !_clippingVolume.contains(bb,mode);
}
protected:
~CullViewState();
};
}
2001-09-20 05:19:47 +08:00
#endif