예제 #1
0
        public override void SetupAnimation()
        {
            base.SetupAnimation();
            //visible rec so that the start of the anim is from a point visible on screen
            var visibleRecX = Random.Rand.Next(NumFrames);
            var visibleRecY = Random.Rand.Next(NumFrames);

            var recIndex = new SKPointI(visibleRecX, visibleRecY);

            //keep geting a random index until one exists
            while (!SeperatedPoints.ContainsKey(recIndex))
            {
                visibleRecX = Random.Rand.Next(NumFrames);
                visibleRecY = Random.Rand.Next(NumFrames);
                recIndex    = new SKPointI(visibleRecX, visibleRecY);
            }

            //index of a randoom point on the random visible rec
            var index = Random.Rand.Next(SeperatedPoints[recIndex].Count);
            //pointF version of the point
            var pointT = SeperatedPoints[recIndex].ToArray()[index];
            //vertex version of the point
            var point = new Vertex(pointT.X, pointT.Y);
            //index of the chosen point in the overall points list
            var indexT = InternalPoints.IndexOf(point);

            //set the first point as used
            _pointUsed[indexT] = true;

            _animateList = new Queue <Vertex>();
            _animateList.Enqueue(point);

            IsSetup = true;
        }
예제 #2
0
        public virtual void DrawPointFrame(SKSurface surface, List <AnimatedPoint> pointChanges)
        {
            using (var canvas = surface.Canvas)
            {
                canvas.Clear();
                //case in frame immediately after animation has completed, nothing needs to be drawn
                if (CurrentFrame > NumFrames)
                {
                    return;
                }

                //vertex and its original vertex in InternalPoints
                var updatedPoints = new Tuple <Vertex, Vertex> [InternalPoints.Count];

                //for quick lookup to check if a specified point index has been modified
                var updatedIndices = new int[pointChanges.Count];

                for (var i = 0; i < pointChanges.Count; i++)
                {
                    var animatedPoint = pointChanges[i];

                    //find index of animated point in InternalPoints
                    var index = InternalPoints.FindIndex(v =>
                                                         v.x.Equals(animatedPoint.Point.X) && v.y.Equals(animatedPoint.Point.Y));

                    //only malloc if null or item2 is different
                    if (updatedPoints[index] != null && updatedPoints[index].Item2.Equals(InternalPoints[index]))
                    {
                        updatedPoints[index].Item1.x = animatedPoint.Point.X + animatedPoint.XDisplacement;
                        updatedPoints[index].Item1.y = animatedPoint.Point.Y + animatedPoint.YDisplacement;
                    }
                    else
                    {
                        updatedPoints[index] = new Tuple <Vertex, Vertex>(
                            new Vertex(animatedPoint.Point.X + animatedPoint.XDisplacement,
                                       animatedPoint.Point.Y + animatedPoint.YDisplacement), InternalPoints[index]);
                    }

                    //mark this point's index as used
                    updatedIndices[i] = index;
                }

                //increment updated points
                foreach (var updatedPoint in updatedPoints)
                {
                    //non-updated points will be null
                    if (updatedPoint == null)
                    {
                        continue;
                    }

                    //increment each triad that contains this updatedPoint
                    foreach (var tri in InternalPointToTriangleDic[updatedPoint.Item2])
                    {
                        GetCorrectPoint(updatedPoints, updatedIndices, tri.a, ref PathPointA);
                        GetCorrectPoint(updatedPoints, updatedIndices, tri.b, ref PathPointB);
                        GetCorrectPoint(updatedPoints, updatedIndices, tri.c, ref PathPointC);

                        Geometry.centroid(tri, InternalPoints, ref Center);
                        //triangle color center
                        CurrentTriangulation.KeepInBounds(ref Center);
                        fillPaint.Color = CurrentTriangulation.GetTriangleColor(Center);

                        Geometry.DrawTrianglePath(ref TrianglePath, PathPointA, PathPointB, PathPointC);
                        canvas.DrawPath(TrianglePath, fillPaint);
                        if (HideLines)
                        {
                            //need to maintain the strokepaint reguardless if we are just hiding its display
                            var backup = strokePaint.Color;
                            strokePaint.Color = fillPaint.Color;
                            canvas.DrawPath(TrianglePath, strokePaint);
                            strokePaint.Color = backup;
                        }
                        else
                        {
                            canvas.DrawPath(TrianglePath, strokePaint);
                        }
                    }
                }
            }
        }