GetPoint() public method

public GetPoint ( float t ) : Vector3
t float
return Vector3
Esempio n. 1
0
        public Section(float startDistance, SplinePoint start, SplinePoint end, int parts, float power)
        {
            this.startDistance = endDistance = startDistance;

            var startPosition = start.transform.localPosition;
            var endPosition   = end.transform.localPosition;
            var startForward  = start.transform.parent.InverseTransformDirection(start.transform.forward);
            var endForward    = end.transform.parent.InverseTransformDirection(end.transform.forward);
            var startUp       = start.transform.parent.InverseTransformDirection(start.transform.up);
            var endUp         = end.transform.parent.InverseTransformDirection(end.transform.up);
            var deltaPower    = Vector3.Distance(startPosition, endPosition) * power;
            var startPower    = start.autoPower ? deltaPower : start.power;
            var endPower      = end.autoPower ? deltaPower : end.power;


            var point = new Point();

            for (int i = 0; i <= parts; i++)
            {
                var t = (float)i / parts;

                var position = Bezier.GetPoint(startPosition, startForward * startPower, endPosition, -endForward * endPower, t);

                endDistance   += i == 0 ? 0 : Vector3.Distance(point.position, position);
                point.distance = endDistance;
                point.forward  = i == 0 ? startForward : (i == parts ? endForward : Vector3.Normalize(position - point.position));
                point.upward   = Vector3.Slerp(startUp, endUp, t);
                point.position = position;

                points.Add(point);
            }
        }
Esempio n. 2
0
    public Vector3 GetLengthAdjustedPoint(float t)
    {
        int index = 0;

        if (t >= 1f)
        {
            t     = 1f;
            index = points.Length - 4;
        }
        else
        {
            float remainingPercentage = t;
            for (int i = 0; i < _segmentLengthPercentages.Length; i++)
            {
                if (remainingPercentage > _segmentLengthPercentages[i])
                {
                    remainingPercentage -= _segmentLengthPercentages[i];
                }
                else
                {
                    t     = remainingPercentage / _segmentLengthPercentages[i];
                    index = i * 3;
                    break;
                }
            }
        }

        return(transform.TransformPoint(Bezier.GetPoint(points[index], points[index + 1], points[index + 2], points[index + 3], t)));
    }
Esempio n. 3
0
    public Vector3 GetPoint(float t)
    {
        try
        {
            for (int i = 0; i < SourceObjectsInUse.Length; i++)
            {
                points[i] = SourceObjectsInUse[i].transform.position;
            }
            int j;
            if (t >= 1f)
            {
                t = 1f;
                j = points.Length - 4;
            }
            else
            {
                t  = Mathf.Clamp01(t) * CurveCount;
                j  = (int)t;
                t -= j;
                j *= 3;
            }
            Vector3 pointsVector = Bezier.GetPoint(points[j], points[j + 1], points[j + 2], points[j + 3], t);


            return(transform.TransformPoint(pointsVector));
        }
        catch {
            print("OUT OF RANGE MAYBE");
            return(Vector3.zero);
        }
    }
        public Vector3 GetPoint(float t, bool worldSpace = true)
        {
            int i;

            if (t >= 1f)
            {
                t = 1f;
                i = points.Length - 2;
            }
            else
            {
                t  = Mathf.Clamp01(t) * CurveCount;
                i  = (int)t;
                t -= i;
            }

            Vector3 pos = Bezier.GetPoint(points[i].curvePoint, points[i].curvePoint + points[i].curveTangent, points[i + 1].curvePoint - points[i + 1].curveTangent, points[i + 1].curvePoint, t);

            if (!worldSpace)
            {
                return(pos);
            }

            return(transform.TransformPoint(pos));
        }
