[osg-users] Detecting if a node is within viewfrustum

Julien Valentin julienvalentin51 at gmail.com
Sat Aug 27 14:41:49 PDT 2016

Hi Sura
I may be wrong but I'm afraid you cannot do that in a cullcallback.
You may use a statefull (caching last cull result/and last aabb of the node) update callback performing a custom culling with a PolytopeIntersector (with a polytope describing the view frustum).
This can be really expensive as the test must be done for all the scenegraph even if node outside frustum..
Further if you wanna know which plane is traversed (in the case lastcullresult!=currentcullresult) I think you'll have to perform a custom collision detection against each frustum plane and the extruded boundingbox of the node(lastbb extruded to currentbb)..

Perhaps Robert will have a best/simplier way to go but personnally I only see this one.


suraj wrote:
> Hi evrybody,
> I am new to Openscene graph and need a help/guidance.
> I wish to find which of the sides of view frustum- left, right, top, bottom near or far- a moving node is crossing. How to find this in Openscene graph?
> I used a class as follows:-
> class MyCullCallback : public osg::NodeCallback
> {
> void operator()(osg::Node* node, osg::NodeVisitor* nv)
>     {
> //      osgUtil::CullVisitor* cv = nv->asCullVisitor();
>         osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
>          if (!cv->isCulled(*node))
>          {
>                         std::cout << "Node is visible: "<< endl;
>          }
>         if ( cv->isCulled(*node))
>         {
>              std::cout << "Node is NOT visible: "<<endl;
>             }
>        traverse(node,nv);
>     }
> };
> The node is given some translation.
> The above cull callback just detects is a node is culled or not...I observed that as long the node is within the viewport it prints, "Node is Visible". 
> However, it never prints "Node is NOT visible", even when the node goes out of the scene. 
> Any help would help me...
> ... 
> Thank you!
> Cheers,
> Suraj

Read this topic online here:

More information about the osg-users mailing list