Exemplo n.º 1
0
        private static int DefaultBezierSubdivisions(CCVector2 p0, CCVector2 p1, CCVector2 p2)
        {
            CCVector2 p01 = CCVector2.Lerp(p0, p1, .5f);
            CCVector2 p12 = CCVector2.Lerp(p1, p2, .5f);

            float dist = ApproxDistance(p0, p01) + ApproxDistance(p01, p12) + ApproxDistance(p12, p2);

            return((int)(dist * 0.10f));
        }
Exemplo n.º 2
0
        private int BuildArcGeometryBuffer(CCVector2 p0, CCVector2 p1, float height, int subdivisions)
        {
            var edge01 = p1 - p0;
            var p01mid = CCVector2.Lerp(p0, p1, 0.5f);

            float width  = edge01.Length();
            float radius = (height / 2) + (width * width) / (height * 8);

            edge01.Normalize();
            var edge01t = new CCVector2(-edge01.Y, edge01.X);
            var center  = p01mid + edge01t * (radius - height);

            float startAngle = PointToAngle(center, p0);
            float endAngle   = PointToAngle(center, p1);

            float arcAngle;

            if (height >= 0)
            {
                if (height < width / 2)
                {
                    arcAngle = (Math.Abs(endAngle - startAngle) < Math.PI)
                        ? endAngle - startAngle
                        : endAngle + (float)Math.PI * 2 - startAngle;
                }
                else
                {
                    arcAngle = ((endAngle - startAngle) > Math.PI)
                        ? endAngle - startAngle
                        : endAngle + (float)Math.PI * 2 - startAngle;
                }
            }
            else
            {
                if (-height < width / 2)
                {
                    arcAngle = (Math.Abs(endAngle - startAngle) < Math.PI)
                        ? endAngle - startAngle
                        : endAngle - (float)Math.PI * 2 - startAngle;
                }
                else
                {
                    arcAngle = ((endAngle - startAngle) > Math.PI)
                        ? startAngle - endAngle
                        : endAngle - (float)Math.PI * 2 - startAngle;
                }
            }

            return(BuildArcGeometryBuffer(center, Math.Abs(radius), subdivisions, startAngle, arcAngle));
        }