public void Update()
    {
        input.Update();

        if (visuals.drawSlicer == false)
        {
            return;
        }

        visuals.Clear();

        for (int id = 0; id < 10; id++)
        {
            if (linearPair[id].A.ToVector2() == Vector2.zero && linearPair[id].B.ToVector2() == Vector2.zero)
            {
                continue;
            }

            if (input.GetVisualsEnabled(id) == false)
            {
                continue;
            }

            visuals.GenerateLinearMesh(linearPair[id], transform);
        }

        visuals.Draw();
    }
Esempio n. 2
0
    public void Update()
    {
        input.Update();

        if (visuals.drawSlicer == false)
        {
            return;
        }

        if (linearPair.A.ToVector2() == Vector2.zero && linearPair.B.ToVector2() == Vector2.zero)
        {
            return;
        }

        visuals.Clear();
        visuals.GenerateLinearMesh(linearPair, transform);
        visuals.Draw();


        if (target != null)
        {
            Polygon2D poly = target.shape.GetWorld();

            int pointIDA = ((verticeID - 1) + poly.pointsList.Count) % poly.pointsList.Count;
            int pointIDB = verticeID;
            int pointIDC = (verticeID + 1) % poly.pointsList.Count;

            Vector2 pointA = poly.pointsList[pointIDA].ToVector2();
            Vector2 pointB = poly.pointsList[pointIDB].ToVector2();
            Vector2 pointC = poly.pointsList[pointIDC].ToVector2();

            double angle = Math2D.FindAngle(pointA, pointB, pointC);

            Vector2D offset = new Vector2D(pointB);

            double angleZero = Vector2D.Atan2(new Vector2D(pointA), new Vector2D(pointB));

            Debug.Log(angle * Mathf.Rad2Deg);

            offset.Push(-angle / 2 + angleZero, 0.5f);

            linearPair.A = offset;
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector2D point = input.GetInputPosition(0);

            if (target != null)
            {
                Polygon2D poly = target.shape.GetWorld();
                if (poly.PointInPoly(point) == false)
                {
                    target = null;

                    linearPair.A = Vector2D.Zero();
                    linearPair.B = Vector2D.Zero();
                }
            }

            foreach (Slicer2D slicer in Slicer2D.GetList())
            {
                Polygon2D poly = slicer.shape.GetWorld();
                if (poly.PointInPoly(point))
                {
                    int    id       = 0;
                    double distance = 1000000;

                    foreach (Vector2D p in poly.pointsList)
                    {
                        double newDistance = Vector2D.Distance(p, point);
                        if (newDistance < distance)
                        {
                            distance = newDistance;
                            id       = poly.pointsList.IndexOf(p);
                        }
                    }

                    verticeID = id;
                    target    = slicer;

                    break;
                }
            }
        }
    }