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

Revision 3526, 3.7 kB (checked in by robert, 10 years ago)

From Geoff Michel, speeling and typo fixes in osgUtil

  • 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.
[3526]35 * This visitor traverses the scene graph, calling each nodes appCallback if
[1435]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
[3526]47    /** During traversal each type of node calls its callbacks and its children traversed. */
[1435]48        virtual void apply(osg::Node& node)         { handle_callbacks_and_traverse(node); }
49       
50        virtual void apply(osg::Geode& node)        { handle_geode_callbacks(node); }
51        virtual void apply(osg::Billboard& node)    { handle_geode_callbacks(node); }
52       
53        virtual void apply(osg::LightSource& node)  { handle_callbacks_and_traverse(node); }
54       
55        virtual void apply(osg::Group& node)        { handle_callbacks_and_traverse(node); }
56        virtual void apply(osg::Transform& node)    { handle_callbacks_and_traverse(node); }
57        virtual void apply(osg::Projection& node)   { handle_callbacks_and_traverse(node); }
58        virtual void apply(osg::Switch& node)       { handle_callbacks_and_traverse(node); }
59        virtual void apply(osg::LOD& node)          { handle_callbacks_and_traverse(node); }
60        virtual void apply(osg::Impostor& node)     { handle_callbacks_and_traverse(node); }
61        virtual void apply(osg::OccluderNode& node) { handle_callbacks_and_traverse(node); }
62
63
64    protected:
65
[3526]66//         /** Prevent unwanted copy construction.*/
[1983]67//         UpdateVisitor(const UpdateVisitor&):osg::NodeVisitor() {}
[1435]68
[3526]69        /** Prevent unwanted copy operator.*/
[1435]70        UpdateVisitor& operator = (const UpdateVisitor&) { return *this; }
71       
72        inline void handle_callbacks_and_traverse(osg::Node& node)
73        {
74            osg::NodeCallback* callback = node.getUpdateCallback();
75            if (callback) (*callback)(&node,this);
76            else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
77        }
78
79        inline void handle_geode_callbacks(osg::Geode& node)
80        {
81            osg::NodeCallback* callback = node.getUpdateCallback();
82            if (callback) (*callback)(&node,this);
[3526]83            /*else if (node.getNumChildrenRequiringUpdateTraversal()>0)*/
84            traverseGeode(node);
[1735]85        }
86       
87        inline void traverseGeode(osg::Geode& geode)
88        {
89            traverse((osg::Node&)geode);
[1435]90           
[3526]91            // Call the app callbacks on the drawables.
[1735]92            for(unsigned int i=0;i<geode.getNumDrawables();++i)
[1435]93            {
[1735]94                osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
95                if (callback) callback->update(this,geode.getDrawable(i));
[1435]96            }
97        }
[3432]98   
[1435]99};
100
101}
102
103#endif
104
Note: See TracBrowser for help on using the browser.