root/OpenSceneGraph/trunk/include/osgAnimation/UpdateCallback @ 10701

Revision 10701, 4.2 kB (checked in by cedricpinson, 5 years ago)

From Cedric Pinson, Fix warning in osgAnimation, UpdateCallback?. Fix bug removing callback in Action. Fix warning Stats

RevLine 
[9093]1/*  -*-c++-*-
[10557]2 *  Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
[9093]3 *
4 * This library is open source and may be redistributed and/or modified under 
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * OpenSceneGraph Public License for more details.
13*/
14
15#ifndef OSGANIMATION_UPDATE_CALLBACK_H
16#define OSGANIMATION_UPDATE_CALLBACK_H
17
18#include <osg/Vec3>
19#include <osg/NodeCallback>
[10518]20#include <osg/StateAttribute>
21#include <osg/Material>
[9093]22#include <osg/observer_ptr>
[9150]23#include <osgAnimation/AnimationManagerBase>
[9094]24#include <osgAnimation/Export>
[9093]25
26namespace osgAnimation
27{
28
[10689]29    class AnimationUpdateCallbackBase : public virtual osg::Object
[9093]30    {
[10518]31    public:
32        virtual bool link(osgAnimation::Channel* channel) = 0;
33        virtual int link(osgAnimation::Animation* animation) = 0;
34    };
35
36    template <class T>
37    class AnimationUpdateCallback : public AnimationUpdateCallbackBase, public T
38    {
[9093]39    public:
[10701]40        AnimationUpdateCallback() {}
[10518]41        AnimationUpdateCallback(const std::string& name) { T::setName(name);}
42        AnimationUpdateCallback(const AnimationUpdateCallback& apc,const osg::CopyOp& copyop):
[10689]43            T(apc, copyop) {}
[10518]44
[10701]45        META_Object(osgAnimation, AnimationUpdateCallback<T>);
46
[10518]47        const std::string& getName() const { return T::getName(); }
[10701]48        bool link(osgAnimation::Channel* channel) { return 0; }
[10518]49        int link(osgAnimation::Animation* animation)
50        {
51            if (T::getName().empty())
52                osg::notify(osg::WARN) << "An update callback has no name, it means it can link only with \"\" named Target, often an error" << std::endl;
53            int nbLinks = 0;
54            for (osgAnimation::ChannelList::iterator it = animation->getChannels().begin();
55                 it != animation->getChannels().end();
56                 it++)
57            {
58                std::string targetName = (*it)->getTargetName();
59                if (targetName == T::getName())
60                {
61                    AnimationUpdateCallbackBase* a = this;
62                    a->link((*it).get());
63                    nbLinks++;
64                }
65            }
66            return nbLinks;
67        }
[9093]68    };
69
[10518]70
71
72
73    class OSGANIMATION_EXPORT UpdateTransform : public AnimationUpdateCallback<osg::NodeCallback>
[9093]74    {
75    protected:
76        osg::ref_ptr<osgAnimation::Vec3Target> _euler;
77        osg::ref_ptr<osgAnimation::Vec3Target> _position;
78        osg::ref_ptr<osgAnimation::Vec3Target> _scale;
79   
80    public:
81
82        META_Object(osgAnimation, UpdateTransform);
83
84        UpdateTransform(const std::string& name = "");
85        UpdateTransform(const UpdateTransform& apc,const osg::CopyOp& copyop);
86
87        /** Callback method called by the NodeVisitor when visiting a node.*/
88        virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
89        void update(osg::MatrixTransform& mat);
90        void update(osg::PositionAttitudeTransform& pat);
91        bool link(osgAnimation::Channel* channel);
[10557]92
93        osgAnimation::Vec3Target* getEuler() {return _euler.get();}
94        osgAnimation::Vec3Target* getPosition() {return _position.get();}
95        osgAnimation::Vec3Target* getScale() {return _scale.get();}
[9093]96    };
97
98
[10518]99
[10671]100    class OSGANIMATION_EXPORT UpdateMaterial : public AnimationUpdateCallback<osg::StateAttributeCallback>
[10518]101    {
102    protected:
103        osg::ref_ptr<osgAnimation::Vec4Target> _diffuse;
104   
105    public:
106
107        META_Object(osgAnimation, UpdateMaterial);
108
109        UpdateMaterial(const std::string& name = "");
110        UpdateMaterial(const UpdateMaterial& apc,const osg::CopyOp& copyop);
111
112        /** Callback method called by the NodeVisitor when visiting a node.*/
113        virtual void operator () (osg::StateAttribute*, osg::NodeVisitor*);
114        void update(osg::Material& material);
115        bool link(osgAnimation::Channel* channel);
[10671]116        osgAnimation::Vec4Target* getDiffuse();
[10518]117    };
118
[9093]119}
120
121#endif
Note: See TracBrowser for help on using the browser.