The goal here is easy to understand but not easy to achieve. It requires exactly another book to tell how to make a realistic enough car model and load it into the scene graph efficiently, as well as how to assemble components and have the wheels rotating. So we have to simplify the problem here—we are going to implement some very ugly car parts only with basic shapes, and demonstrate the use of the scene graph in the assembly process.
All we need to do here is use the transformation node, which is one the most basic classes in the OSG library. But it is not easy to be skillful with it.
1. Include necessary headers:
#include <osg/ShapeDrawable> #include <osg/AnimationPath> #include <osg/MatrixTransform> #include <osgDB/ReadFile> #include <osgViewer/Viewer>
2. The convenient function
createTransformNode()
will create a transformation node for every part shape we have:osg::MatrixTransform* createTransformNode( osg::Drawable...