示例#1
0
        //------------------------------------------------------------------------

        ClipResult clip(ref Vector4 pleq)
        {
            int n = m_points.Count();

            if (s_clipBuffer[0] == null || (int)s_clipBuffer[0].Count() < n * 2)
            {
                s_clipBuffer[0] = new List <Vector3>();
                s_clipBuffer[1] = new List <Vector3>();
                for (int i = 0; i < n * 2; i++)
                {
                    Vector3 v  = new Vector3();
                    Vector3 v1 = new Vector3();
                    s_clipBuffer[0].Add(v);
                    s_clipBuffer[1].Add(v1);
                }
            }

            int        clippedVertexCount = 0;
            ClipResult result             = clipInner(
                ref m_points, m_points.Count(),
                ref s_clipBuffer[0], ref clippedVertexCount,
                ref pleq);

            for (int i = 0; i < clippedVertexCount; i++)
            {
                m_points.Add(new Vector3(s_clipBuffer[0][i]));
            }

            return(result);
        }
示例#2
0
        //------------------------------------------------------------------------

        public ClipResult clip(ref AABB aabb)
        {
            bool clipped = false;

            for (int axis = 0; axis < 3; axis++)
            {
                for (int dir = 0; dir < 2; dir++)
                {
                    Vector4 pleq = new Vector4(0, 0, 0, 0);
                    pleq[axis] = dir == 0 ? 1 : -1;
                    pleq.w     = -pleq[axis] * (dir == 0 ? aabb.m_mn[axis] : aabb.m_mx[axis]);

                    ClipResult res = clip(ref pleq);
                    if (res == ClipResult.CLIP_VANISHED)
                    {
                        return(ClipResult.CLIP_VANISHED);
                    }
                    else if (res == ClipResult.CLIP_CLIPPED)
                    {
                        clipped = true;
                    }
                }
            }

            if (clipped)
            {
                return(ClipResult.CLIP_CLIPPED);
            }

            return(ClipResult.CLIP_ORIGINAL);
        }
示例#3
0
        private static void clipPolygonBottom(List <Point> src, List <Point> dst, double bottom)
        {
            dst.Clear();
            for (int i = 0; i < src.Count; i++)
            {
                int next = (i + 1) % src.Count;

                Point      clippedPoint = new Point();
                ClipResult clipResult   =
                    clipBottomLine(src[i], src[next], clippedPoint, bottom);
                switch (clipResult)
                {
                case ClipResult.A_IN:
                    dst.Add(src[i]);
                    dst.Add(clippedPoint);
                    break;

                case ClipResult.B_IN:
                    dst.Add(clippedPoint);
                    break;

                case ClipResult.BOTH_IN:
                    dst.Add(src[i]);
                    break;

                case ClipResult.BOTH_OUT:
                    break;
                }
            }
        }
        private void ClipAndDraw(Graphics g, Color c, Rectangle window, PointF a, PointF b)
        {
            ClipResult result = LiangBarsky.ClipLine(window, a, b);

            if (result.Visible)
            {
                using (Pen p = new Pen(c))
                    g.DrawLine(p, result.A, result.B);
            }
        }
示例#5
0
        public ClipResult clipInner(ref List <Vector3> inPoints, int numInPoints,
                                    ref List <Vector3> outPoints, ref int numOutPoints,
                                    Vector4 pleq)
        {
            numOutPoints = 0;
            if (numInPoints == 0)
            {
                return(ClipResult.CLIP_VANISHED);
            }

            ClipResult result = ClipResult.CLIP_ORIGINAL;
            Vector3    a;
            Vector3    b  = inPoints[numInPoints - 1];
            float      sa = 0;
            float      sb = Vector4.dot(ref b, ref pleq);

            for (int i = 0; i < numInPoints; i++)  // 障碍物
            {
                a  = b;
                b  = inPoints[i];
                sa = sb;
                sb = Vector4.dot(ref b, ref pleq);
                bool na = sa < 0;
                bool nb = sb < 0;

                if (!na && !nb)
                {
                    outPoints[numOutPoints++] = b;
                    continue;
                }

                result = ClipResult.CLIP_CLIPPED;
                if (na && nb)
                {
                    continue;
                }

                float   cval = sa / (sa - sb);
                Vector3 c    = a + cval * (b - a);

                outPoints[numOutPoints++] = c;

                if (na)
                {
                    outPoints[numOutPoints++] = b;
                }
            }

            if (numOutPoints == 0)
            {
                return(ClipResult.CLIP_VANISHED);
            }
            return(result);
        }
