root/OpenSceneGraph/trunk/src/osgPlugins/Inventor/ShuttleCallback.cpp @ 6051

Revision 6051, 1.5 kB (checked in by robert, 8 years ago)

Added osg::FrameStamp::set/getSimulationTime().

Added setting of osg_SimulationTime and osg_DeltaSimulationTime to the uniforms set by SceneView?

Added frame(double simulationTime) and advance(double simulationTime) parameters to
osgViewer::SimpleViewer?, Vewer and CompositeViewer?.

Updated various examples and Nodes to use SimulationTime? where appropriate.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[2225]1#include <osg/MatrixTransform>
2
3#include "ShuttleCallback.h"
4
5ShuttleCallback::ShuttleCallback(const osg::Vec3& startPos,
6                                 const osg::Vec3& endPos,
7                                 float frequency)
8{
9    _startPos = startPos;
10    _endPos = endPos;
11    _frequency = frequency;
12   
13    _previousTraversalNumber = -1;
14    _previousTime = -1.0;
15    _angle = 0.0;
16}
17
18void ShuttleCallback::operator() (osg::Node* node, osg::NodeVisitor* nv)
19{
20    if (!nv)
21        return;
22
23    osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node);
24    if (!transform)
25        return;
26
27    const osg::FrameStamp* fs = nv->getFrameStamp();
28    if (!fs)
29        return;
30   
31    // ensure that we do not operate on this node more than
32    // once during this traversal.  This is an issue since node
33    // can be shared between multiple parents.
34    if (nv->getTraversalNumber()!=_previousTraversalNumber)
35    {
[6051]36        double currentTime = fs->getSimulationTime();
[2915]37        _angle += (currentTime - _previousTime) * 2 * osg::PI * _frequency;
[2225]38       
39        double frac = 0.5 + 0.5 * sin(_angle);
40
41        osg::Vec3 position = _startPos * (1.0 - frac) + _endPos * frac;
42
43        // update the specified transform
44        transform->setMatrix(osg::Matrix::translate(position));
45           
46        _previousTraversalNumber = nv->getTraversalNumber();
47        _previousTime = currentTime;
48    }
49
50    // must call any nested node callbacks and continue subgraph traversal.
51    traverse(node,nv);
52
53}
Note: See TracBrowser for help on using the browser.