Exemplo n.º 1
0
        public float move(PathPosition currentPosition, float distance, out PathPosition newPosition)
        {
            float distToEnd = (points.Length-1 - currentPosition.pointIndex - currentPosition.ratio) * distanceBetweenPoints;
            float distToStart = (currentPosition.pointIndex + currentPosition.ratio) * distanceBetweenPoints;

            if (distance - distToEnd > 0)
            {
                newPosition = getEndPoint();
                return distance - distToEnd;
            }
            else if (distance + distToStart < 0)
            {
                newPosition = getStartPoint();
                return distance + distToStart;
            }

            distance += currentPosition.ratio * distanceBetweenPoints;

            int tam = (int)(distance / distanceBetweenPoints);
            float artan = distance / distanceBetweenPoints - tam;

            if (artan < 0)
            {
                artan += 1f;
                tam--;
            }

            newPosition = new PathPosition(currentPosition.pointIndex + tam, artan);
            return 0;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates a point on the BezierPath
        /// </summary>
        /// <param name="curveIndex">On which bezier curve, your point is ? (Starts from 0)</param>
        /// <param name="t">between 0 and 1 , specifies the point on the curve</param>
        /// <returns>A Vector3 of the specified point</returns>
        public Vector3 getLocalPosition(PathPosition position)
        {
            int nodeIndex = position.pointIndex;

            Vector3 p0 = controlPoints[nodeIndex];
            Vector3 p1 = controlPoints[nodeIndex + 1];
            Vector3 p2 = controlPoints[nodeIndex + 2];
            Vector3 p3 = controlPoints[nodeIndex + 3];

            return CalculateBezierPoint(position.ratio, p0, p1, p2, p3);
        }
Exemplo n.º 3
0
        public void AddMinionSpecificPosition(Minion minion, PathPosition position)
        {
            try
            {
                toBeAddedMinions.Add(minion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace + " : " + e.Message);
            }

            if (minion.position == null)
                minion.position = new MinionPosition();

            minion.position.board = this;
            minion.position.pathPosition = new PathPosition(position.pointIndex, position.ratio);

        }
Exemplo n.º 4
0
 public PathPosition getStartPoint()
 {
     PathPosition startPoint = new PathPosition(0, 0.0f);
     return startPoint;
 }
Exemplo n.º 5
0
        public Vector3 findDiffOnPath(PathPosition position)
        {
            int index = position.pointIndex;
            Vector3 x = controlPoints[index];
            Vector3 y = controlPoints[index + 1];
            Vector3 z = controlPoints[index + 2];
            Vector3 w = controlPoints[index + 3];

            float t = position.ratio;
            return t * t * (-3 * x + 9 * y - 9 * z + 3 * w) + t * (6 * x - 12 * y + 6 * z) + (-3 * x + 3 * y);
        }
Exemplo n.º 6
0
        public float move(PathPosition currentPosition, float distance, out PathPosition newPosition)
        {
            newPosition = new PathPosition(currentPosition.pointIndex, currentPosition.ratio);

			float diff = findDiffOnPath(currentPosition).magnitude;
            float bitDistance = distance / diff;

            newPosition.ratio += bitDistance;

            while (newPosition.ratio >= 1)
            {
                newPosition.ratio -= 1;
                newPosition.pointIndex += 3;

                if (newPosition.pointIndex == controlPoints.Count - 1)
                {
                    float remaining = newPosition.ratio * diff;
                    newPosition.pointIndex -= 3;
                    newPosition.ratio = 1;
                    return remaining;
                }
            }

            while (newPosition.ratio < 0)
            {
                newPosition.ratio += 1;
                newPosition.pointIndex -= 3;

                if (newPosition.pointIndex == -3)
                {
                    float remaining = (newPosition.ratio - 1f) * diff;
                    newPosition.pointIndex += 3;
                    newPosition.ratio = 0;
                    return remaining;
                }
				if( newPosition.pointIndex == -4)
				{
					return 0f;
				}
            }
            return 0;
        }
Exemplo n.º 7
0
 public PathPosition getEndPoint()
 {
     PathPosition endPoint = new PathPosition(controlPoints.Count - 4, 1.0f);
     return endPoint;
 }
Exemplo n.º 8
0
 public Vector3 getLocalPosition(PathPosition pathPosition)
 {
     return points[pathPosition.pointIndex] + (points[pathPosition.pointIndex + 1] - points[pathPosition.pointIndex]) * pathPosition.ratio;
 }
Exemplo n.º 9
0
 public Vector3 findDiffOnPath(PathPosition position)
 {
     return (points[position.pointIndex+1]-points[position.pointIndex]).normalized;
 }