From 6ea4f4a9391926839462fb12a025ae6107e3ba8e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Jun 2014 15:05:51 +0000 Subject: [PATCH] From Pjotr Sventachov and Robert Osfield, added callback unit test to osgcallback example, to use test run osgcallback --test, if everything is functioning then test1 to test7 messages should be reported to the console. --- examples/osgcallback/osgcallback.cpp | 133 +++++++++++++++++++++------ 1 file changed, 107 insertions(+), 26 deletions(-) diff --git a/examples/osgcallback/osgcallback.cpp b/examples/osgcallback/osgcallback.cpp index de5d264e9..d148fea24 100644 --- a/examples/osgcallback/osgcallback.cpp +++ b/examples/osgcallback/osgcallback.cpp @@ -38,7 +38,7 @@ class UpdateCallback : public osg::NodeCallback { virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { + { std::cout<<"update callback - pre traverse"<setDrawCallback(new DrawableDrawCallback()); } } - + virtual void apply(osg::Transform& node) { apply((osg::Node&)node); @@ -140,7 +140,7 @@ public: class CameraUpdateCallback : public osg::NodeCallback { virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) - { + { std::cout<<"Camera update callback - pre traverse"<setReadFileCallback(new MyReadFileCallback()); - + // initialize the viewer. osgViewer::Viewer viewer; // load the nodes from the commandline arguments. - osg::Node* rootnode = osgDB::readNodeFiles(arguments); + osg::ref_ptr rootnode; - // if not loaded assume no arguments passed in, try use default mode instead. - if (!rootnode) rootnode = osgDB::readNodeFile("cow.osgt"); - - if (!rootnode) + if (arguments.read("--test")) { - osg::notify(osg::NOTICE)<<"Please specify a file on the command line"< root = new osg::Group(); + rootnode = root; + + osg::Node *test1 = new osg::Node(); + test1->setUpdateCallback(new TestNodeUpdateCallback("test1")); + root->addChild(test1); + + osg::Drawable *test2 = new osg::Drawable(); + test2->osg::Node::setUpdateCallback(new TestNodeUpdateCallback("test2")); + root->addChild(test2); + + osg::Drawable *test3 = new osg::Drawable(); + test3->setUpdateCallback(new TestDrawableUpdateCallback("test3")); + root->addChild(test3); + + osg::Geode *test4 = new osg::Geode(); + osg::Drawable *drawable1 = new osg::Drawable(); + drawable1->osg::Node::setUpdateCallback(new TestNodeUpdateCallback("test4")); + test4->addDrawable(drawable1); + root->addChild(test4); + + osg::Geode *test5 = new osg::Geode(); + osg::Drawable *drawable2 = new osg::Drawable(); + drawable2->setUpdateCallback(new TestDrawableUpdateCallback("test5")); + test5->addDrawable(drawable2); + root->addChild(test5); + + osg::Geode *test6 = new osg::Geode(); + osg::Drawable *drawable3 = new osg::Drawable(); + drawable3->setUpdateCallback(new TestDrawableUpdateCallback("test6")); + test6->addChild(drawable3); + root->addChild(test6); + + osg::Geode *test7 = new osg::Geode(); + osg::Drawable *drawable4 = new osg::Drawable(); + drawable4->osg::Node::setUpdateCallback(new TestNodeUpdateCallback("test7")); + test7->addChild(drawable4); + root->addChild(test7); + + printf("Numchildren with updates %u\n", rootnode->getNumChildrenRequiringUpdateTraversal()); - return 1; } - - // run optimization over the scene graph - osgUtil::Optimizer optimzer; - optimzer.optimize(rootnode); - - // insert all the callbacks - InsertCallbacksVisitor icv; - rootnode->accept(icv); + else + { + rootnode = osgDB::readNodeFiles(arguments); + + // if not loaded assume no arguments passed in, try use default mode instead. + if (!rootnode) rootnode = osgDB::readNodeFile("cow.osgt"); + + if (!rootnode) + { + osg::notify(osg::NOTICE)<<"Please specify a file on the command line"<accept(icv); + } viewer.getCamera()->setUpdateCallback(new CameraUpdateCallback()); viewer.getCamera()->setEventCallback(new CameraEventCallback()); @@ -195,5 +266,15 @@ int main( int argc, char **argv ) // set the scene to render viewer.setSceneData(rootnode); - return viewer.run(); + viewer.setCameraManipulator(new osgGA::TrackballManipulator); + + viewer.realize(); + + while(!viewer.done()) + { + OSG_NOTICE<