2001-10-04 23:12:57 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-09-20 07:41:39 +08:00
|
|
|
#ifndef OSGUTIL_APPVISITOR
|
|
|
|
#define OSGUTIL_APPVISITOR 1
|
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Geode>
|
|
|
|
#include <osg/Billboard>
|
|
|
|
#include <osg/LOD>
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/LightSource>
|
|
|
|
#include <osg/Transform>
|
2002-04-15 21:15:48 +08:00
|
|
|
#include <osg/Projection>
|
2001-09-20 07:41:39 +08:00
|
|
|
#include <osg/Impostor>
|
2002-06-12 02:41:57 +08:00
|
|
|
#include <osg/OccluderNode>
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#include <osgUtil/Export>
|
|
|
|
|
|
|
|
namespace osgUtil {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basic AppVisitor implementation for animating a scene.
|
|
|
|
* This visitor traverses the scene graph, call each nodes appCallback if
|
|
|
|
* it exists.
|
|
|
|
*/
|
|
|
|
class OSGUTIL_EXPORT AppVisitor : public osg::NodeVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AppVisitor();
|
|
|
|
virtual ~AppVisitor();
|
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
|
2001-09-20 07:41:39 +08:00
|
|
|
|
2002-06-12 02:41:57 +08:00
|
|
|
virtual void apply(osg::Group& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Transform& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Projection& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Switch& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::LOD& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::Impostor& node) { handle_callbacks_and_traverse(node); }
|
|
|
|
virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/** prevent unwanted copy construction.*/
|
|
|
|
AppVisitor(const AppVisitor&):osg::NodeVisitor() {}
|
|
|
|
|
|
|
|
/** prevent unwanted copy operator.*/
|
|
|
|
AppVisitor& operator = (const AppVisitor&) { return *this; }
|
|
|
|
|
2002-04-15 21:15:48 +08:00
|
|
|
inline void handle_callbacks_and_traverse(osg::Node& node)
|
2001-09-20 07:41:39 +08:00
|
|
|
{
|
|
|
|
osg::NodeCallback* callback = node.getAppCallback();
|
|
|
|
if (callback) (*callback)(&node,this);
|
|
|
|
else if (node.getNumChildrenRequiringAppTraversal()>0) traverse(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 07:41:39 +08:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|