public void UpdatePicker(IColorable currentSelectable)
    {
        if (currentSelectable == null)
        {
            return;
        }

        if (currentSelectable.ColorFillArea)
        {
            _currentColor = currentSelectable.GetInlineAreaColor();
        }
        else
        {
            _currentColor = currentSelectable.GetPathColor();
        }

        _alpha.value = _currentColor.a;

        Color.RGBToHSV(_currentColor, out _currentHue, out _currentSaturation, out _currentValue);

        float   hue       = 360 * _currentHue;
        Vector2 direction = CurveMath.Rotate(Vector2.right, hue);

        _hueSelector.localPosition = direction.normalized * _hueRadius;
        _image.color = Color.HSVToRGB(_currentHue, 1, 1);

        Vector2 newPositon;

        newPositon.x = _currentSaturation * _svRectWidth - _saturationValueRectWidth;
        newPositon.y = _currentValue * _svRectWidth - _saturationValueRectWidth;
        _colorSelector.localPosition = newPositon;

        OnColorChanged?.Invoke(currentSelectable.GetInlineAreaColor(), currentSelectable.GetPathColor());
    }
Esempio n. 2
0
        public void OnPointDragged(MovePointBehaviour.PointMoveEventArgs e)
        {
            var oldPoint = e.OldPoint;
            var newPoint = e.NewPoint;

            var index            = Curve.IndexOf(e.OldPoint);
            var prevPoint        = Curve.Points[index - 1];
            var biggestValueForY = double.MinValue;

            var newCurve = Curve.Points.GetRange(0, Curve.Points.Count);

            newCurve[index] = newPoint;
            var lastPoint = newCurve[newCurve.Count - 1];

            for (double x = 0; x < lastPoint.X; x++)
            {
                var y = CurveMath.SolveCubicSpline(newCurve, x);
                if (biggestValueForY > y)
                {
                    newPoint = oldPoint;
                    break;
                }

                if (y > biggestValueForY)
                {
                    biggestValueForY = y;
                }
            }

            e.NewPoint          = newPoint;
            Curve.Points[index] = e.NewPoint;

            Points = CalculateNewPoints();
        }
    void SetInsertedHandlesPosition(BezierSegment insertedSegment, BezierSegment neighborSegment, BezierSegment segment)
    {
        int index = _currentHoverData.HoveredSegmentPointIndex;

        Vector2 tangent      = segment.Tangent(index - 1);
        float   segmentCount = segment.SegmentCount;
        float   quotient     = (index / segmentCount);

        Vector2 b = segment.SegmentPoints[index - 1];

        insertedSegment.Point = b;

        Vector2 q = CurveMath.GetPointOnLine(neighborSegment.SecondHandle, segment.FirstHandle, quotient);

        Vector2 q0 = neighborSegment.MoveHandleCloserToPoint(1 - quotient, true);

        segment.MoveHandleCloserToPoint(quotient, false);

        Vector2 r0 = CurveMath.GetIntersectionPointCoordinates(q0, q - q0, b, tangent);

        insertedSegment.SecondHandle = b + (b - r0) / index * (segmentCount - index);
        insertedSegment.FirstHandle  = r0;

        _currentPathObject.UpdatePointsHandlesRenderer();
    }
Esempio n. 4
0
    public virtual void OnDrawGizmos()
    {
        if (!ShowCurve || !P0 || !P1 || !P0_Tangent || !P1_Tangent)
        {
            return;
        }

        //draw tangents
        Gizmos.color = new Color(1, 0, 0, 1.0f);
        Gizmos.DrawLine(P0.transform.position, P0_Tangent.transform.position);
        Gizmos.color = new Color(1, 0, 0, 1.0f);
        Gizmos.DrawLine(P1.transform.position, P1_Tangent.transform.position);

        //draw curve
        Vector3 prevPos = P0.transform.position;

        for (int c = 1; c <= Resolution; c++)
        {
            float   t       = (float)c / Resolution;
            Vector3 currPos = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            Vector3 currTan = (currPos - prevPos).normalized;
            float   mag     = (currPos - prevPos).magnitude;

            Gizmos.color = new Color(0, 0, mag, 1);
            Gizmos.DrawLine(prevPos, currPos);

            prevPos = currPos;
        }
    }
