Time for action—creating a user timer

A timer event is emitted whenever the internal counter reaches a specified interval. This is common in various GUI systems, and allows users to set a customized timer callback to receive the timing message and implement related operations.

Now we are able to realize the same work in OSG. As there are no standard timer events defined in the osgGA::GUIEventAdapter class, we have to make use of the USER event type, as well as an additional data pointer.

  1. Include the necessary headers:
    #include <osg/Switch>
    #include <osgDB/ReadFile>
    #include <osgGA/GUIEventHandler>
    #include <osgViewer/Viewer>
    #include <iostream>
    
  2. A TimerInfo structure is first defined to manage the parameters (mainly the trigger time of the timer) ...

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.