Fixed cluster culling.

This commit is contained in:
Robert Osfield 2004-07-09 20:58:43 +00:00
parent a7490a2ea2
commit 3f4b8e9034
3 changed files with 13 additions and 5 deletions

View File

@ -34,7 +34,7 @@ class SG_EXPORT ClusterCullingCallback : public Drawable::CullCallback
/** compute the control point, normal and deviation from the contents of the drawable.*/
void computeFrom(const osg::Drawable* drawable);
void set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation);
void set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation, float radius);
void setControlPoint(const osg::Vec3& controlPoint) { _controlPoint = controlPoint; }
const osg::Vec3& getControlPoint() const { return _controlPoint; }

View File

@ -134,17 +134,18 @@ void ClusterCullingCallback::computeFrom(const osg::Drawable* drawable)
_radius = sqrtf(cdf._radius2);
}
void ClusterCullingCallback::set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation)
void ClusterCullingCallback::set(const osg::Vec3& controlPoint, const osg::Vec3& normal, float deviation, float radius)
{
_controlPoint = controlPoint;
_normal = normal;
_deviation = deviation;
_radius = radius;
}
bool ClusterCullingCallback::cull(osg::NodeVisitor* nv, osg::Drawable* , osg::State*) const
{
return false;
// return false;
if (_deviation<=-1.0f)
{
@ -153,8 +154,12 @@ bool ClusterCullingCallback::cull(osg::NodeVisitor* nv, osg::Drawable* , osg::St
}
osg::Vec3 eye_cp = nv->getEyePoint() - _controlPoint;
float radius = eye_cp.length();
float deviation = (eye_cp * _normal)/eye_cp.length();
if (radius<_radius) return false;
float deviation = (eye_cp * _normal)/radius;
// osg::notify(osg::NOTICE)<<"ClusterCullingCallback::cull() _normal="<<_normal<<" _controlPointtest="<<_controlPoint<<" eye_cp="<<eye_cp<<std::endl;
// osg::notify(osg::NOTICE)<<" deviation="<<deviation<<" _deviation="<<_deviation<<" test="<<(deviation < _deviation)<<std::endl;

View File

@ -2173,6 +2173,7 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
float min_dot_product = 1.0f;
float max_cluster_culling_height = 0.0f;
float max_cluster_culling_radius = 0.0f;
for(r=0;r<numRows;++r)
{
@ -2215,6 +2216,7 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
float local_m = globe_radius*( 1.0/ cos(theta+phi) - 1.0);
min_dot_product = osg::minimum(min_dot_product, local_dot_product);
max_cluster_culling_height = osg::maximum(max_cluster_culling_height,local_m);
max_cluster_culling_radius = osg::maximum(max_cluster_culling_radius,static_cast<float>(beta*globe_radius));
}
else
{
@ -2305,7 +2307,8 @@ osg::Node* DataSet::DestinationTile::createPolygonal()
ccc->set(center_position + transformed_center_normal*max_cluster_culling_height ,
transformed_center_normal,
min_dot_product);
min_dot_product,
max_cluster_culling_radius);
geometry->setCullCallback(ccc);
}