###########################################
Creating a Viewpoint and Visualizing Shapes
###########################################

.. code:: cpp

    // Create a viewpoint directly, using the RED::Factory:
    RED::Object* viewpoint = RED::Factory::CreateInstance( CID_REDViewpoint );
    if( !viewpoint )
        RC_TEST( RED_ALLOC_FAILURE );

    // Add shapes to visualize ('iresmgr' is our RED::IResourceManager interface, 'shape' is a RED::Object shape):
    RED::IViewpoint* iviewpoint = viewpoint->As< RED::IViewpoint >();
    RC_TEST( iviewpoint->AddShape( shape, iresmgr->GetState() ) );

The viewpoint is created directly from the ``RED::Factory``. Shapes can be added to it simply using ``RED::IViewpoint::AddShape``. Please note that performing this operation is similar to adding the shape to the scene graph root instead:

.. code:: cpp

    // Same operation, but accessing the scene graph root first:
    RED::Object* root;
    RC_TEST( iviewpoint->GetRootShape( root ) );
    RED::ITransformShape* itroot = root->As< RED::ITransformShape >();
    RC_TEST( itroot->AddChild( shape, RED_SHP_DAG_NO_UPDATE, iresmgr->GetState() ) );

A viewpoint always own a scene graph root. The scene graph structure that is visualized by a viewpoint is attached to its root. The ``RED::IViewpoint::AddShape`` and ``RED::IViewpoint::RemoveShape`` methods are convenient helpers to manage the scene graph structure. More advanced functions on the scene graph can be gained by accessing the root shape directly. 