Esempio n. 5
0
    private float[] GetSegmentLengths(int totalSegmentsPerCurve, out float totalLength)
    {
        totalLength = 0f;
        int curveCount = this.CurveCount;

        float[] list = new float[curveCount];

        for (int i = 0; i < curveCount; i++)
        {
            float curveLength = 0f;
            int   index       = i * 3;

            Vector3 lastPoint = Bezier.GetPoint(points[index], points[index + 1], points[index + 2], points[index + 3], 0f);
            for (int j = 1; j <= totalSegmentsPerCurve; j++)
            {
                float location = (float)j / (float)totalSegmentsPerCurve;

                Vector3 point  = Bezier.GetPoint(points[index], points[index + 1], points[index + 2], points[index + 3], location);
                float   length = (point - lastPoint).magnitude;

                curveLength += length;

                lastPoint = point;
            }

            list[i]      = curveLength;
            totalLength += curveLength;
        }

        return(list);
    }
Esempio n. 6
0
    public Vector3 GetPoint(float t)
    {
        int i = 0;

        ComputeTimeIndex(ref t, out i);
        return(transform.TransformPoint(Bezier.GetPoint(path.points[i], path.points[i + 1], path.points[i + 2], path.points[i + 3], t)));
    }
Esempio n. 7
0
    public Vector3 GetPoint(float t, bool inWorldSpaceCoordinates = true)
    {
        int i;

        if (t >= 1f)
        {
            t = 1f;
            i = points.Length - 4;
        }
        else
        {
            t  = Mathf.Clamp01(t) * CurveCount;
            i  = (int)t;
            t -= i;
            i *= 3;
        }

        if (inWorldSpaceCoordinates)
        {
            return(transform.TransformPoint(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t)));
        }
        else
        {
            return(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t));
        }
    }
Esempio n. 8
0
    private float[] GetSegmentLengths(int totalSegmentsPerCurve, out float totalLength)
    {
        totalLength = 0f;

        var curveCount = CurveCount;

        var curveLengths = new float[curveCount];

        for (var i = 0; i < curveCount; i++)
        {
            var curveLength = 0f;

            var index = i * 3;

            var lastPoint = Bezier.GetPoint(Points[index], Points[index + 1], Points[index + 2], Points[index + 3], 0f);

            for (int j = 1; j <= totalSegmentsPerCurve; j++)
            {
                var location = (float)j / (float)totalSegmentsPerCurve;

                var point  = Bezier.GetPoint(Points[index], Points[index + 1], Points[index + 2], Points[index + 3], location);
                var length = (point - lastPoint).magnitude;

                curveLength += length;

                lastPoint = point;
            }

            curveLengths[i] = curveLength;

            totalLength += curveLength;
        }

        return(curveLengths);
    }
Esempio n. 9
0
    private IEnumerator Jump(PlayerController player, Vector3 a, Vector3 b, Vector3 c, float jumpTime, PlayerVFX vfx)
    {
        float elapsed = 0f;

        while (elapsed < jumpTime)
        {
            float t = elapsed / jumpTime;

            player.transform.position = Bezier.GetPoint(a, b, c, t);
            player.transform.rotation = Quaternion.Lerp(player.transform.rotation, Quaternion.Euler(endRot), t);

            //player.transform.forward = player.rigid.velocity + Bezier.GetDerivative(a, b, c, t);

            elapsed += Time.deltaTime;
            yield return(null);
        }

        player.IsJumping         = false;
        jumpRoutine              = null;
        player.rigid.constraints = RigidbodyConstraints.FreezeRotation;

        player.rigid.velocity += Vector3.up * -2f;

        vfx.landingSparks.Play();
    }
Esempio n. 10
0
    private void SpawnFigures()
    {
        Vector3[] previousePoints = GetPreviousePoints();

        for (int i = 0; i < _defaulSegmentNumbers + 1; i++)
        {
            for (int x = 0; x < _numberHandles - 1; x += 3)
            {
                Vector3 firstPoint  = previousePoints[x / 3];
                Vector3 secondPoint = Bezier.GetPoint(_handles[x].position, _handles[x + 1].position, _handles[x + 2].position, _handles[x + 3].position, GetParameter(i));

                _firstPoint  = firstPoint;
                _secondPoint = secondPoint;

                previousePoints[x / 3] = secondPoint;
            }

            int     figuresCount = CalculateNumberOfFiguresOverDistance(_firstPoint, _secondPoint);
            Vector3 direction    = (_secondPoint - _firstPoint).normalized;

            for (int j = 0; j < figuresCount; j++)
            {
                _spawner.Spawn(_firstPoint + direction * GetNewSpacing(j));
            }
        }
    }
