How to set LocalGeometryNode updatecallback?

classic Classic list List threaded Threaded
2 messages Options
qing qing
Reply | Threaded
Open this post in threaded view
|

How to set LocalGeometryNode updatecallback?

I want to make a plane fly on earth, I make a AnimationPathCallback on LocalGeometryNode, but it not work, this is my code

        _viewer = dynamic_cast<osgViewer::Viewer *>(__super::getViewer());
        _viewer->setThreadingModel(osgViewer::ViewerBase::AutomaticSelection);
        _viewer->getCamera()->setClearColor(osg::Vec4(0, 0, 0, 255));
        _scene = new osg::Group;
        _viewer->setSceneData(_scene);

        _mapNode = dynamic_cast<MapNode *>(osgDB::readNodeFile("../data/earthfile.earth"));
        _scene->addChild(_mapNode);

        _skyNode = SkyNode::create(_mapNode);
        DateTime dt(QDateTime::currentDateTimeUtc().toTime_t());
        _skyNode->setDateTime(dt);
        _scene->addChild(_skyNode);
       
        _earthManipulator = dynamic_cast<EarthManipulator *>(_viewer->getCameraManipulator());

        LocalGeometryNode *airportNode = new LocalGeometryNode(_mapNode);
        osg::Node *model = osgDB::readNodeFile("../data/airport.ive");
        airportNode->setNode(model);
        airportNode->setPosition(GeoPoint(_mapNode->getMap()->getSRS(), 116.2, 33, 0));
        _scene->addChild(airportNode);

        LocalGeometryNode *planeNode = new LocalGeometryNode(_mapNode);
        osg::Node *b737 = osgDB::readNodeFile("../data/b737.ive");
        planeNode->setNode(b737);
        planeNode->setPosition(GeoPoint(_mapNode->getMap()->getSRS(), 116.2, 33, 60));
        planeNode->setLocalRotation(osg::Quat(osg::inDegrees(-45.0), osg::Z_AXIS));
        _scene->addChild(planeNode);

        //_earthManipulator->setTetherNode(planeNode, 1000, 0, -30, 500);

        osg::AnimationPath *path = new osg::AnimationPath;
        path->setLoopMode(osg::AnimationPath::NO_LOOPING);
        for(int i=0; i<5; ++i){
                osg::Vec3d pos;
                _mapNode->getMapSRS()->getEllipsoid()->convertLatLongHeightToXYZ(osg::inDegrees(33.0), osg::inDegrees(i+116.2), 60, pos.x(), pos.y(), pos.z());
                path->insert(i * 600, osg::AnimationPath::ControlPoint(pos, osg::Quat(osg::inDegrees(0.0), osg::Z_AXIS)));
        }
        planeNode->setUpdateCallback(new osg::AnimationPathCallback(path));

        _earthManipulator->setViewpoint(Viewpoint("tt", 116.2, 33, 0, 0, -30, 500), 3);
qing qing
Reply | Threaded
Open this post in threaded view
|

Re: How to set LocalGeometryNode updatecallback?

This post was updated on .
I put planeNode in a MatrixTransform and set MatrixTransform updatecallback, and clear LocalGeometryNode's GeoTransform matrix, slove it
but have another problem, is plane rotation is wrong