-1

I would like to run this pseudo-code with OpenSceneGraph:

while (!done) {
  addNodeToSceneGraph();
  displayCurrentSceneGraph();
  waitForKeyPressed();
}

How can I implement it, preferably using the standard OSG API?

EDIT

Here is a concrete example:

int main() {
  osgViewer::Viewer viewer;
  osg::Geode*       geode = new osg::Geode();

  viewer.setSceneData(geode);
  geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0, 0, 0), 1)));

  viewer.frame();
  this_thread::sleep_for(seconds(2));

  geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(2, 0, 0), 1)));
  
  return viewer.run();
}

I would like the call to viewer.frame() above, display the first sphere and after 2s the second sphere would get displayed. It displays a blank screen for 2s instead. What do I have to change?

Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72

1 Answers1

0

Calling setCameraManipulator() solves the problem (see https://groups.google.com/g/osg-users/c/ToHowfxKbvE). This code snippet produces the intended result:

int main() {
  osgViewer::Viewer viewer;
  osg::Geode*       geode = new osg::Geode();

  viewer.setCameraManipulator(new osgGA::TrackballManipulator());   
  viewer.setSceneData(geode);
  geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0, 0, 0), 1)));

  viewer.frame();
  this_thread::sleep_for(seconds(2));

  geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(2, 0, 0), 1)));
  
  return viewer.run();
}
Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72