示例#6
0
    public ClipResult ClipTri(Edge edgeA, Edge edgeB, List <Triangle> clippedtris)
    {
        if (TriAContainsTriB(edgeA, edgeB))
        {
            return(ClipResult.BINSIDEA);
        }
        List <EdgeClip> clippededges = new List <EdgeClip>();
        ClipResult      r            = ClipResult.OUTSIDE;
        int             n;

        mCoincident = null;
        n           = ClipAgainstEdge(edgeA, edgeB, clippededges);
        if (mCoincident == edgeB)
        {
            Edge adjacentA = edgeA.Tri.Edges[(edgeA.EdgeIndex + 2) % 3];
            clippededges.Clear();
            n = ClipAgainstEdge(adjacentA, edgeB, clippededges);
        }
        if ((n >= 2) &&
            ((clippededges[0].Status & EdgeClip.OUTSIDE) == 0))
        {
            r = ClipTriangles(edgeA.Tri, edgeB.Tri, clippededges[0], clippededges[1], clippedtris);
        }
        switch (r)
        {
        case ClipResult.CLIPPED:
            mIntersections[0] = clippededges[0].IntersectionPoint;
            mIntersections[1] = clippededges[1].IntersectionPoint;
            mClippedEdges[0]  = clippededges[0].Clipped;
            mClippedEdges[1]  = clippededges[1].Clipped;
            return(ClipResult.ACLIPSB);

        case ClipResult.INSIDE:
            return(ClipResult.BINSIDEA);
        }
        return(ClipResult.OUTSIDE);
    }
示例#7
0
        //------------------------------------------------------------------------

        public ClipResult clip(ref Beam beam)
        {
            int m = numPoints();

            if (m == 0)
            {
                return(ClipResult.CLIP_VANISHED);
            }

            int n = beam.numPleqs();

            if (n == 0)
            {
                return(ClipResult.CLIP_ORIGINAL);
            }

            ClipResult result = ClipResult.CLIP_ORIGINAL;

            if (s_clipBuffer[0] == null || (int)s_clipBuffer[0].Count < (n + m) * 2)
            {
                s_clipBuffer[0] = new List <Vector3>();
                s_clipBuffer[1] = new List <Vector3>();

                for (int i = 0; i < (n + m) * 2; i++)
                {
                    s_clipBuffer[0].Add(new Vector3());
                    s_clipBuffer[1].Add(new Vector3());
                }
            }

            int        clippedVertices = 0;
            ClipResult res             = clipInner(
                ref m_points, m_points.Count,
                ref s_clipBuffer[0], ref clippedVertices,
                beam.getPleq(0));

            if (res == ClipResult.CLIP_VANISHED)
            {
                return(ClipResult.CLIP_VANISHED);
            }
            else if (res == ClipResult.CLIP_CLIPPED)
            {
                result = ClipResult.CLIP_CLIPPED;
            }

            List <Vector3> clipSource = s_clipBuffer[0];  // 新的障碍物面
            List <Vector3> clipTarget = s_clipBuffer[1];

            for (int i = 1; i < n; i++)  // 对beam的每一个面
            {
                int newClippedVertices = 0;
                res = clipInner(
                    ref clipSource, clippedVertices,
                    ref clipTarget, ref newClippedVertices,
                    beam.getPleq(i));

                clippedVertices = newClippedVertices;
                List <Vector3> tmp = clipSource;
                clipSource = clipTarget;
                clipTarget = tmp;

                if (res == ClipResult.CLIP_VANISHED)
                {
                    return(ClipResult.CLIP_VANISHED);
                }
                else if (res == ClipResult.CLIP_CLIPPED)
                {
                    result = ClipResult.CLIP_CLIPPED;
                }
            }

            m_points = new List <Vector3>(new Vector3[clippedVertices]);
            for (int i = 0; i < clippedVertices; i++)
            {
                m_points[i] = clipSource[i];
            }

            return(result);
        }
