Time for action—quickly creating simple objects

It is easy to create simple objects by using an osg::Shape subclass. We will take three typical shapes as examples: a box with different width, height, and depth values, a sphere with a radius value, and a cone with a radius and a height.

  1. Include necessary headers:
    #include <osg/ShapeDrawable>
    #include <osg/Geode>
    #include <osgViewer/Viewer>
  2. Add three osg::ShapeDrawable objects successively, each with a type of basic shape. We set these shapes to different positions to make them visible to viewers at the same time, and for the reason of distinguishing them from each other, we color the latter two shapes green and respectively, blue by using the setColor() method of osg::ShapeDrawable:
    osg::ref_ptr<osg::ShapeDrawable> ...

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.