Esempio n. 5
0
    public override bool OverPathObject()
    {
        Vector2 mousePosition = Program.Instance.GetMouseCanvasPosition();

        // not over bounding box

        if (!MouseOverObject())
        {
            return(false);
        }

        int crossings = 0;

        for (int i = 0; i < _pointsSorted.Count - 1; i++)
        {
            float biggerY = _pointsSorted[i].y > _pointsSorted[i + 1].y ? _pointsSorted[i].y : _pointsSorted[i + 1].y;

            bool isFound;

            if (mousePosition.y <= biggerY)
            {
                if ((mousePosition.x >= _pointsSorted[i].x && mousePosition.x <= _pointsSorted[i + 1].x) || (mousePosition.x <= _pointsSorted[i].x && mousePosition.x >= _pointsSorted[i + 1].x))
                {
                    if (mousePosition.y <= CurveMath.GetIntersectionPointCoordinates(_pointsSorted[i], _pointsSorted[i + 1], mousePosition, mousePosition + Vector2.up, out isFound).y)
                    {
                        if (isFound)
                        {
                            crossings++;
                        }
                    }
                }
            }
        }
        return(crossings % 2 == 1);
    }
    void BezierCurve(BezierSegment otherSegment)
    {
        int segments = SegmentCount;

        for (int i = 1; i <= segments; i++)
        {
            float   t = i / (float)segments;
            Vector2 pointToAddWithZIsIndex = CurveMath.CalculateBezierPoint(t, otherSegment.Point, otherSegment.SecondHandle, FirstHandle, Point);
            segmentPoints[i - 1] = pointToAddWithZIsIndex;
        }
        _pathObject.UpdateLineRenderer(this);
    }
Esempio n. 7
0
    private void GetCorePoints(ref Vector3[] pos)
    {
        Vector3 prevPos = P0.transform.position;

        pos[0] = prevPos;
        float lastId = (float)(Resolution - 1);

        for (int c = 1; c < Resolution; c++)
        {
            float t = c / lastId;
            pos[c]  = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            prevPos = pos[c];
        }
    }
Esempio n. 8
0
    public override List <PathPointData> GetPathData(float prevDistance, Vector3 prevPosition)
    {
        List <PathPointData> pathData = new List <PathPointData>();
        int     iterations            = 20;
        Vector3 prevPoint;
        Vector3 currPoint;
        float   distance = prevDistance;

        for (int nodeIndex = 0; nodeIndex < CurveNodes.Count - 1; nodeIndex++)
        {
            prevPoint = CurveNodes[nodeIndex].NodePosiion;

            for (int i = 1; i <= iterations; i++)
            {
                currPoint = CurveMath.NodeLerpPostion(
                    CurveNodes[nodeIndex],
                    CurveNodes[nodeIndex + 1],
                    (float)i / (float)iterations);

                pathData.Add(
                    new PathPointData(
                        distance,
                        prevPoint + prevPosition,
                        CurveMath.NodeLerpRotation(
                            CurveNodes[nodeIndex],
                            CurveNodes[nodeIndex + 1],
                            currPoint - prevPoint,
                            (float)i / (float)iterations)));

                distance += (currPoint - prevPoint).magnitude;
                prevPoint = currPoint;
            }
        }

        pathData.Add(
            new PathPointData(
                distance,
                CurveNodes[CurveNodes.Count - 1].NodePosiion + prevPosition,
                CurveNodes[CurveNodes.Count - 1].GetMainRotation()));

        return(pathData);
    }
