Hello Ronald,

> Is there an easy to way to do this job?

Well, using an update callback as in the tutorial would probably do it, is it
not easy enough?

i.e.

class MyUpdateCallback : public osg::NodeCallback
{
    public:
        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
        {
            // Do whatever work you need to do here. Any data you may need
            // could either be passed to the constructor of the
            // MyUpdateCallback class and stored as protected data inside,
            // or stored as user data on the node you need to use it on.

            // If you want to add/remove nodes in the graph for example, you
            // could have methods that add nodes into vectors "_nodesToAdd"
            // and "_nodesToRemove" and then the operator() would do the
            // actual additions and removals, to make sure they happen during
            // the update traversal.

            // ...

            // This is needed to make sure other callbacks in the graph get
            // called as well.
            traverse(node, nv);
        }
};


int main(int argc, char** argv)
{
    // ...

    // Either create a class that derives from osg::Referenced to store the data
    // you need, and then attach it to the node:
    osg::ref_ptr<osg::Referenced> someUserData = new SomeUserData;
    myNode->setUserData(someUserData.get());
    // Or just pass the data to the callback's constructor.

    // Then, add the callback to the node.
    myNode->setUpdateCallback(new MyUpdateCallback(...));

    // ...
}


> And, the code link on
> http://www.openscenegraph.org/documentation/NPSTutorials/osgUpdate.htm
>   is broken now.

Seems so. Those are pretty old tutorials and it seems that various parts are
becoming broken (even discounting the fact that they were written for OSG 1.2).
It also seems that the equivalent page on the new wiki is also missing the code.
See:

http://www.openscenegraph.org/projects/osg/wiki/Support/Tutorials/Callbacks

But still, from the code on the page, you will probably be able to see what's
going on and be able to adapt that to your needs.

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [EMAIL PROTECTED]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to