|
Revision 6051, 1.5 kB
(checked in by robert, 6 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
|
| Line | |
|---|
| 1 | #include <osg/MatrixTransform> |
|---|
| 2 | |
|---|
| 3 | #include "ShuttleCallback.h" |
|---|
| 4 | |
|---|
| 5 | ShuttleCallback::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 | |
|---|
| 18 | void 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 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | if (nv->getTraversalNumber()!=_previousTraversalNumber) |
|---|
| 35 | { |
|---|
| 36 | double currentTime = fs->getSimulationTime(); |
|---|
| 37 | _angle += (currentTime - _previousTime) * 2 * osg::PI * _frequency; |
|---|
| 38 | |
|---|
| 39 | double frac = 0.5 + 0.5 * sin(_angle); |
|---|
| 40 | |
|---|
| 41 | osg::Vec3 position = _startPos * (1.0 - frac) + _endPos * frac; |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | transform->setMatrix(osg::Matrix::translate(position)); |
|---|
| 45 | |
|---|
| 46 | _previousTraversalNumber = nv->getTraversalNumber(); |
|---|
| 47 | _previousTime = currentTime; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | traverse(node,nv); |
|---|
| 52 | |
|---|
| 53 | } |
|---|