Esempio n. 9
0
    public void CalculateVelocityField()
    {
        VelocityField.Clear();

        Vector3 prevPos = P0.transform.position;

        for (int c = 1; c <= Resolution; c++)
        {
            float   t       = (float)c / Resolution;
            Vector3 currPos = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            Vector3 currTan = (currPos - prevPos).normalized;
            float   mag     = VelocityMagCurve.Evaluate(t);

            VelocityFieldNode ti = new VelocityFieldNode();
            ti.TargetPosition = prevPos;
            ti.TargetVelocity = currTan;
            ti.Mag            = mag;
            VelocityField.Add(ti);
            prevPos = currPos;
        }
    }
Esempio n. 10
0
        public void OnPointDragged(MovePointBehaviour.PointMoveEventArgs e)
        {
            var oldPoint = e.OldPoint;
            var newPoint = e.NewPoint;

            var index = Curve.IndexOf(e.OldPoint);

            var newCurve = Curve.Points.GetRange(0, Curve.Points.Count);

            newCurve[index] = newPoint;

            var firstPoint = newCurve[0];
            var lastPoint  = newCurve[newCurve.Count - 1];

            var biggestValueForY = double.MinValue;

            if (ValidateCurve)
            {
                for (double x = firstPoint.X + 0.01; x < lastPoint.X - 0.01; x++)
                {
                    var y = CurveMath.SolveCubicSpline(newCurve, x);
                    if (y < biggestValueForY || newPoint.X >= lastPoint.X || newPoint.X <= firstPoint.X)
                    {
                        newPoint = oldPoint;
                        break;
                    }

                    if (y > biggestValueForY)
                    {
                        biggestValueForY = y;
                    }
                }
            }

            e.NewPoint          = newPoint;
            Curve.Points[index] = e.NewPoint;

            Points = CalculateNewPoints();
            UpdateSelectedPoint();
        }
    void IsAnyOtherPointBelow(out bool isAnysmaller, Vector2 left, Vector2 right)
    {
        float leftY            = left.y;
        float leftX            = left.x;
        float rightY           = right.y;
        float rightX           = right.x;
        float _currentSmallest = float.MaxValue;

        isAnysmaller = false;

        for (int i = 2; i < _points.Count - 2; i++)
        {
            Vector2 currentPoint = _points[i];

            if (currentPoint.x > leftX && currentPoint.x < rightX)
            {
                float currentY = currentPoint.y;
                if (currentY < leftY && currentY < rightY)
                {
                    Vector2 followingPoint = _points[i + 1];
                    Vector2 previousPoint  = _points[i - 1];
                    if ((previousPoint.y > leftY && previousPoint.x > leftX && previousPoint.x < rightX) ||
                        (followingPoint.y > leftY && followingPoint.x > leftX && followingPoint.x < rightX))
                    {
                        bool    found;
                        Vector2 intersection = CurveMath.GetIntersectionPointCoordinates(currentPoint, previousPoint, left, right, out found);
                        if (found && CurveMath.IsPointOnLine(left, right, intersection))
                        {
                            if (currentY < _currentSmallest)
                            {
                                _currentSmallest = currentY;
                                beneathIndex     = i;
                                isAnysmaller     = true;
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 12
0
        private IEnumerable <Point> CalculateNewPoints()
        {
            var points = CurveMath.GetInterpolatedCubicSplinedCurve(Curve.Points);

            return(points);
        }
Esempio n. 13
0
 public double getY(double x)
 {
     return(CurveMath.SolveCubicSpline(curve.Points, x));
 }
Esempio n. 14
0
 public void GetPositionAt(float val, ref Vector3 pos)
 {
     val = Mathf.Clamp(val, 0.0f, 1.0f);
     pos = CurveMath.CalculateBezierPoint(val, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
 }
        private void UpdateCurve()
        {
            var points = model.Curve.Points;

            Points = CurveMath.GetInterpolatedCubicSplinedCurve(model.Curve.Points);
        }
Esempio n. 16
0
 private IEnumerable <Point> CalculateNewPoints()
 {
     return(CurveMath.GetInterpolatedCubicSplinedCurve(Model.Points));
 }