|
楼主 |
发表于 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));
有什么问题么??? |
|