Added the support in AnimationPathCallback for taking a pivot, axis and rotation rate
paramters in its constructor to allow it to be used to create rotations around a point. This provides the same interface and functionality as osgUtil::TransformCallback but has the advantage and AnimationPathCallback is fully supported by the .osg and .ive file formats.
This commit is contained in:
parent
ac0a6a6ac5
commit
83d492162e
@ -15,7 +15,6 @@
|
||||
#include <osgGA/TrackballManipulator>
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
#include <osgProducer/Viewer>
|
||||
|
||||
@ -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;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include <osg/TexEnvCombine>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/TexGenNode>
|
||||
|
||||
@ -137,13 +135,13 @@ ref_ptr<Group> _create_scene()
|
||||
ref_ptr<Geode> geode_2 = new Geode;
|
||||
ref_ptr<MatrixTransform> 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> geode_3 = new Geode;
|
||||
ref_ptr<MatrixTransform> 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;
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <osg/io_utils>
|
||||
|
||||
#include <osgUtil/Tesselator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/CullVisitor>
|
||||
#include <osgUtil/Optimizer>
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <osg/ClearNode>
|
||||
|
||||
#include <osgUtil/Tesselator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
#include <osgText/Text>
|
||||
@ -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)
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <osg/MatrixTransform>
|
||||
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
|
||||
class PBufferTexture2D : public osg::Texture2D
|
||||
@ -239,7 +238,7 @@ osg::ref_ptr<osg::Node> buildSceneGraphAndSetCameraViews(osg::Node *loadedModel,
|
||||
osg::ref_ptr<osg::MatrixTransform> loadedModelTransform = new osg::MatrixTransform;
|
||||
loadedModelTransform->addChild(loadedModel);
|
||||
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osgUtil::TransformCallback(
|
||||
osg::ref_ptr<osg::NodeCallback> 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<osg::Node> buildSceneGraph(osg::Node *loadedModel, Producer::Render
|
||||
osg::ref_ptr<osg::MatrixTransform> loadedModelTransform = new osg::MatrixTransform;
|
||||
loadedModelTransform->addChild(loadedModel);
|
||||
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osgUtil::TransformCallback(
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osg::AnimationPathCallback(
|
||||
loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
loadedModelTransform->setUpdateCallback(nc.get());
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include <osgGA/FlightManipulator>
|
||||
#include <osgGA/DriveManipulator>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/SmoothingVisitor>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
@ -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();
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include <osg/RefNodePath>
|
||||
#include <osg/PositionAttitudeTransform>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
|
||||
#include <osg/CameraNode>
|
||||
#include <osg/TexGenNode>
|
||||
|
||||
@ -36,13 +34,13 @@ ref_ptr<Group> _create_scene()
|
||||
ref_ptr<Geode> geode_2 = new Geode;
|
||||
ref_ptr<MatrixTransform> 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> geode_3 = new Geode;
|
||||
ref_ptr<MatrixTransform> 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;
|
||||
|
@ -20,8 +20,7 @@
|
||||
#include <osg/ColorMask>
|
||||
#include <osg/Depth>
|
||||
#include <osg/ClipNode>
|
||||
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osg/AnimationPath>
|
||||
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgUtil/Optimizer>
|
||||
@ -382,7 +381,7 @@ int main( int argc, char **argv )
|
||||
osg::ref_ptr<osg::MatrixTransform> loadedModelTransform = new osg::MatrixTransform;
|
||||
loadedModelTransform->addChild(loadedModel.get());
|
||||
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osgUtil::TransformCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
osg::ref_ptr<osg::NodeCallback> nc = new osg::AnimationPathCallback(loadedModelTransform->getBound().center(),osg::Vec3(0.0f,0.0f,1.0f),osg::inDegrees(45.0f));
|
||||
loadedModelTransform->setUpdateCallback(nc.get());
|
||||
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include <osg/Projection>
|
||||
|
||||
#include <osgUtil/Tesselator>
|
||||
#include <osgUtil/TransformCallback>
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
|
||||
|
@ -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(); }
|
||||
|
@ -21,6 +21,7 @@
|
||||
namespace osgUtil
|
||||
{
|
||||
|
||||
/** TransformCallback is now deprecated, use osg::AnimationPathCallback instead.*/
|
||||
class OSGUTIL_EXPORT TransformCallback : public osg::NodeCallback
|
||||
{
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user