示例#1
0
    // dessine une edge d'une epaisseur thickness en appliquant les transformations
    // de planMatrix
    public static void Draw(Edge2 edge, Matrix4x4 planMatrix, int thickness = 10, 
		float offsetWidth=0, float offsetHeight=0)
    {
        Matrix4x4 matrix = GUI.matrix;

        Vector2 nextPt = edge.GetNextPoint2 ();
        nextPt.Set(nextPt.x+offsetWidth, nextPt.y+offsetHeight);
        nextPt = planMatrix.MultiplyPoint (nextPt);

        Vector2 prevPt = edge.GetPrevPoint2 ();
        prevPt.Set(prevPt.x+offsetWidth, prevPt.y+offsetHeight);
        prevPt = planMatrix.MultiplyPoint (prevPt);

        float angle = Vector2.Angle(nextPt - prevPt, Vector2.right);

        if (prevPt.y > nextPt.y)
        {
            angle = -angle;
        }

        GUIUtility.RotateAroundPivot (angle, prevPt);

        GUI.DrawTexture(new Rect (prevPt.x, prevPt.y - thickness / 2 ,
            (nextPt - prevPt).magnitude, thickness), SOLID_EDGE_TEXTURE);

        GUI.matrix = matrix;
    }
示例#2
0
    public void InsertPoint(Edge2 edge, Point2 point)
    {
        int edgeAndPointIndex = _edges.IndexOf (edge);

        if (edgeAndPointIndex < 0)
            return;

        Point2 nextPoint = edge.GetNextPoint2 ();
        Edge2 newEdge = new Edge2 (point, nextPoint);
        edge.SetNextPoint2 (point);
        point.SetEdges (edge, newEdge);
        nextPoint.SetPrevEdge (newEdge);

        _edges.Insert (edgeAndPointIndex + 1, newEdge);
        _points.Insert (edgeAndPointIndex + 1, point);

        Point2 prevPoint = edge.GetPrevPoint2 ();
        prevPoint.Update (false);
        point.Update (false);
        nextPoint.Update (false);

        UpdateBounds ();
    }
示例#3
0
    protected void FindIntersectedEdge()
    {
        _selectedEdgeIndexCandidate = -1;
        int edgeCounter = 0;

        float scale = 1 / _planTransformation.GetScale ().x;
        float pr = POINT_RADIUS * scale;

        // pour chaque edge on crée un rectangle de l'epaisseur POINT_RADIUS * currentScale
        // et de la longueur de l'edge. Puis on applique une transformation au curseur correspondant
        // a l'orientation de l'edge. Et on verifie que le curseur intersecte le rectangle.

        foreach (Edge2 edge in _polygon.GetEdges ())
        {
            Point2 prevPoint = edge.GetPrevPoint2 ();
            Point2 prevEdgePoint = new Point2 (prevPoint);
            if (prevPoint.GetJunction () == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = prevPoint as ArchedPoint2;
                prevEdgePoint.Set (aPoint.GetNextTangentPoint ());
            }

            Point2 nextPoint = edge.GetNextPoint2 ();
            Point2 nextEdgePoint = new Point2 (nextPoint);
            if (nextPoint.GetJunction () == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = nextPoint as ArchedPoint2;
                nextEdgePoint.Set (aPoint.GetPrevTangentPoint ());
            }

            Edge2 transformedEdge = new Edge2 (prevEdgePoint, nextEdgePoint);

            Vector2 prevPt = transformedEdge.GetPrevPoint2 ();
            prevPt.Set(prevPt.x+_offsetWidth, prevPt.y+_offsetHeight);
            Vector2 nextPt = transformedEdge.GetNextPoint2 ();
            nextPt.Set(nextPt.x+_offsetWidth, nextPt.y+_offsetHeight);

            Vector3 translation = new Vector3 (prevPt.x, 0, prevPt.y);
            Matrix4x4 translationMatrix = Matrix4x4.TRS (translation, Quaternion.identity, Vector3.one);

            Vector3 edgeVector = new Vector3 (transformedEdge.ToVector2 ().x, 0, transformedEdge.ToVector2 ().y);
            Quaternion rotation = Quaternion.FromToRotation (edgeVector, Vector3.right);
            Matrix4x4 rotationMatrix = Matrix4x4.TRS (Vector3.zero, rotation, Vector3.one);

            Matrix4x4 edgeMatrix = translationMatrix * rotationMatrix * translationMatrix.inverse;
            Vector3 transformedCursor3 = edgeMatrix.MultiplyPoint (new Vector3 (_cursor.x, 0, _cursor.y));
            Vector2 transformedCursor = new Vector2 (transformedCursor3.x, transformedCursor3.z);

            Rect edgeRect = new Rect (prevPt.x + (pr / 2),
                                      prevPt.y - (pr / 2),
                                      transformedEdge.GetLength () - pr,
                                      pr);

            if (edgeRect.Contains (transformedCursor))
            {
                _selectedEdgeIndexCandidate = edgeCounter;
        //				Debug.Log ("EDGE " + edgeCounter);
            }

            ++edgeCounter;
        }
    }