C++ 路径动画没有效果

0 投票

操作系统:ubuntu18.04

组件:iobjects c++ 9d

问题详细描述:项目中需要实现符号在地图上移动的效果,我了解到可以用动画来实现。发现有Animation相关的类,使用了但没有效果(符号未移动),相关代码如下。

    //! AnimationManager Config
    UGAnimationManager::Instance()->AddMapEditorWnd(qMapControl->GetUGMapWnd());
    //! create animation group
    UGString unitgroup = _U("unitgroup");
    UGAnimationGroup* pGroup = UGAnimationManager::Instance()->AddAnimationGroup(unitgroup);
    if(pGroup == nullptr)
    {
        qDebug() << "UnitAnimationGroup created failed...";
        return;
    }
    //! add animation to group
    QString strLayerName = "AAA";//该图层为CAD图层,之前已成功创建,并且地图上显示了创建的符号图标。
    //! 获取军标对象
    QList<GIS_ICON> gislist = qMapControl->GetAllGeometry(strLayerName);
    for(int i = 0; i < gislist.size();i++)
    {
        UGGeometry3D* pobj = (UGGeometry3D*)gislist.at(i).pGeometry;
        UGPoint2D point = pobj->GetInnerPoint();
        UGPoint3D startpt,endpt;
        startpt.x = point.x;
        startpt.y = point.y;
        startpt.z = 0;
        endpt.x = point.x + 1;
        endpt.y = point.y;
        endpt.z = 0;
        UGWayAnimation* pAnimation = new UGWayAnimation();
        pAnimation->SetName(_U("test"));
        pAnimation->SetPathType(POLYLINE);

        pAnimation->AddPathPt(startpt);
        pAnimation->AddPathPt(endpt);

        bool isTrue = pAnimation->SetGeometry((UGGeometry3D*)pobj,qMapControl->GetUGMapWnd(),_U("AAA"));
        qDebug() << "动画设置符号关联"<<isTrue;
        pAnimation->SetAnimationPlayBeginFunc(AnimationPlayBegin_Proc,(UGlong)this);
        pAnimation->SetAnimationPlayFinishFunc(AnimationPlayFinish_Proc,(UGlong)this);
        pAnimation->SetStartTime(0.0);
        pAnimation->SetDuration(40);
        pAnimation->ShowPathTrack(true);
        int num = pAnimation->GetPathPtCount();
        qDebug() << "路径点数量:"<<num;
        UGPoint3Ds pts = pAnimation->GetPathAllPt();
        for(int i = 0; i < pts.GetSize();i++)
        {
            qDebug() << pts[i].x << pts[i].y;
        }
        bool isAdd = pGroup->AddAnimation(pAnimation);
        qDebug() << "添加动画到动画组"<<isAdd;
        qDebug() << "动画是否可用:"<<pAnimation->IsAvailable();
        qDebug() << "动画对象所在图层名称"<<Translator::UGStr2QStr(pAnimation->m_strLayerName);
        qDebug() << "动画关联的地图名或者场景名称"<<Translator::UGStr2QStr(pAnimation->m_strControlName);
        pAnimation->Excute();
        UGGeometry* pUGan = UGAnimationManager::Instance()->CreateGraphicObject(gislist.at(i).pGeometry,_U("all-layers"),_U("AAA"));
        if(pUGan == nullptr)
            qDebug() << "动画对象创建失败";
    }
    //! play animation
    UGAnimationManager::Instance()->Play();
    qDebug() <<"二维态势推演许可:"<< UGAnimationManager::Instance()->IsHavePlot2DAnimationLicense();
    qDebug() << "二维动画图层名称:"<< Translator::UGStr2QStr(UGAnimationManager::Instance()->m_strDynamicLayerName);
    UGAnimationManager::Instance()->RefreshTrackingLayers();

动画设置符号关联 true

路径点数量: 2

122 41

124 41

添加动画到动画组 true

动画是否可用: 1

动画对象所在图层名称 "AAA"

动画关联的地图名或者场景名称 "all-layers"

140720316589664 "test"

二维态势推演许可: 1

二维动画图层名称: "GraphicObjectAnimationLayer"

打印输出看着都是正常的,就是地图上的符号不动。

4月 29 分类:  55次浏览 | 用户: nuaa_li 初出茅庐 (24 分)

1个回答

0 投票
你有添加timer吗,需要在timer的事件中去执行pAnimationManager->Excute();
4月 30 用户: 程逸诗 名扬四海 (4,242 分)
...