zoukankan      html  css  js  c++  java
  • 相机沿着场景旋转

    class Test : public osgGA::AnimationPathManipulator
    {
    public:
     Test(osg::AnimationPath* path) : AnimationPathManipulator(path)
     {
     }
     ~Test(){}
    private:
     osg::Quat _rotation;
     osg::Vec3d _center;
     double _distance;
     double _current;
    public:
        virtual void setByMatrix(const osg::Matrixd& matrix) { _matrix = matrix; }

            /** set the position of the matrix manipulator using a 4x4 Matrix.*/
            virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _matrix.invert(matrix); }

            /** get the position of the manipulator as 4x4 Matrix.*/
            virtual osg::Matrixd getMatrix() const { return _matrix; }

            /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
            virtual osg::Matrixd getInverseMatrix() const
      {
       return  _matrix;
      }

      void home(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
      {
       _current = osg::Timer::instance()->tick();
      }
      
      bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
      {
       if( !valid() ) return false;
           
       switch(ea.getEventType())
       {
       case osgGA::GUIEventAdapter::FRAME:
        {
         osg::AnimationPath::ControlPoint cp;

         double t = _animationPath->getLastTime() - _animationPath->getFirstTime();
         double kk = osg::Timer::instance()->tick();
         double duration = osg::Timer::instance()->delta_s(_current, kk);
         duration = fmod(duration, t);
         duration += _animationPath->getFirstTime();
         _animationPath->getInterpolatedControlPoint(duration, cp);
         cp.getMatrix(_matrix);
        }
       case osgGA::GUIEventAdapter::KEYUP:
        {
         if (ea.getKey() == 's')
         { 
                           
         }
        }
        case osgGA::GUIEventAdapter::KEYUP
        {
         if (ea.getKey() == 'p')
         {

         }
         
        }
       }

       return true;

      }

    };

    osgViewer::Viewer viewer;
     osg::Group* group = new osg::Group;
     
     osg::Node* node = osgDB::readNodeFile("D:/osgBin/bin/cow.osg");
     group->addChild(node);

     osg::MatrixTransform* transform = new osg::MatrixTransform;
     transform->setMatrix(osg::Matrixd::translate(20, 0, 0));

     osg::Node* node1 = osgDB::readNodeFile("D:/osgBin/bin/cow.osg");

     transform->addChild(node1);
     group->addChild(transform);

     osg::AnimationPath* path = new osg::AnimationPath;
     path->setLoopMode(osg::AnimationPath::LOOP);

     for (int i = 0; i < 36; i++)
     {
      osg::Quat quat(10 * i, osg::Vec3d(0.0, 1.0, 0.0));
      osg::Matrixd m = osg::Matrixd::translate(-group->getBound().center()) * osg::Matrixd::rotate(quat) * osg::Matrixd::translate(0, 0, -group->getBound().radius() * 3);
      osg::Vec3f pos = m.getTrans();
      osg::Quat rot = m.getRotate();

      path->insert( i * 5, osg::AnimationPath::ControlPoint(pos, rot) );
     }
     
       viewer.setCameraManipulator(new Test(path));
       viewer.setSceneData(node);

        return viewer.run();

  • 相关阅读:
    Docker
    Docker
    Linux
    VUE- 前端插件
    小程序中实现 input 搜索框功能
    Vue 中用delete方式进行axios请求接口,请求状态码报415(Unsupported Media Type)
    关于小程序使用map组件,标记markers时报错误(ret is not defined)
    关于element 框架中table表格选中并切换下一页之前选中数据消失的问题
    vue切换路由时报错 uncaught(in promise) Navigation Duplicated 问题
    2019-09-09 JS面试题(持续更新中)
  • 原文地址:https://www.cnblogs.com/lizhengjin/p/1797000.html
Copyright © 2011-2022 走看看