0

I have a code that handles a Cull Callback by overriding traverse method:

void SomeNode::traverse(osg::NodeVisitor& nv)
{
    if (nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR)
    {
        //adjust child node positions depending on the projection
    }
}

but looks like there is an alternate way how to add a Cull Callback with

void Node::setCullCallback(Callback* nc);

Which one is better and in what situation? And is the first way is correct?

Koban
  • 463
  • 1
  • 6
  • 12

1 Answers1

0

The most common way is to set a Cull Callback on the node, as it doesn't require you to write a custom osg::Node derived class. As such you can add the callback to any existing node type, in particular to models loaded from file.

It's also quite flexible since you can easily add/remove/replace callbacks at runtime.

In both cases, if culling is active on the node of interest, the traverse() method or the callback are invoked only if the node passes the culling test.

rickyviking
  • 846
  • 6
  • 17
  • Is it right that this code with overriding traverse method is not quite correct, because if there are multiple Cull Callbacks added to a node, traverse method is executed multiple time (for each added collback) and theoretically there should be not only 'nv.getVisitorType() == osg::NodeVisitor::CULL_VISITOR' condition, in traverse method, but also something like dynamic_cast to make the code work differently for each type of the Cull Visitor? – Koban Sep 26 '17 at 17:11
  • @Koban not sure what you mean, as you seem to mix the concepts of cull visitor and cull callback. Normally your node will be visited each frame by as many cull traversal as the number active Cameras. The default class used for each culling traversal is osgUtil::CullVisitor. Your callback(s) will be invoked one time for each visit (taking into account the culling test I mentioned in the answer) – rickyviking Sep 26 '17 at 22:25