root/OpenSceneGraph/trunk/src/osgAnimation/UpdateMatrixTransform.cpp @ 11034

Revision 11034, 2.6 kB (checked in by robert, 4 years ago)

Build fixes for build without ref_ptr<> automatic type conversion

RevLine 
[11009]1/*  -*-c++-*-
2 *  Copyright (C) 2009 Cedric Pinson <cedric.pinson@plopbyte.net>
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#include <osgAnimation/UpdateMatrixTransform>
16#include <osg/NodeVisitor>
17#include <osg/MatrixTransform>
18
19using namespace osgAnimation;
20
21UpdateMatrixTransform::UpdateMatrixTransform( const UpdateMatrixTransform& apc,const osg::CopyOp& copyop) : osg::Object(apc,copyop), AnimationUpdateCallback<osg::NodeCallback>(apc, copyop)
22{
23    _transforms = StackedTransform(apc.getStackedTransforms(), copyop);
24}
25
26UpdateMatrixTransform::UpdateMatrixTransform(const std::string& name) : AnimationUpdateCallback<osg::NodeCallback>(name)
27{
28}
29
30/** Callback method called by the NodeVisitor when visiting a node.*/
31void UpdateMatrixTransform::operator()(osg::Node* node, osg::NodeVisitor* nv)
32{
33    if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
34    {
35        osg::MatrixTransform* matrixTransform = dynamic_cast<osg::MatrixTransform*>(node);
36        if (matrixTransform)
37        {
38            // here we would prefer to have a flag inside transform stack in order to avoid update and a dirty state in matrixTransform if it's not require.
39            _transforms.update();
40            const osg::Matrix& matrix = _transforms.getMatrix();
41            matrixTransform->setMatrix(matrix);
42        }
43    }
44    traverse(node,nv);
45}
46
47
48bool UpdateMatrixTransform::link(osgAnimation::Channel* channel)
49{
50    const std::string& channelName = channel->getName();
51   
52    // check if we can link a StackedTransformElement to the current Channel
53    for (StackedTransform::iterator it = _transforms.begin(); it != _transforms.end(); ++it)
54    {
[11034]55        StackedTransformElement* element = it->get();
[11009]56        if (element && !element->getName().empty() && channelName == element->getName())
57        {
58            Target* target = element->getOrCreateTarget();
59            if (target && channel->setTarget(target))
60                return true;
61        }
62    }
63
64    osg::notify(osg::INFO) << "UpdateMatrixTransform::link Channel " << channel->getName() << " does not contain a symbolic name that can be linked to a StackedTransformElement." << std::endl;
65
66    return false;
67}
Note: See TracBrowser for help on using the browser.