Time for action—switching between the normal and damaged Cessna

We are going to construct a scene with the osg::Switch node. It can even be used to implement state-switching animations and more complicated work, but at present we will only demonstrate how to predefine the visibilities of child nodes before the scene viewer starts.

  1. Include the necessary headers:
    #include <osg/Switch>
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    
  2. We will read two models from files and use a switch to control them. We can find a normal Cessna and a damaged one in the OSG sample data directory. They are good for simulating different states (normal/damaged) of an aircraft:
    osg::ref_ptr<osg::Node> model1= osgDB::readNodeFile("cessna.osg"); osg::ref_ptr<osg::Node> ...

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.