Time for action—switching nodes in the update traversal
Do you remember that we have designed an animated switch node in Chapter 5, Managing Scene Graph? It is derived from osg::Switch
, but will automatically change the states of its first two children according to an internal counter, through overriding the traverse()
virtual method.
Now we would like to redo the same task, but this time using the update callback mechanism. This requires customizing a new class derived from the osg::NodeCallback
base class, and overriding the operator()
to perform the execution in the callback implementaton.
- Include the necessary headers:
#include <osg/Switch> #include <osgDB/ReadFile> #include <osgViewer/Viewer>
- Declare the
SwitchingCallback
class. It is anosg::NodeCallback ...
Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.