root/OpenSceneGraph/trunk/src/osgUtil/TransformCallback.cpp @ 13041

Revision 13041, 2.2 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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*/
13#include <osg/MatrixTransform>
14
15#include <osgUtil/TransformCallback>
16
17using namespace osgUtil;
18
19TransformCallback::TransformCallback(const osg::Vec3& pivot,const osg::Vec3& axis,float angularVelocity)
20{
21    _pivot = pivot;
22    _axis = axis;
23    _angular_velocity = angularVelocity;
24
25    _previousTraversalNumber = osg::UNINITIALIZED_FRAME_NUMBER;
26    _previousTime = -1.0;
27
28    _pause = false;
29}
30
31void TransformCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
32{
33    osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node);
34    if (nv && transform)
35    {
36
37        const osg::FrameStamp* fs = nv->getFrameStamp();
38        if (!fs) return; // not frame stamp, no handle on the time so can't move.
39
40        double newTime = fs->getSimulationTime();
41
42        // ensure that we do not operate on this node more than
43        // once during this traversal.  This is an issue since node
44        // can be shared between multiple parents.
45        if (!_pause && nv->getTraversalNumber()!=_previousTraversalNumber)
46        {
47            float delta_angle = _angular_velocity*(newTime-_previousTime);
48
49            osg::Matrix mat = osg::Matrix::translate(-_pivot)*
50                              osg::Matrix::rotate(delta_angle,_axis)*
51                              osg::Matrix::translate(_pivot);
52
53
54            // update the specified transform
55            transform->preMult(mat);
56
57            _previousTraversalNumber = nv->getTraversalNumber();
58        }
59
60        _previousTime = newTime;
61
62    }
63
64    // must call any nested node callbacks and continue subgraph traversal.
65    traverse(node,nv);
66
67}
Note: See TracBrowser for help on using the browser.