details: http://hg.plopbyte.net/animtk/animtk/rev/0acae4280750 changeset: 322:0acae4280750 user: "Cedric Pinson <[EMAIL PROTECTED]>" date: Fri Oct 24 20:45:46 2008 +0200 description: update example, coding style
diffs (truncated from 2483 to 300 lines): diff -r 1e17ce6af3c7 -r 0acae4280750 example/benchmark/bench.cpp --- a/example/benchmark/bench.cpp Fri Oct 24 20:33:52 2008 +0200 +++ b/example/benchmark/bench.cpp Fri Oct 24 20:45:46 2008 +0200 @@ -34,82 +34,85 @@ osgATK::AnimationManager* bench1(int nbA osgATK::AnimationManager* bench1(int nbAnimation, int nbKeyframes, int nbChannels) { - osgATK::AnimationManager* mng = new osgATK::AnimationManager(); - // let's start ! - mng->initTimer(); + osgATK::AnimationManager* mng = new osgATK::AnimationManager(); + // let's start ! + mng->initTimer(); - for (int i = 0; i < nbAnimation; i++) { + for (int i = 0; i < nbAnimation; i++) + { - osgATK::Animation* anim = new osgATK::Animation; - anim->setPlaymode(osgATK::Animation::PPONG); + osgATK::Animation* anim = new osgATK::Animation; + anim->setPlaymode(osgATK::Animation::PPONG); - // Now, let's define our first animation - // We need somes keyframes to describe changes - osgATK::FloatKeyframeContainer* kf = new osgATK::FloatKeyframeContainer; + // Now, let's define our first animation + // We need somes keyframes to describe changes + osgATK::FloatKeyframeContainer* kf = new osgATK::FloatKeyframeContainer; - for (int k = 0; k < nbKeyframes; k++) - kf->push_back(osgATK::FloatKeyframe(k*1.0, k*1.0)); + for (int k = 0; k < nbKeyframes; k++) + kf->push_back(osgATK::FloatKeyframe(k*1.0, k*1.0)); - for (int c = 0; c < nbChannels; c++) { - // We need a sampler to interpolate keyframes - osgATK::FloatLinearSampler* sampler = new osgATK::FloatLinearSampler; - sampler->setKeyframeContainer(kf); + for (int c = 0; c < nbChannels; c++) + { + // We need a sampler to interpolate keyframes + osgATK::FloatLinearSampler* sampler = new osgATK::FloatLinearSampler; + sampler->setKeyframeContainer(kf); - // And we finaly bind the sampler with a target (the value we want to update) - osgATK::FloatLinearChannel* channel = new osgATK::FloatLinearChannel(sampler); - anim->addChannel(channel); + // And we finaly bind the sampler with a target (the value we want to update) + osgATK::FloatLinearChannel* channel = new osgATK::FloatLinearChannel(sampler); + anim->addChannel(channel); + } + + mng->registerAnimation(anim); + mng->playAnimation(anim); } - - mng->registerAnimation(anim); - mng->playAnimation(anim); - } - mng->buildTargetReference(); - return mng; + mng->buildTargetReference(); + return mng; } void benchIt(osgATK::AnimationManager* mng, int nbUpdate) { - float timeFalse = 0; - for (int i = 0; i < nbUpdate; i++) { - mng->update(timeFalse); - timeFalse += 0.01; - } + float timeFalse = 0; + for (int i = 0; i < nbUpdate; i++) + { + mng->update(timeFalse); + timeFalse += 0.01; + } } int main (int argc, char* argv[]) { - int nbupdate = 10000; + int nbupdate = 10000; - osg::ref_ptr<osgATK::AnimationManager> bench = bench1(100, 10000, 6); - { - NPROFILE_SAMPLE("bench1 10000 keysframes"); - benchIt(bench.get(), nbupdate); - } + osg::ref_ptr<osgATK::AnimationManager> bench = bench1(100, 10000, 6); + { + NPROFILE_SAMPLE("bench1 10000 keysframes"); + benchIt(bench.get(), nbupdate); + } - bench = bench1(100, 1000, 6); - { - NPROFILE_SAMPLE("bench2 1000 keysframes"); - benchIt(bench.get(), nbupdate); - } + bench = bench1(100, 1000, 6); + { + NPROFILE_SAMPLE("bench2 1000 keysframes"); + benchIt(bench.get(), nbupdate); + } - bench = bench1(100, 100, 6); - { - NPROFILE_SAMPLE("bench3 100 keysframes"); - benchIt(bench.get(), nbupdate); - } + bench = bench1(100, 100, 6); + { + NPROFILE_SAMPLE("bench3 100 keysframes"); + benchIt(bench.get(), nbupdate); + } - bench = bench1(100, 10, 6); - { - NPROFILE_SAMPLE("bench4 10 keysframes"); - benchIt(bench.get(), nbupdate); - } + bench = bench1(100, 10, 6); + { + NPROFILE_SAMPLE("bench4 10 keysframes"); + benchIt(bench.get(), nbupdate); + } #ifdef USE_NPROFILE - nprf::GetProfiler()->EndProfile(); - nprf::GetProfiler()->GetRootNode()->DisplayFlatStats(std::cout); + nprf::GetProfiler()->EndProfile(); + nprf::GetProfiler()->GetRootNode()->DisplayFlatStats(std::cout); #endif - return 0; + return 0; } diff -r 1e17ce6af3c7 -r 0acae4280750 example/osgnode/osgnode.cpp --- a/example/osgnode/osgnode.cpp Fri Oct 24 20:33:52 2008 +0200 +++ b/example/osgnode/osgnode.cpp Fri Oct 24 20:45:46 2008 +0200 @@ -31,54 +31,55 @@ #include <osg/Material> #include <osgATK/Sampler> - class AnimtkUpdateCallback : public osg::NodeCallback - { - public: +class AnimtkUpdateCallback : public osg::NodeCallback +{ +public: META_Object(osgATK, AnimtkUpdateCallback); - AnimtkUpdateCallback() { - _sampler = new osgATK::Vec3CubicBezierSampler; - _playing = false; - _lastUpdate = 0; + AnimtkUpdateCallback() + { + _sampler = new osgATK::Vec3CubicBezierSampler; + _playing = false; + _lastUpdate = 0; } AnimtkUpdateCallback(const AnimtkUpdateCallback& val, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY): - osg::Object(val, copyop), - osg::NodeCallback(val, copyop), - _sampler(val._sampler), - _startTime(val._startTime), - _currentTime(val._currentTime), - _playing(val._playing), - _lastUpdate(val._lastUpdate) + osg::Object(val, copyop), + osg::NodeCallback(val, copyop), + _sampler(val._sampler), + _startTime(val._startTime), + _currentTime(val._currentTime), + _playing(val._playing), + _lastUpdate(val._lastUpdate) { } /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) { - if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && - nv->getFrameStamp() && - nv->getFrameStamp()->getFrameNumber() != _lastUpdate) { - - _lastUpdate = nv->getFrameStamp()->getFrameNumber(); - _currentTime = osg::Timer::instance()->tick(); - - if (_playing && _sampler.get() && _sampler->getKeyframeContainer()) { - osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node); - if (transform) { - osg::Vec3 result; - float t = osg::Timer::instance()->delta_s(_startTime, _currentTime); - float duration = _sampler->getEndTime() - _sampler->getStartTime(); - t = fmod(t, duration); - t += _sampler->getStartTime(); - _sampler->getValueAt(t, result); - transform->setMatrix(osg::Matrix::translate(result)); - } + if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && + nv->getFrameStamp() && + nv->getFrameStamp()->getFrameNumber() != _lastUpdate) { + + _lastUpdate = nv->getFrameStamp()->getFrameNumber(); + _currentTime = osg::Timer::instance()->tick(); + + if (_playing && _sampler.get() && _sampler->getKeyframeContainer()) { + osg::MatrixTransform* transform = dynamic_cast<osg::MatrixTransform*>(node); + if (transform) { + osg::Vec3 result; + float t = osg::Timer::instance()->delta_s(_startTime, _currentTime); + float duration = _sampler->getEndTime() - _sampler->getStartTime(); + t = fmod(t, duration); + t += _sampler->getStartTime(); + _sampler->getValueAt(t, result); + transform->setMatrix(osg::Matrix::translate(result)); + } + } } - } - // note, callback is responsible for scenegraph traversal so - // they must call traverse(node,nv) to ensure that the - // scene graph subtree (and associated callbacks) are traversed. - traverse(node,nv); + // note, callback is responsible for scenegraph traversal so + // they must call traverse(node,nv) to ensure that the + // scene graph subtree (and associated callbacks) are traversed. + traverse(node,nv); } void start() { _startTime = osg::Timer::instance()->tick(); _currentTime = _startTime; _playing = true;} @@ -89,55 +90,59 @@ osg::Timer_t _currentTime; bool _playing; int _lastUpdate; - }; - - - class AnimtkStateSetUpdateCallback : public osg::StateSet::Callback - { - public: +}; + + +class AnimtkStateSetUpdateCallback : public osg::StateSet::Callback +{ +public: META_Object(osgATK, AnimtkStateSetUpdateCallback); - AnimtkStateSetUpdateCallback() { - _sampler = new osgATK::Vec4LinearSampler; - _playing = false; - _lastUpdate = 0; + AnimtkStateSetUpdateCallback() + { + _sampler = new osgATK::Vec4LinearSampler; + _playing = false; + _lastUpdate = 0; } AnimtkStateSetUpdateCallback(const AnimtkStateSetUpdateCallback& val, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY): - osg::Object(val, copyop), - osg::StateSet::Callback(val, copyop), - _sampler(val._sampler), - _startTime(val._startTime), - _currentTime(val._currentTime), - _playing(val._playing), - _lastUpdate(val._lastUpdate) + osg::Object(val, copyop), + osg::StateSet::Callback(val, copyop), + _sampler(val._sampler), + _startTime(val._startTime), + _currentTime(val._currentTime), + _playing(val._playing), + _lastUpdate(val._lastUpdate) { } /** Callback method called by the NodeVisitor when visiting a node.*/ virtual void operator()(osg::StateSet* state, osg::NodeVisitor* nv) { - if (state && - nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR && - nv->getFrameStamp() && - nv->getFrameStamp()->getFrameNumber() != _lastUpdate) { - - _lastUpdate = nv->getFrameStamp()->getFrameNumber(); - _currentTime = osg::Timer::instance()->tick(); - - if (_playing && _sampler.get() && _sampler->getKeyframeContainer()) { - osg::Material* material = dynamic_cast<osg::Material*>(state->getAttribute(osg::StateAttribute::MATERIAL)); - if (material) { - osg::Vec4 result; _______________________________________________ Animtk-devs mailing list Animtk-devs@gna.org https://mail.gna.org/listinfo/animtk-devs