查看: 904|回复: 1

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

[复制链接]

该用户从未签到

发表于 2020-9-10 14:41:11 | 显示全部楼层 |阅读模式
请教大帅哥们,为啥我的事件处理handle里面没运行,根本 没用为啥???

该用户从未签到

 楼主| 发表于 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));
有什么问题么???
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表