Esempio n. 11
0
    void OnDrawGizmos()
    {
        if (!showPath || path == null || path.Length == 0)
        {
            return;
        }

        Vector3 a, b, c = path[0].worldPos;

        for (int i = 1; i < path.Length; i++)
        {
            a = c;
            b = path[i - 1].worldPos;
            c = (b + path[i].worldPos) * 0.5f;
            for (float t = 0f; t < 1f; t += 0.1f)
            {
                Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), .3f);
            }
        }

        a = c;
        b = path[path.Length - 1].worldPos;
        c = b;
        for (float t = 0f; t < 1f; t += 0.1f)
        {
            Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), .3f);
        }
    }
Esempio n. 12
0
    // Get point from the progress time passed by enemy.
    public Vector3 GetPathPoint(float t, out bool IsFinished)
    {
        for (int i = 0; i < pathingPoints.Length - 1; i++)
        {
            // Subtract delay time from progress
            t -= pathingPoints[i].GetDelayTime();
            // If the time elapsed goes to the next bezier curve
            if (t - pathingPoints[i].GetTravelTime() > 0)
            {
                // remove the travel time of the curve just travelled
                t -= pathingPoints[i].GetTravelTime();
            }
            else
            {
                if (t <= 0)
                {
                    // If time is less than zero make zero so it stays at start point of the curve, this adds the delay until it expends the delay time
                    t = 0;
                }
                // Make time between 0 and 1 for the bezier function
                t = t / pathingPoints[i].GetTravelTime();
                // return the point
                IsFinished = false;
                return(Bezier.GetPoint(transform.TransformPoint(pathingPoints[i].GetLocation()), transform.TransformPoint(pathingPoints[i].GetLocation() + pathingPoints[i].GetControlPoint(1)), transform.TransformPoint(pathingPoints[i + 1].GetLocation() + pathingPoints[i + 1].GetControlPoint(0)), transform.TransformPoint(pathingPoints[i + 1].GetLocation()), t));
            }
        }

        // return the final location possible
        IsFinished = true;
        return(Bezier.GetPoint(transform.TransformPoint(pathingPoints[pathingPoints.Length - 2].GetLocation()), transform.TransformPoint(pathingPoints[pathingPoints.Length - 2].GetLocation() + pathingPoints[pathingPoints.Length - 2].GetControlPoint(1)), transform.TransformPoint(pathingPoints[pathingPoints.Length - 1].GetLocation() + pathingPoints[pathingPoints.Length - 1].GetControlPoint(0)), transform.TransformPoint(pathingPoints[pathingPoints.Length - 1].GetLocation()), 1));
    }
Esempio n. 13
0
    // Get a point in the line related to the given parametric position (0 to 1)
    public Vector3 GetPoint(float t)
    {
        // T is the fractional part (0 to 1) to get the interpolation value for the sline curve
        // where 0 is the beggining of the spline, 1 is the end

        // However, we first have to find witch curve we are in

        int i; // the point in which will be returned

        // if t is 1 or more, set it to the last curve
        if (t >= 1f)
        {
            t = 1f;
            i = points.Length - 4;
        }
        else
        {
            t  = Mathf.Clamp01(t) * CurveCount;
            i  = (int)t;
            t -= 1;
            i *= 3;

            // to get the ACTUAL points, the curve index must be multiplied by 3
        }

        Vector3 bezierLocalPoint = Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t);

        return(transform.TransformPoint(bezierLocalPoint));
    }
Esempio n. 14
0
    public Vector3 GetPointL(float t)
    {
        int i;

        FixT(ref t, out i);
        return(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t));
    }
