private void GenerateSegments(SpriteShapeController sc, List <ShapeAngleRange> angleRanges)
        {
            var          controlPointCount = sc.spline.GetPointCount();
            var          angleRangeIndices = new int[controlPointCount];
            ShapeSegment activeSegment     = new ShapeSegment()
            {
                start = -1, end = -1, angleRange = -1
            };

            m_ShapeSegments.Clear();

            for (int i = 0; i < controlPointCount; ++i)
            {
                var   actv = i;
                var   next = SplineUtility.NextIndex(actv, controlPointCount);
                var   pos1 = sc.spline.GetPosition(actv);
                var   pos2 = sc.spline.GetPosition(next);
                bool  continueStrip = (sc.spline.GetTangentMode(actv) == ShapeTangentMode.Continuous), edgeUpdated = false;
                float angle = 0;
                if (false == continueStrip || activeSegment.start == -1)
                {
                    angle = SplineUtility.SlopeAngle(pos1, pos2) + 90.0f;
                }

                next = (!sc.spline.isOpenEnded && next == 0) ? (actv + 1) : next;
                int mn = (actv < next) ? actv : next;
                int mx = (actv > next) ? actv : next;

                var anglerange = RangeFromAngle(angleRanges, angle);
                angleRangeIndices[actv] = anglerange;
                if (anglerange == -1)
                {
                    activeSegment = new ShapeSegment()
                    {
                        start = mn, end = mx, angleRange = anglerange
                    };
                    m_ShapeSegments.Add(activeSegment);
                    continue;
                }

                // Check for Segments. Also check if the Segment Start has been resolved. Otherwise simply start with the next one
                if (activeSegment.start != -1)
                {
                    continueStrip = continueStrip && (angleRangeIndices[activeSegment.start] != -1);
                }

                bool canContinue = (actv != (controlPointCount - 1)) || (!sc.spline.isOpenEnded && (actv == (controlPointCount - 1)));
                if (continueStrip && canContinue)
                {
                    for (int s = 0; s < m_ShapeSegments.Count; ++s)
                    {
                        activeSegment = m_ShapeSegments[s];
                        if (activeSegment.start - mn == 1)
                        {
                            edgeUpdated         = true;
                            activeSegment.start = mn;
                            m_ShapeSegments[s]  = activeSegment;
                            break;
                        }
                        if (mx - activeSegment.end == 1)
                        {
                            edgeUpdated        = true;
                            activeSegment.end  = mx;
                            m_ShapeSegments[s] = activeSegment;
                            break;
                        }
                    }
                }

                if (!edgeUpdated)
                {
                    activeSegment.start      = mn;
                    activeSegment.end        = mx;
                    activeSegment.angleRange = anglerange;
                    m_ShapeSegments.Add(activeSegment);
                }
            }
        }
Example #2
0
        private void buttonLine_Click(object sender, EventArgs e)
        {
            Shape shape = new ShapeSegment(5);

            ModifyRigidBody(shape);
        }