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

Revision 11032, 1.5 kB (checked in by robert, 4 years ago)

From Jan Peciva, "I am sending improved version of Inventor plugin. Attaching just
modified files, while GroupSoLOD.h and .cpp was deleted. Please, delete
it from repository, it is not used any longer and I doubt if it is
probably not used for anything meaningful for a while. In the new code,
there is no GroupSoLOD. Please, delete it.

I am using new plugin version for about 1.5 month so I consider it
stable by myself.

List of changes:
- rewritten Inventor state stack
- shaders support
- light attenuation support
- support for reading from stream (readNode(std::istream& fin, options))
- improved grouping node handling (SoSeparator?, SoGroup?,...)
- fixed transformation bug when two SoShapes/Drawables? with different transformations are placed bellow one grouping node
- introduced preprocessing to handle more advanced usage schemes of SoLOD and SoSwitch? nodes
- unused code clean up
- improved notify messages
- animation callbacks fixes
- FindInventor?.cmake improved finding routines, support for Coin3 and Coin4"

  • 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
[11032]5ShuttleCallback::ShuttleCallback(const osg::Vec3& startPos,
[2225]6                                 const osg::Vec3& endPos,
7                                 float frequency)
8{
9    _startPos = startPos;
10    _endPos = endPos;
11    _frequency = frequency;
[11032]12
[2225]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();
[11032]28    if (!fs)
29        return;
30
[2225]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();
[11032]37        if (_previousTime == -1.)
38            _previousTime = currentTime;
[2915]39        _angle += (currentTime - _previousTime) * 2 * osg::PI * _frequency;
[2225]40
[11032]41        double frac = 0.5 - 0.5 * cos(_angle);
42
[2225]43        osg::Vec3 position = _startPos * (1.0 - frac) + _endPos * frac;
44
45        // update the specified transform
46        transform->setMatrix(osg::Matrix::translate(position));
[11032]47
[2225]48        _previousTraversalNumber = nv->getTraversalNumber();
49        _previousTime = currentTime;
50    }
51
52    // must call any nested node callbacks and continue subgraph traversal.
53    traverse(node,nv);
54
55}
Note: See TracBrowser for help on using the browser.