diff --git a/examples/osgclip/osgclip.cpp b/examples/osgclip/osgclip.cpp index d88b9eb95..420897e76 100644 --- a/examples/osgclip/osgclip.cpp +++ b/examples/osgclip/osgclip.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include @@ -65,7 +64,7 @@ osg::Node* decorate_with_clip_node(osg::Node* subgraph) osg::MatrixTransform* transform= new osg::MatrixTransform; - osg::NodeCallback* nc = new osgUtil::TransformCallback(subgraph->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); + osg::NodeCallback* nc = new osg::AnimationPathCallback(subgraph->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); transform->setUpdateCallback(nc); osg::ClipNode* clipnode = new osg::ClipNode; diff --git a/examples/osgdepthshadow/osgdepthshadow.cpp b/examples/osgdepthshadow/osgdepthshadow.cpp index 020fc2f64..35c1247f7 100644 --- a/examples/osgdepthshadow/osgdepthshadow.cpp +++ b/examples/osgdepthshadow/osgdepthshadow.cpp @@ -18,8 +18,6 @@ #include #include -#include - #include #include @@ -137,13 +135,13 @@ ref_ptr _create_scene() ref_ptr geode_2 = new Geode; ref_ptr transform_2 = new MatrixTransform; transform_2->addChild(geode_2.get()); - transform_2->setUpdateCallback(new osgUtil::TransformCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(45.0f))); + transform_2->setUpdateCallback(new osg::AnimationPathCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(45.0f))); scene->addChild(transform_2.get()); ref_ptr geode_3 = new Geode; ref_ptr transform_3 = new MatrixTransform; transform_3->addChild(geode_3.get()); - transform_3->setUpdateCallback(new osgUtil::TransformCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(-22.5f))); + transform_3->setUpdateCallback(new osg::AnimationPathCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(-22.5f))); scene->addChild(transform_3.get()); const float radius = 0.8f; diff --git a/examples/osgdistortion/osgdistortion.cpp b/examples/osgdistortion/osgdistortion.cpp index 99fe67ecf..3b701d879 100644 --- a/examples/osgdistortion/osgdistortion.cpp +++ b/examples/osgdistortion/osgdistortion.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/examples/osglauncher/osglauncher.cpp b/examples/osglauncher/osglauncher.cpp index 3e88ce283..3ea5be335 100644 --- a/examples/osglauncher/osglauncher.cpp +++ b/examples/osglauncher/osglauncher.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include diff --git a/examples/osglogo/osglogo.cpp b/examples/osglogo/osglogo.cpp index 3af0be897..22d681ca3 100644 --- a/examples/osglogo/osglogo.cpp +++ b/examples/osglogo/osglogo.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -190,7 +189,7 @@ osg:: Node* createTextLeft(const osg::BoundingBox& bb) osg:: Node* createGlobe(const osg::BoundingBox& bb,float ratio, const std::string& filename) { osg::MatrixTransform* xform = new osg::MatrixTransform; - xform->setUpdateCallback(new osgUtil::TransformCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(10.0f))); + xform->setUpdateCallback(new osg::AnimationPathCallback(bb.center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(10.0f))); osg::Node* bluemarble = osgDB::readNodeFile(filename.c_str()); if (bluemarble) diff --git a/examples/osgpbuffer/osgpbuffer.cpp b/examples/osgpbuffer/osgpbuffer.cpp index 66a52e950..b76c132d6 100644 --- a/examples/osgpbuffer/osgpbuffer.cpp +++ b/examples/osgpbuffer/osgpbuffer.cpp @@ -18,7 +18,6 @@ #include #include -#include class PBufferTexture2D : public osg::Texture2D @@ -239,7 +238,7 @@ osg::ref_ptr buildSceneGraphAndSetCameraViews(osg::Node *loadedModel, osg::ref_ptr loadedModelTransform = new osg::MatrixTransform; loadedModelTransform->addChild(loadedModel); - osg::ref_ptr nc = new osgUtil::TransformCallback( + osg::ref_ptr nc = new osg::AnimationPathCallback( loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); loadedModelTransform->setUpdateCallback(nc.get()); @@ -269,7 +268,7 @@ osg::ref_ptr buildSceneGraph(osg::Node *loadedModel, Producer::Render osg::ref_ptr loadedModelTransform = new osg::MatrixTransform; loadedModelTransform->addChild(loadedModel); - osg::ref_ptr nc = new osgUtil::TransformCallback( + osg::ref_ptr nc = new osg::AnimationPathCallback( loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); loadedModelTransform->setUpdateCallback(nc.get()); diff --git a/examples/osgprerender/osgprerender.cpp b/examples/osgprerender/osgprerender.cpp index fc50c0c32..ec0991d45 100644 --- a/examples/osgprerender/osgprerender.cpp +++ b/examples/osgprerender/osgprerender.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -450,7 +449,7 @@ int main( int argc, char **argv ) osg::MatrixTransform* loadedModelTransform = new osg::MatrixTransform; loadedModelTransform->addChild(loadedModel); - osg::NodeCallback* nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); + osg::NodeCallback* nc = new osg::AnimationPathCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); loadedModelTransform->setUpdateCallback(nc); osg::Group* rootNode = new osg::Group(); diff --git a/examples/osgprerendercubemap/osgprerendercubemap.cpp b/examples/osgprerendercubemap/osgprerendercubemap.cpp index 011251820..657503598 100644 --- a/examples/osgprerendercubemap/osgprerendercubemap.cpp +++ b/examples/osgprerendercubemap/osgprerendercubemap.cpp @@ -19,8 +19,6 @@ #include #include -#include - #include #include @@ -36,13 +34,13 @@ ref_ptr _create_scene() ref_ptr geode_2 = new Geode; ref_ptr transform_2 = new MatrixTransform; transform_2->addChild(geode_2.get()); - transform_2->setUpdateCallback(new osgUtil::TransformCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(45.0f))); + transform_2->setUpdateCallback(new osg::AnimationPathCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(45.0f))); scene->addChild(transform_2.get()); ref_ptr geode_3 = new Geode; ref_ptr transform_3 = new MatrixTransform; transform_3->addChild(geode_3.get()); - transform_3->setUpdateCallback(new osgUtil::TransformCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(-22.5f))); + transform_3->setUpdateCallback(new osg::AnimationPathCallback(Vec3(0, 0, 0), Y_AXIS, inDegrees(-22.5f))); scene->addChild(transform_3.get()); const float radius = 0.8f; diff --git a/examples/osgreflect/osgreflect.cpp b/examples/osgreflect/osgreflect.cpp index 5f61749ce..fa10496e3 100644 --- a/examples/osgreflect/osgreflect.cpp +++ b/examples/osgreflect/osgreflect.cpp @@ -20,8 +20,7 @@ #include #include #include - -#include +#include #include #include @@ -382,7 +381,7 @@ int main( int argc, char **argv ) osg::ref_ptr loadedModelTransform = new osg::MatrixTransform; loadedModelTransform->addChild(loadedModel.get()); - osg::ref_ptr nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); + osg::ref_ptr nc = new osg::AnimationPathCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f)); loadedModelTransform->setUpdateCallback(nc.get()); diff --git a/examples/osgscalarbar/osgscalarbar.cpp b/examples/osgscalarbar/osgscalarbar.cpp index 8b0ecf76d..f776b6c6c 100644 --- a/examples/osgscalarbar/osgscalarbar.cpp +++ b/examples/osgscalarbar/osgscalarbar.cpp @@ -9,7 +9,6 @@ #include #include -#include #include diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index b5d17aaf3..a49687335 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -237,6 +237,7 @@ class OSG_EXPORT AnimationPathCallback : public NodeCallback META_Object(osg,AnimationPathCallback); + /** Construct an AnimationPathCallback with a specified animation path.*/ AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0,double timeMultiplier=1.0): _animationPath(ap), _pivotPoint(0.0,0.0,0.0), @@ -248,6 +249,9 @@ class OSG_EXPORT AnimationPathCallback : public NodeCallback _pause(false), _pauseTime(0.0) {} + /** Construct an AnimationPathCallback and automatical create an animation path to produce a rotation about a point.*/ + AnimationPathCallback(const osg::Vec3d& pivot,const osg::Vec3d& axis,float angularVelocity); + void setAnimationPath(AnimationPath* path) { _animationPath = path; } AnimationPath* getAnimationPath() { return _animationPath.get(); } diff --git a/include/osgUtil/TransformCallback b/include/osgUtil/TransformCallback index a19d89215..1fe0a9209 100644 --- a/include/osgUtil/TransformCallback +++ b/include/osgUtil/TransformCallback @@ -21,6 +21,7 @@ namespace osgUtil { +/** TransformCallback is now deprecated, use osg::AnimationPathCallback instead.*/ class OSGUTIL_EXPORT TransformCallback : public osg::NodeCallback { diff --git a/src/osg/AnimationPath.cpp b/src/osg/AnimationPath.cpp index c353889bc..323647d42 100644 --- a/src/osg/AnimationPath.cpp +++ b/src/osg/AnimationPath.cpp @@ -115,6 +115,38 @@ void AnimationPath::write(std::ostream& fout) const fout.precision(prec); } +AnimationPathCallback::AnimationPathCallback(const osg::Vec3d& pivot,const osg::Vec3d& axis,float angularVelocity): + _pivotPoint(pivot), + _useInverseMatrix(false), + _timeOffset(0.0), + _timeMultiplier(1.0), + _firstTime(DBL_MAX), + _latestTime(0.0), + _pause(false), + _pauseTime(0.0) +{ + _animationPath = new AnimationPath; + _animationPath->setLoopMode(osg::AnimationPath::LOOP); + + double time0 = 0.0; + double time1 = osg::PI*0.5/angularVelocity; + double time2 = osg::PI*1.0/angularVelocity; + double time3 = osg::PI*1.5/angularVelocity; + double time4 = osg::PI*2.0/angularVelocity; + + osg::Quat rotation0(0.0, axis); + osg::Quat rotation1(osg::PI*0.5, axis); + osg::Quat rotation2(osg::PI*1.0, axis); + osg::Quat rotation3(osg::PI*1.5, axis); + + + _animationPath->insert(time0,osg::AnimationPath::ControlPoint(pivot,rotation0)); + _animationPath->insert(time1,osg::AnimationPath::ControlPoint(pivot,rotation1)); + _animationPath->insert(time2,osg::AnimationPath::ControlPoint(pivot,rotation2)); + _animationPath->insert(time3,osg::AnimationPath::ControlPoint(pivot,rotation3)); + _animationPath->insert(time4,osg::AnimationPath::ControlPoint(pivot,rotation0)); +} + class AnimationPathCallbackVisitor : public NodeVisitor { public: