On 08/01/2011 11:05 AM, Martin Haffner wrote:
Hi,

I have problems with understanding the use of a NodeCallback.

Can anyone explain me what a Nodecallback is doing?

A NodeCallback is a class that implements a method ( operator() ), which is called when a particular traversal (update, cull, draw, event, etc) reaches that node in the scene. These traversals are run every time a new frame is drawn.


Another concrete question:
I have some code with a class that derives from osg::Nodecallback. This class 
implements operator():

Code:

class CameraUpdateCallback : public osg::NodeCallback {
private:
     osg::ref_ptr<osg::Camera>            mOtherCam;

     public:
         CameraUpdateCallback(osg::Camera* otherCam) : mOtherCam(otherCam) {   }

     osg::ref_ptr<osg::Camera>            m_sourceCamera;
     void operator()(osg::Node* node, osg::NodeVisitor* nv) {
             osg::Camera* cam = static_cast<osg::Camera*>( node );

             cam->setViewMatrix(mOtherCam->getViewMatrix() );
             cam->setProjectionMatrix(mOtherCam->getProjectionMatrix() );

             traverse(node , nv);
      }

...
camera->setUpdateCallback( new CameraUpdateCallback( currentView->getCamera() ) 
);

While I don't really understand the purpose of this code, I can tell you that this is defining a callback that seems to be setting the view and projection matrices of an osg::Camera (camera) to be equal to those of another osg::Camera (otherCam). The callback is attached to camera and will be run during the update traversal ( setUpdateCallback() ).

NodeCallbacks and traversals are fundamental operations of OSG (and most other scene graphs as well). If you aren't grasping them from my brief description, I'd recommend checking out the OSG Quick Start Guide, which explains them in a bit more depth.

--"J"

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to