Esempio n. 15
0
    public OrientedPoint GetOrientedPoint(float t)
    {
        Vector3    tangent, normal;
        Quaternion orientation;

        int i;

        if (t >= 1f)
        {
            t = 1f;
            i = points.Length - 4;
        }
        else
        {
            t  = Mathf.Clamp01(t) * CurveCount;
            i  = (int)t;
            t -= i;
            i *= 3;
        }

        Vector3 point = Bezier.GetPoint(
            points[i], points[i + 1], points[i + 2], points[i + 3], t, out tangent, out normal, out orientation);

        return(new OrientedPoint(point, orientation, sampledLengths.Sample(t)));
    }
Esempio n. 16
0
    public Vector3 GetPoint(float t)
    {
        int i;

        if (t >= 1f)
        {
            t = 1f;
            i = points.Length - 4;
        }
        else
        {
            t  = Mathf.Clamp01(t) * CurveCount;
            i  = (int)t;
            t -= i;
            i *= 3;
        }
        Vector3 toReturn = Vector3.zero;

        try
        {
            toReturn = transform.TransformPoint(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t));
        }
        catch
        {
            Debug.Log(" Error in BesierSpline.cs - > Get point \n\tPoint length : " + points.Length + " \tindex : " + i);
            // temporary. I keept getting an error from this chunk of code but I can't find out why.
            // 1. The problem was the script didn't reliably keep the variable points populated. It should be fixed but I keep this herre so see.
        }

        return(toReturn);
    }
Esempio n. 17
0
    //------------------------------------------------------------------------------------------------------------------

    public void GenerateRuntimeData()
    {
        var results = new List <Point>();

        var index = 0;

        for (var i = 0; i < points.Count - 1; i += 3)
        {
            var p1 = points[i].position;
            var p2 = points[i + 1].position;
            var p3 = points[i + 2].position;
            var p4 = points[i + 3].position;

            for (float j = 0; j < curveSubdivision; j++)
            {
                var ratio = j / curveSubdivision;

                var position    = Bezier.GetPoint(p1, p2, p3, p4, ratio);
                var errorRadius = Mathf.Lerp(points[i].errorRadius, points[i + 3].errorRadius, ratio);

                results.Add(new Point(position, errorRadius * radiusForgiveness));
            }
        }

        var last = points.Last();

        last.errorRadius *= radiusForgiveness;

        results.Add(last);
        runtimePoints = results.ToArray();
    }
Esempio n. 18
0
    public Vector3 GetPoint(float t)
    {
        int i;

        // Catch wrap around
        if (t < 0.0f)
        {
            t = t + 1.0f;
        }
        if (t >= 1f)
        {
            t = t - 1f;
        }

        // Catch invalid values
        if (t < 0.0f)
        {
            t = 0.0f;
        }
        if (t > 1.0f)
        {
            t = 1.0f;
        }

        t  = Mathf.Clamp01(t) * CurveCount;
        i  = (int)t;
        t -= i;
        i *= 3;

        return(transform.TransformPoint(Bezier.GetPoint(controlPoints[i], controlPoints[i + 1], controlPoints[i + 2], controlPoints[i + 3], t)));
    }
Esempio n. 19
0
    public Vector3 GetPoint(float t)
    {
        t = Mathf.Clamp01(t);
        //0, 1, 2, 3, 4, 5, 6, 7, 8, 9
        int startIndex = 0;

        //t 가 1 과 같거나 크다면...
        if (t >= 1.0f)
        {
            t          = 1.0f;
            startIndex = this.points.Count - 4;     //마지막 커프 시작인덱스
        }
        else
        {
            //0, 1, 2, 3, 4, 5, 6, 7, 8, 9  -> 3Curve
            //t = 0.4f;

            t           = t * CurveCount; // 1.2
            startIndex  = (int)t;         // 1 ( CurveIndex )
            t           = t - startIndex; // 0.2f
            startIndex *= 3;              // 3
        }



        return(this.transform.TransformPoint(
                   Bezier.GetPoint(
                       points[startIndex + 0],
                       points[startIndex + 1],
                       points[startIndex + 2],
                       points[startIndex + 3],
                       t)));
    }
