Time for action—performing translations of child nodes

Now we are going to make use of the transformation node. The osg::MatrixTransform node, which multiplies the current model-view matrix with a specified one directly, will help to transfer our model to different places in the viewing space.

  1. Include the necessary headers:
    #include <osg/MatrixTransform>
    #include <osgDB/ReadFile>
    #include <osgViewer/Viewer>
    
  2. Load the Cessna model first:
    osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( "cessna.osg" );
    
  3. The osg::MatrixTransform class is derived from osg::Group, so it can use the addChild() method to add more children. All child nodes will be affected by the osg::MatrixTransform node and be transformed according to the presetting matrix. Here, we ...

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.