root/OpenSceneGraph/trunk/include/osgUtil/UpdateVisitor @ 3432

Revision 3432, 3.6 kB (checked in by robert, 10 years ago)

From Geoff Michel, typos and spelling fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[1529]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
[1435]13
14#ifndef OSGUTIL_UPDATEVISITOR
15#define OSGUTIL_UPDATEVISITOR 1
16
17#include <osg/NodeVisitor>
18#include <osg/Node>
19#include <osg/Geode>
20#include <osg/Billboard>
21#include <osg/LOD>
22#include <osg/Switch>
23#include <osg/LightSource>
24#include <osg/Transform>
25#include <osg/Projection>
26#include <osg/Impostor>
27#include <osg/OccluderNode>
28
29#include <osgUtil/Export>
30
31namespace osgUtil {
32
33/**
34 * Basic UpdateVisitor implementation for animating a scene.
35 * This visitor traverses the scene graph, call each nodes appCallback if
36 * it exists.
37 */
38class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
39{
40    public:
41
42        UpdateVisitor();
43        virtual ~UpdateVisitor();
44
45        virtual void reset();
46
47        virtual void apply(osg::Node& node)         { handle_callbacks_and_traverse(node); }
48       
49        virtual void apply(osg::Geode& node)        { handle_geode_callbacks(node); }
50        virtual void apply(osg::Billboard& node)    { handle_geode_callbacks(node); }
51       
52        virtual void apply(osg::LightSource& node)  { handle_callbacks_and_traverse(node); }
53       
54        virtual void apply(osg::Group& node)        { handle_callbacks_and_traverse(node); }
55        virtual void apply(osg::Transform& node)    { handle_callbacks_and_traverse(node); }
56        virtual void apply(osg::Projection& node)   { handle_callbacks_and_traverse(node); }
57        virtual void apply(osg::Switch& node)       { handle_callbacks_and_traverse(node); }
58        virtual void apply(osg::LOD& node)          { handle_callbacks_and_traverse(node); }
59        virtual void apply(osg::Impostor& node)     { handle_callbacks_and_traverse(node); }
60        virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
61
62
63    protected:
64
[1983]65//         /** prevent unwanted copy construction.*/
66//         UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
[1435]67
68        /** prevent unwanted copy operator.*/
69        UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
70       
71        inline void handle_callbacks_and_traverse(osg::Node& node)
72        {
73            osg::NodeCallback* callback = node.getUpdateCallback();
74            if (callback) (*callback)(&node,this);
75            else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
76        }
77
78        inline void handle_geode_callbacks(osg::Geode& node)
79        {
80            osg::NodeCallback* callback = node.getUpdateCallback();
81            if (callback) (*callback)(&node,this);
[2313]82            /*else if (node.getNumChildrenRequiringUpdateTraversal()>0)*/ traverseGeode(node);
[1735]83        }
84       
85        inline void traverseGeode(osg::Geode& geode)
86        {
87            traverse((osg::Node&)geode);
[1435]88           
89            // call the app callbacks on the drawables.
[1735]90            for(unsigned int i=0;i<geode.getNumDrawables();++i)
[1435]91            {
[1735]92                osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
93                if (callback) callback->update(this,geode.getDrawable(i));
[1435]94            }
95        }
[3432]96   
[1435]97};
98
99}
100
101#endif
102
Note: See TracBrowser for help on using the browser.