Esempio n. 20
0
    private float CalcCurveLenght(int curveIndex)
    {
        float     len        = 0;
        const int lineStep   = 1000;
        int       beginIndex = curveIndex * 3;
        Vector3   p0         = points[beginIndex];
        Vector3   p1         = points[beginIndex + 1];
        Vector3   p2         = points[beginIndex + 2];
        Vector3   p3         = points[beginIndex + 3];


        if (useSimpson)
        {
            mp0 = p0;
            mp1 = p1;
            mp2 = p2;
            mp3 = p3;

            len = beze_length(1);
        }
        else
        {
            Vector3 lineStart = Bezier.GetPoint(p0, p1, p2, p3, 0);
            for (int i = 1; i <= lineStep; ++i)
            {
                Vector3 lineEnd = Bezier.GetPoint(p0, p1, p2, p3, i / (float)lineStep);
                len      += (lineEnd - lineStart).magnitude;
                lineStart = lineEnd;
            }
        }

        return(len);
    }
Esempio n. 21
0
    private void OnDrawGizmosSelected()
    {
        if (pathToTravel == null || pathToTravel.Count <= 0)
        {
            return;
        }

        Color gColor = Gizmos.color;

        Gizmos.color = Color.red;

        Vector3 a, b, c = pathToTravel[0].Position;

        for (int i = 1; i < pathToTravel.Count; i++)
        {
            a = c;
            b = pathToTravel[i - 1].Position;
            c = (b + pathToTravel[i].Position) * 0.5f;
            for (float t = 0; t < 1; t += 0.01f)
            {
                Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), .2f);
            }
        }

        a = c;
        b = pathToTravel[pathToTravel.Count - 1].Position;
        c = b;
        for (float t = 0; t < 1; t += 0.01f)
        {
            Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), .2f);
        }

        Gizmos.color = gColor;
    }
Esempio n. 22
0
    /// <summary>
    /// 画出当前的路线行驶
    /// </summary>
    void OnDrawGizmos()
    {
        if (pathToTravel == null || pathToTravel.Count == 0)
        {
            return;
        }

        Vector3 a, b, c = pathToTravel[0].Position;

        for (int i = 1; i < pathToTravel.Count; i++)
        {
            a = c;
            b = pathToTravel[i - 1].Position;
            c = (b + pathToTravel[i].Position) * 0.5f;
            for (float t = 0f; t < 1f; t += Time.deltaTime * travelSpeed)
            {
                Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), 2f);
            }
        }

        a = c;
        b = pathToTravel[pathToTravel.Count - 1].Position;
        c = b;
        for (float t = 0f; t < 1f; t += 0.1f)
        {
            Gizmos.DrawSphere(Bezier.GetPoint(a, b, c, t), 2f);
        }
    }
Esempio n. 23
0
    private bool m_ended = false;               //Bool that turns true if disc reaches end of Bezier curve and hasn't collided with anything.


    // Update is called once per frame
    void Update()
    {
        //Get flight duration from DiscController and DiscThrow sripts.
        m_duration = (GetComponentInParent <DiscController>().m_durationmulti *DiscThrow.m_styledurationmulti);

        //If disc hasn't collided...
        if (!m_Collided)
        {
            //...move disc along the curve
            Vector3 tepm = m_curve.GetVelocity(0.98f).normalized *m_duration;
            m_progress += Time.deltaTime / (m_duration * m_timemulti);
            Vector3 position = m_curve.GetPoint(m_progress);

            //If disc has nearly reached end of Bezier curve change m_ended to true and set velocity of disc.
            if (m_progress >= 0.99f && !m_ended)
            {
                m_ended         = true;
                m_rigb.velocity = tepm;
                print("m_rigb: " + m_rigb.velocity);
            }
            //Move disc with rigidbody and velocity to last known position on the Bezier path and let physics take over.
            else if (m_progress <= 1f)
            {
                transform.position = position;
                print("m_rigb normal: " + m_rigb);
            }
            //If bool look forward is true, transform disc along with the direction of curve.
            if (m_lookForward)
            {
                transform.LookAt(position + m_curve.GetDirection(m_progress));
            }
        }
    }
