Exemplo n.º 1
0
        public RFPathSegment AddCatMulSegment(Vector3 startPoint, Vector3 endPoint, Vector3 cp1, Vector3 cp2, float steps, float alpha, bool toHead = false)
        {
            RFPathSegment seg = new RFPathSegment();

            seg.SetAsCatmulRom(cp1, startPoint, endPoint, cp2, steps, alpha);
            return(AddSegment(seg, toHead));
        }
Exemplo n.º 2
0
        public RFPathSegment AddBezierSegment(Vector3 startPoint, Vector3 endPoint, Vector3 cp1, Vector3 cp2, float steps, bool toHead = false)
        {
            RFPathSegment seg = new RFPathSegment();

            seg.SetAsBezier2D(cp1, startPoint, endPoint, cp2, steps);
            return(AddSegment(seg, toHead));
        }
Exemplo n.º 3
0
        public RFPathSegment AddStraightSegment(Vector3 startPoint, Vector3 endPoint, float steps, bool toHead = false)
        {
            RFPathSegment seg = new RFPathSegment();

            seg.SetAsStraight(startPoint, endPoint, steps);
            return(AddSegment(seg, toHead));
        }
Exemplo n.º 4
0
        public RFPathSegment AddFixedSegment(List <Vector3> points, bool toHead = false)
        {
            RFPathSegment seg = new RFPathSegment();

            seg.SetAsFixed(points);
            return(AddSegment(seg, toHead));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Return a segment based on a point within MaxDistance to a step within the segment
        /// </summary>
        /// <param name="maxDistance">Max distance POINT can be from a step.</param>
        /// <param name="point">Point to check.</param>
        /// <param name="checkCloseToEnds">If true, dont return the segment if the check point is within MaxDistance to an endpoint</param>
        public RFPathSegment GetSegmentFromStepPoint(float maxDistance, Vector3 point, bool checkCloseToEnds = false)
        {
            for (int cnt = 0; cnt < PathSegments.Count; cnt++)
            {
                RFPathSegment seg = PathSegments[cnt];

                if (checkCloseToEnds == true)
                {
                    if (seg.IsNearEnd(point, maxDistance))
                    {
                        return(null);
                    }
                    if (seg.IsNearStart(point, maxDistance))
                    {
                        return(null);
                    }
                }


                if (seg.PoinNearSteps(point, maxDistance))
                {
                    return(seg);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets segment options based on lastSegment
        /// </summary>
        /// <param name="newPoint">New Endpoint for the segment </param>
        /// <param name="lastSegment">Segment to base startpoint and other options from</param>
        public void CreateNextFromOther(Vector3 newPoint, RFPathSegment lastSegment)
        {
            segmentType       = lastSegment.segmentType;
            segmentSteps      = lastSegment.segmentSteps;
            segmentStartPoint = lastSegment.segmentEndPoint;
            segmentEndPoint   = newPoint;

            ResetControlPoints(true);

            alpha = lastSegment.alpha;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a new segment, based off the last segment in the list
        /// </summary>
        /// <returns>Newly created segment, or null of no segments currently exist</returns>
        /// <param name="newPoint">End point of segment to create</param>
        public RFPathSegment AddPointFromLastSegment(Vector3 newPoint)
        {
            RFPathSegment lastSeg = GetLastSegment();

            if (lastSeg == null)
            {
                Debug.Log("No segments...");
                return(null);
            }

            RFPathSegment seg = new RFPathSegment();

            seg.CreateNextFromOther(newPoint, lastSeg);
            return(AddSegment(seg));
        }
Exemplo n.º 8
0
        public RFPathSegment AddSegment(RFPathSegment segment, bool toHead = false)
        {
            if (toHead)
            {
                PathSegments.Insert(0, segment);
                if (PathSegments.Count == 1)
                {
                    segment.SwapEndpoints();
                }
            }
            else
            {
                PathSegments.Add(segment);
            }

            return(segment);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets all path points.
        /// </summary>
        /// <returns>List of path points</returns>
        public List <Vector3> GetAllPathPoints()
        {
            List <Vector3> allPoints = new List <Vector3>();

            for (int cnt = 0; cnt < PathSegments.Count; cnt++)
            {
                RFPathSegment seg = PathSegments[cnt];

                // Add the start POint
                if (cnt == 0)
                {
                    allPoints.Add(seg.segmentStartPoint);
                }
                else if (allPoints[allPoints.Count - 1] != seg.segmentStartPoint)
                {
                    allPoints.Add(seg.segmentStartPoint);
                }


                // Step through segment steps; add steps of not already added
                List <Vector3> segSteps = seg.GetSegmentSteps();
                for (int segCnt = 0; segCnt < segSteps.Count; segCnt++)
                {
                    Vector3 segStepPoint = segSteps[segCnt];
                    bool    okayToAdd    = true;
                    if (segCnt == 0)
                    {
                        okayToAdd = segStepPoint != allPoints[allPoints.Count - 1];
                    }

                    if (okayToAdd)
                    {
                        allPoints.Add(segStepPoint);
                    }
                }

                // Add endpoint, if not in collection
                if (allPoints[allPoints.Count - 1] != seg.segmentEndPoint)
                {
                    allPoints.Add(seg.segmentEndPoint);
                }
            }

            return(allPoints);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create a new segment, based on the first segment of the list
        /// </summary>
        /// <returns>Newly created segment</returns>
        /// <param name="newPoint">Starting point of new segment.</param>
        public RFPathSegment AddPointFromFirstSegment(Vector3 newPoint)
        {
            RFPathSegment seg = null;

            if (PathSegments.Count > 0)
            {
                RFPathSegment lastSeg = PathSegments[0];
                if (lastSeg != null)
                {
                    seg = new RFPathSegment();
                    seg.CreatePrevFromOther(newPoint, lastSeg);
                    seg = AddSegment(seg, true);
                }
            }

            if (seg == null)
            {
                Debug.Log("No First segment?");
            }

            return(seg);
        }
Exemplo n.º 11
0
        public bool DoesPointControlSegment(float maxDistance, Vector3 point, bool checkControlPoints = true)
        {
            for (int cnt = 0; cnt < PathSegments.Count; cnt++)
            {
                RFPathSegment seg = PathSegments[cnt];
                if (Vector3.Distance(point, seg.segmentStartPoint) <= maxDistance ||
                    Vector3.Distance(point, seg.segmentEndPoint) <= maxDistance)
                {
                    return(true);
                }

                // Check control points (if requested, and if it's a curve!)
                if (checkControlPoints && seg.IsCurve())
                {
                    if (Vector3.Distance(point, seg.controlPoint1) <= maxDistance ||
                        Vector3.Distance(point, seg.controlPoint2) <= maxDistance)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }