yyyDDDyyy 发表于 2020-9-10 14:41:11

osgGA::EventHandler里的handle函数未运行

请教大帅哥们,为啥我的事件处理handle里面没运行,根本 没用为啥???

yyyDDDyyy 发表于 2020-9-10 14:43:00

class Rotation : public osgGA::EventHandler
{
public:
    Rotation(osg::MatrixTransform *mt)
      : _mt(mt)
    {
      spt = osg::Timer::instance()->getSecondsPerTick(); //得到一个tick值为多少秒
    }

    bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
    {
      if (ea.getEventType() == ea.FRAME)
      {
            if (pause == true)
            {
                osg::Timer_t timer = osg::Timer::instance()->tick();
                osg::Timer::instance()->setStartTick(timer - static_cast<unsigned int>(temp / spt));
                return false;
            }
            //地球自转
            osg::Vec3d x = {1, 0, 0};
            temp = osg::Timer::instance()->time_s(); //以秒为单位获得运行时间
            double t = fmod(temp , 86400.0 / speed) / (86400.0 / speed)* 2 * pi;

            T.set(cos(t), sin(t), 0, 0, \
                  -sin(t), cos(t), 0, 0, \
                  0, 0, 1, 0, \
                  0, 0, 0, 1);
            _mt->setMatrix(osg::Matrix::rotate(x, T.preMult(x)));

      }
      return false;
    }

private:
    double temp;
    double spt;
    osg::Matrixd T;
    osg::MatrixTransform* _mt;

};

viewer->addEventHandler(new Rotation(mt));
有什么问题么???
页: [1]
查看完整版本: osgGA::EventHandler里的handle函数未运行