Ejemplo n.º 1
0
        public override void Update(TimeSpan elapsedTime)
        {
            var controlState = this.controller.Control();
            this.head.Update(elapsedTime, controlState);

            var currentPathPart = new CentiPathPart(this.head.Position, this.lastSaved);

            this.updateParts(currentPathPart);

            if (currentPathPart.DistanceToPrevious > 0.5f.U())
            {
                this.tailPath.AddFirst(currentPathPart);
                this.lastSaved = currentPathPart;
            }
        }
Ejemplo n.º 2
0
        private void updateParts(CentiPathPart startPosition)
        {
            var intervalStart = startPosition;
            var intervalStartDistance = 0.U();

            var intervalLength = intervalStart.DistanceToPrevious;

            var intervalEndNode = this.tailPath.First;

            var i = 0;

            var partDistanceStep = 1.5f.U();
            var partDistance = partDistanceStep;

            while (true)
            {
                var intervalEnd = intervalEndNode.Value;
                var intervalEndDistance = intervalStartDistance + intervalLength;

                if (intervalLength > 0.U())
                {
                    while (partDistance < intervalEndDistance)
                    {
                        // position part, move to next
                        var part = this.parts[i];

                        var p = (partDistance - intervalStartDistance) / intervalLength;

                        part.SetPosition(intervalStart.Position.LerpTo(intervalEnd.Position, p));

                        partDistance += partDistanceStep;
                        i++;

                        if (i == this.parts.Count)
                        {
                            while (this.tailPath.Last != intervalEndNode)
                                this.tailPath.RemoveLast();

                            return;
                        }
                    }
                }

                if (intervalEndNode.Next == null)
                {
                    for (; i < this.parts.Count; i++)
                    {
                        var part = this.parts[i];
                        part.SetPosition(intervalEnd.Position);
                    }
                    return;
                }

                intervalStart = intervalEnd;
                intervalStartDistance = intervalEndDistance;
                intervalLength = intervalStart.DistanceToPrevious;

                intervalEndNode = intervalEndNode.Next;
            }
        }
Ejemplo n.º 3
0
 public CentiPathPart(Position2 position, CentiPathPart previous)
     : this(position, (position - previous.Position).Length)
 {
 }
Ejemplo n.º 4
0
 public CentiPathPart(Position2 position, CentiPathPart previous)
     : this(position, (position - previous.Position).Length)
 {
 }