示例#8
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;

            if (e.ProgressPercentage != 100)
            {
                return;
            }

            txtConsole.Text = "";

            ClipResult result = (ClipResult)e.UserState;

            if (result.status != "success")
            {
                txtConsole.AppendText(result.status + System.Environment.NewLine);
                txtConsole.AppendText(result.message);
                ModifyProgressBarColor.SetState(progressBar1, 2);
                return;
            }

            foreach (ParsedLink link in result.ParsedLinks)
            {
                richTextBox1.SelectionColor = link.GetColour();
                if (!link.AlternativeProposed)
                {
                    if (link.Url.Count == 1)
                    {
                        richTextBox1.AppendText(link.InnerText + " " + link.Url[0] + Environment.NewLine);
                    }
                    else
                    {
                        richTextBox1.AppendText(link.InnerText + Environment.NewLine);
                        richTextBox1.AppendText(link.Url.Select(l => "    " + l + Environment.NewLine).Aggregate((a, b) => a + b));
                    }
                }
                else
                {
                    if (link.Url.Count == 1)
                    {
                        richTextBox1.AppendText(string.Format("{1}{0}    Original: {2}{0}    Proposed: {3}{0}", Environment.NewLine, link.InnerText, link.OriginalUrl, link.Url[0]));
                    }
                    else
                    {
                        richTextBox1.AppendText(string.Format("{1}{0}    Original: {2}{0}    Proposed:{0}", Environment.NewLine, link.InnerText, link.OriginalUrl));
                        richTextBox1.AppendText(link.Url.Select(l => "    " + l + Environment.NewLine).Aggregate((a, b) => a + b));
                    }
                }
            }

            txtConsole.AppendText("Results for " + result.Title + System.Environment.NewLine + System.Environment.NewLine);

            txtConsole.AppendText("Links Analyzed: " + result.ParsedLinks.Count() + System.Environment.NewLine);
            txtConsole.AppendText("Valid JDownload Links found: " + result.JLinksCount + System.Environment.NewLine);
            txtConsole.AppendText("Total Links found: " + result.ParsedLinks.Select(l => l.Url.Count).Sum() + System.Environment.NewLine + System.Environment.NewLine);

            if (result.LinkDupes.Count() > 0)
            {
                txtConsole.AppendText(string.Format("Duplicate links ({0}) found at:{1}", result.LinkDupes.Count(), System.Environment.NewLine));
                foreach (string dupe in result.LinkDupes)
                {
                    txtConsole.AppendText("    " + dupe + System.Environment.NewLine);
                }
            }

            if (result.SourceDupes.Count() > 0)
            {
                txtConsole.AppendText(string.Format("Source numbers duplicated ({0}):{1}", result.SourceDupes.Count(), System.Environment.NewLine));
                foreach (int dupe in result.SourceDupes)
                {
                    txtConsole.AppendText(string.Format("    Source[{0}]{1}", dupe, System.Environment.NewLine));
                }
            }

            if (result.SourceMissing.Count() > 0)
            {
                txtConsole.AppendText(string.Format("The following source numbers ({0}) could not be found:{1}", result.SourceMissing.Count(), System.Environment.NewLine));
                foreach (int missing in result.SourceMissing)
                {
                    txtConsole.AppendText(string.Format("    Source[{0}]{1}", missing, System.Environment.NewLine));
                }
            }

            if (result.BrokenDeviantArtLinks.Count() > 0)
            {
                txtConsole.AppendText(string.Format("The following images ({0}) have broken DeviantArt links:{1}", result.BrokenDeviantArtLinks.Count(), System.Environment.NewLine));
                foreach (ParsedLink link in result.BrokenDeviantArtLinks)
                {
                    txtConsole.AppendText(string.Format("   Source[{0}]: {1}{2}", link.Source, link.Url[0], System.Environment.NewLine));
                }
            }

            if (result.AlternativeLinks.Count() > 0)
            {
                txtConsole.AppendText(string.Format("The following images ({0}) are not deviant art links and the image preview is being used:{1}", result.AlternativeLinks.Count(), System.Environment.NewLine));
                foreach (ParsedLink link in result.AlternativeLinks)
                {
                    txtConsole.AppendText(string.Format("   Source[{0}]: {1}", link.Source, link.Url.Select(l => l + Environment.NewLine).Aggregate((a, b) => a + b)));
                }
            }

            textBox2.Text = result.JLinks;

            txtConsole.AppendText(System.Environment.NewLine + "Thank you for using EQD DA Clipper!");
        }