40行代码在iPhone上动画显示路线图

原创
2014/07/04 13:40
阅读数 338

lines

<!-- lang: cpp -->
void addAnimatedBezierDemo(GiPlayingHelper *play)
{
    __block Point2d pt1, pt2, pt3, pt4;
    __block float t = 0;

    [play addPlayProvider:^int(GiFrame frame) {
        MgShapes *shapes = MgShapes::fromHandle(frame.shapes);
    
        if (shapes->getShapeCount() == 0) {
            GiViewHelper *helper = [GiViewHelper sharedInstance:frame.view];
            MgShapeT<MgPathShape> path;
        
            path._context.setLineWidth(-5, true);
            pt1 = d2m(10, 50, helper);
            pt2 = d2m(100, 400, helper);
            pt3 = d2m(300, 400, helper);
            pt4 = d2m(300, 50, helper);
        
            path._shape.path().moveTo(pt1);
            path._shape.path().bezierTo(pt2, pt3, pt4);
            shapes->addShape(path);
        }
    
        if (frame.tick < frame.lastTick + 10) {
            return 0;
        }
    
        MgShape* newsp = shapes->getLastShape()->cloneShape();
        GiPath& path = ((MgPathShape*)newsp->shape())->path();
    
        Point2d pts[12] = { pt1, pt2, pt3, pt4 };
        mgcurv::splitBezier(pts, t, pts + 4, pts + 8);
        path.clear();
        path.moveTo(pts[4]);
        path.beziersTo(3, pts + 5);
    
        t += 1e-2;
        if (t > 1)
            t = 0;
        shapes->updateShape(newsp, true);
        return 1;
    } ended:nil tag:1];
}

代码见 vgplay-ios 项目的 AnimatedLines.mmAnimatedBezier.mm

只是一个动画原型,还需要更多完善,使用还需要精简。目标使用还比较复杂,理想情况是写类似于脚本串指定速度、时间、moveto/lineto/curveto等简单绘图指令,隐藏坐标转换、图形更新等复杂细节。

展开阅读全文
打赏
0
5 收藏
分享
加载中
更多评论
打赏
0 评论
5 收藏
0
分享
返回顶部
顶部