Exemplo n.º 1
0
        // TODO: Pass nodes into actual line draw thingy
        public float GetConnectionCenterY(SF_NodeConnector cA, SF_NodeConnector cB)
        {
            Rect a = cA.node.rect;
            Rect b = cB.node.rect;

            if (cA.GetConnectionPoint().y > cB.GetConnectionPoint().y)
            {
                return(0.5f * (a.yMax + b.yMin));
            }
            else
            {
                return(0.5f * (b.yMax + a.yMin));
            }
        }
Exemplo n.º 2
0
        public static Vector2[] ConnectionBezierOffsetArray(float offset, SF_NodeConnector startCon, SF_NodeConnector endCon, int segments)
        {
            Vector2 start = startCon.GetConnectionPoint();
            Vector2 end   = endCon.GetConnectionPoint();

            bool reversed = (start.x < end.x);

            Vector2[] points;

            int pCount = (segments + 1);           // Point count per bezier

            if (reversed)
            {
                points = new Vector2[pCount * 2];               // Two curves
            }
            else
            {
                points = new Vector2[pCount];
            }



            if (reversed)
            {
                // Calculate new start/end positions!
                // We want an S shape, which essentially is two curves with a connected center
                // Let's define the new points!


                float midVert;

                if (startCon.node.rect.center.y > endCon.node.rect.center.y)
                {
                    midVert = (startCon.node.BoundsTop() + endCon.node.BoundsBottom()) / 2;
                }
                else
                {
                    midVert = (startCon.node.BoundsBottom() + endCon.node.BoundsTop()) / 2;
                }



                float deltaX = Mathf.Abs(start.x - end.x);
                float mul    = Mathf.InverseLerp(0f, 100f, deltaX);
                mul = SF_Tools.Smoother(mul) * 0.70710678118f;


                Vector2 bAp0 = start;                                         // Start Point
                Vector2 bAp3 = new Vector2(start.x, midVert);                 // End Point



                float   tangentMag = Mathf.Abs(bAp0.y - bAp3.y) * mul;           // TODO: Scale based on length if smaller than something
                Vector2 tangentVec = new Vector2(tangentMag, 0f);


                Vector2 bAp1 = bAp0 - tangentVec;                                       // Start Tangent
                Vector2 bAp2 = bAp3 - tangentVec;                                       // End Tangent


                for (int i = 0; i < pCount; i++)
                {
                    float t = (float)i / (float)segments;
                    points[i] = CubicBezierOffset(offset, bAp0, bAp1, bAp2, bAp3, t);
                }

                // Second line! Let's go

                Vector2 bBp0 = new Vector2(end.x, midVert);                // Start Point
                Vector2 bBp3 = end;                                        // End Point

                tangentMag = Mathf.Abs(bBp0.y - bBp3.y) * mul;             // TODO: Scale based on length if smaler than something
                tangentVec = new Vector2(tangentMag, 0f);

                Vector2 bBp1 = bBp0 + tangentVec;                                       // Start Tangent
                Vector2 bBp2 = bBp3 + tangentVec;                                       // End Tangent

                for (int i = 0; i < pCount; i++)
                {
                    float t = (float)i / (float)segments;
                    points[i + pCount] = CubicBezierOffset(offset, bBp0, bBp1, bBp2, bBp3, t);
                }
            }
            else
            {
                for (int i = 0; i < pCount; i++)
                {
                    float t = (float)i / (float)segments;
                    points[i] = ConnectionBezierOffset(offset, start, end, t);
                }
            }



            return(points);
        }