Esempio n. 24
0
    public Vector3 GetPoint(float t)
    {
        float alpha;
        int   i = GetIndexFromTime(t, out alpha);

        return(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], alpha));
    }
Esempio n. 25
0
    private void MovePosition(Vector3 a, Vector3 b, Vector3 c, float t)
    {
        transform.localPosition = Bezier.GetPoint(a, b, c, t);
        Vector3 d = Bezier.GetDerivative(a, b, c, t);

        d.y = 0f;
        transform.localRotation = Quaternion.LookRotation(d);
    }
Esempio n. 26
0
    public Vector3 GetPoint(float t)
    {
        //quadratic
        //return transform.TransformPoint(Bezier.GetPoint(points[0], points[1], points[2], t));

        //cubic
        return(transform.TransformPoint(Bezier.GetPoint(points[0], points[1], points[2], points[3], t)));
    }
Esempio n. 27
0
    public Vector3 GetPointLength()
    {
        int   i;
        float t = 1f;

        i = points.Length - 4;
        return(transform.TransformPoint(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t)));
    }
Esempio n. 28
0
    IEnumerator TravelPath()
    {
        Vector3 a, b, c = pathToTravel[0].Position;

        yield return(LookAt(pathToTravel[1].Position));

        Grid.DecreaseVisibility(currentTravelLocation ? currentTravelLocation : this.pathToTravel[0], visionRange);

        float t = Time.deltaTime * travelSpeed;

        for (int i = 1; i < pathToTravel.Count; i++)
        {
            currentTravelLocation = pathToTravel[i];
            a = c;
            b = pathToTravel[i - 1].Position;
            c = (b + currentTravelLocation.Position) * 0.5f;
            Grid.IncreaseVisibility(currentTravelLocation, visionRange);

            for (; t < 1f; t += Time.deltaTime * travelSpeed)
            {
                transform.localPosition = Bezier.GetPoint(a, b, c, t);
                Vector3 d = Bezier.GetDerivative(a, b, c, t);
                d.y = 0f;
                transform.localRotation = Quaternion.LookRotation(d);

                yield return(null);
            }

            Grid.DecreaseVisibility(currentTravelLocation, visionRange);

            t -= 1f;
        }

        currentTravelLocation = null;

        a = c;
        b = location.Position;
        c = b;

        Grid.IncreaseVisibility(location, visionRange);

        for (; t < 1f; t += Time.deltaTime * travelSpeed)
        {
            transform.localPosition = Bezier.GetPoint(a, b, c, t);
            Vector3 d = Bezier.GetDerivative(a, b, c, t);
            d.y = 0f;
            transform.localRotation = Quaternion.LookRotation(d);

            yield return(null);
        }

        transform.localPosition = location.Position;
        orientation             = transform.localRotation.eulerAngles.y;

        ListPool <HexCell> .Add(pathToTravel);

        pathToTravel = null;
    }
Esempio n. 29
0
        private Vector3d GetModifiedNormal(Vector3d uvw, Vector3 normal, double offset = 0.005)
        {
            Vector3d offsetUVW = uvw - offset * normal.Double();
            //Vector3d offsetUVW = (uvw - Vector3d.One * 0.5) * (1.0 - offset) + Vector3d.One * 0.5;
            var basePoint = Bezier.GetPoint(_data.DataPoints, uvw);
            var off       = Bezier.GetPoint(_data.DataPoints, offsetUVW);

            return((basePoint - off).Normalized());
        }
Esempio n. 30
0
    public Vector3 GetEvenPoint(float oldT)
    {
        int   i;
        float newT;

        GetEvenCurveT(oldT, out i, out newT);

        return(transform.TransformDirection(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], newT)));
    }