2

So I am trying to create a mini-map/PIP. I have an existing program with scene that runs inside a Qt Widget. I have a class, NetworkViewer, which extends CompositeViewer. In NetworkViewer's constructor I call the following function. Notice the root is the scene which is populated elsewhere.


void NetworkViewer::init() {
  root = new osg::Group() ;

  viewer = new osgViewer::View( );
  viewer->setSceneData( root ) ;

  osg::Camera* camera ;
  camera = createCamera(0,0,100,100) ;
  viewer->setCamera( camera );
  viewer->addEventHandler( new NetworkGUIHandler( (GUI*)view ) ) ;
  viewer->setCameraManipulator(new osgGA::TrackballManipulator) ;
  viewer->getCamera()->setClearColor(
    osg::Vec4( LIGHT_CLOUD_BLUE_F,0.0f));
  addView( viewer );

  osgQt::GraphicsWindowQt* gw =
    dynamic_cast( camera->getGraphicsContext() );
  QWidget* widget = gw ? gw->getGLWidget() : NULL;

  QGridLayout* grid = new QGridLayout( ) ;
  grid->addWidget( widget );
  grid->setSpacing(1);
  grid->setMargin(1);
  setLayout( grid );

  initHUD( ) ;
}

The create camera function is as follows:

osg::Camera* createCamera( int x, int y, int w, int h ) {
  osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
  osg::ref_ptr traits
    = new osg::GraphicsContext::Traits;
  traits->windowName = "" ;
  traits->windowDecoration = false ;
  traits->x = x;
  traits->y = y;
  traits->width = w;
  traits->height = h;
  traits->doubleBuffer = true;
  traits->alpha = ds->getMinimumNumAlphaBits();
  traits->stencil = ds->getMinimumNumStencilBits();
  traits->sampleBuffers = ds->getMultiSamples();
  traits->samples = ds->getNumMultiSamples();

  osg::ref_ptr camera = new osg::Camera;
  camera->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );

  camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
  camera->setViewMatrix(osg::Matrix::translate(-10.0f,-10.0f,-30.0f));
  camera->setProjectionMatrixAsPerspective(
    20.0f,
    static_cast(traits->width)/static_cast(traits->height),
    1.0f, 10000.0f );
  return camera.release();
}

I have been looking at several camera examples and searching for a solution for a while to no avail. What I am really looking for is the background being my main camera which takes up most of the screen and displays the scene graph while my mini-map appears in the bottom right. It has the same scene as the main camera but is overlaid on top of it and has its own set of controls for selection etc since it will have different functionality.

I was thinking that perhaps by adding another camera as a slave I would be able to do this:

      camera = createCamera(40,40,50,50) ;
      viewer->addSlave(camera) ;

But this doesn't seem to work. If I disable the other camera I do see a clear area that it appears this camera was suppose to be rendering in (its viewport) but that doesn't help. I've played around with rendering order thinking it could be that to no avail.

Any ideas? What it the best way to do such a minimap is? What am I doing wrong? Also anyway to make the rendering of the minimap circular instead of rectangular?

genpfault
  • 51,148
  • 11
  • 85
  • 139
David Mokon Bond
  • 1,576
  • 2
  • 18
  • 42

1 Answers1

0

I am not personnally using OpenSceneGraph, so I can't advise you on your code. I think the best is to ask in the official forums. But I have some ideas on the minimap:

First, you have to specify the basic features of your minimap. Do you want it to emphasize some elements of the scene, or just show the scene (ie, RTS-like minimap vs simple top-show of the scene) ?

I assume you do not want to emphasize some elements of the scene. I also assume your main camera is not really 'minimap-friendly'. So, the simplest is to create a camera with the following properties:

  • direction = (0,-1,0) (Y is the vertical axis)
  • mode = orthographic
  • position = controlled by what you want, for example your main camera

Now, for the integration of the image. You can:

  • set the viewport of the minimap camera to what you want, if your minimap is rectangular.
  • render the minimap to a texture (RTT) and then blend it through an extra rendering pass.

You can also search other engines forums (like Irrlicht and Ogre) to see how they're doing minimaps.

Synxis
  • 9,236
  • 2
  • 42
  • 64
  • Thanks, I did ask on the official forums before here, but unfortunately there were no responses. – David Mokon Bond Nov 13 '12 at 04:21
  • I'm afraid the only thing is to see how people do it with other engines. You can also search in games (but remember there are several different types of minimap). – Synxis Nov 13 '12 at 17:34