AddVertex() 개인적인 메소드

private AddVertex ( double x, double y, int data ) : bool
x double
y double
data int
리턴 bool
예제 #1
0
        public float[] TessPolygon(float[] vertex2dCoords, int[] contourEndPoints, out int areaCount)
        {
            vertexts.Clear();//reset
            //
            int ncoords = vertex2dCoords.Length / 2;

            if (ncoords == 0)
            {
                areaCount = 0; return(null);
            }

            int nn = 0;

            for (int i = 0; i < ncoords; ++i)
            {
                vertexts.Add(new Vertex(vertex2dCoords[nn++], vertex2dCoords[nn++]));
            }
            //-----------------------
            tessListener.Reset(vertexts);
            //-----------------------
            tess.BeginPolygon();

            int nContourCount = contourEndPoints.Length;
            int beginAt       = 0;

            for (int m = 0; m < nContourCount; ++m)
            {
                int thisContourEndAt = (contourEndPoints[m] + 1) / 2;
                tess.BeginContour();
                for (int i = beginAt; i < thisContourEndAt; ++i)
                {
                    Vertex v = vertexts[i];
                    tess.AddVertex(v.m_X, v.m_Y, 0, i);
                }
                beginAt = thisContourEndAt + 1;
                tess.EndContour();
            }


            tess.EndPolygon();
            //-----------------------
            List <Vertex> vertextList = tessListener.resultVertexList;
            //-----------------------------
            //switch how to fill polygon
            int j = vertextList.Count;

            float[] vtx = new float[j * 2];
            int     n   = 0;

            for (int p = 0; p < j; ++p)
            {
                var v = vertextList[p];
                vtx[n]     = (float)v.m_X;
                vtx[n + 1] = (float)v.m_Y;
                n         += 2;
            }
            //triangle list
            areaCount = j;
            return(vtx);
        }
예제 #2
0
        public void ParseStreamForTesselator(Tesselate.Tesselator tesselator, int instructionStreamIndex)
        {
            m_VertexList.Clear();
            m_CurrentOutput = 0;

            string[] instructionStream = m_InsructionStream[instructionStreamIndex];
            for (int curInstruction = 0; curInstruction < instructionStream.Length; curInstruction++)
            {
                switch (instructionStream[curInstruction])
                {
                case "BP":
                    tesselator.BeginPolygon();
                    break;

                case "BC":
                    tesselator.BeginContour();
                    break;

                case "V":
                    double x = Convert.ToDouble(instructionStream[curInstruction + 1]);
                    double y = Convert.ToDouble(instructionStream[curInstruction + 2]);
                    curInstruction += 2;
                    double[] coords = new double[3];
                    coords[0] = x;
                    coords[1] = y;
                    tesselator.AddVertex(coords, m_VertexList.Count);
                    m_VertexList.Add(new Vertex(x, y));
                    break;

                case "EC":
                    tesselator.EndContour();
                    break;

                case "EP":
                    tesselator.EndPolygon();
                    break;

                default:
                    throw new Exception();
                }
            }
        }
        /// <summary>
        /// Renders out the junction shape to the screen.
        /// </summary>
        private void CreateJunctionShape()
        {
            // Create the AGG tesselator and set it up
            Tesselator tess = new Tesselator();
            tess.callCombine += OnTesselatorCombine;
            tess.callVertex += OnVertex;
            tess.callMesh += OnMesh;
            tess.callBegin += OnTesselatorBegin;
            tess.callEnd += OnTesselatorEnd;

            // Go through the junction's internal shape
            IPoly poly = State.JunctionManager.Junction.Shape;

            renderPoints.Clear();
            tess.BeginPolygon();
            tess.BeginContour();

            for (int i = 0; i < poly.PointCount; i++)
            {
             				// Get the point
                PointF p = new PointF(
                    (float) poly.GetX(i), (float) poly.GetY(i));

                // Add the vertex with the index it will have when we
                // refer to it later.
                tess.AddVertex(
                    new double [] { p.X, p.Y, 0 },
                    renderPoints.Count);

                // Create the center
                renderPoints.Add(p);
            }

            // Finish up the polygon, which renders the rendering
            // commands
            //Log.Info("Tesselating {0} points", renderPoints.Count);
            tess.EndContour();
            tess.EndPolygon();
        }
예제 #4
0
        public void ParseStreamForTesselator(Tesselate.Tesselator tesselator, int instructionStreamIndex)
        {
            m_VertexList.Clear();
            m_CurrentOutput = 0;

            string[] instructionStream = m_InsructionStream[instructionStreamIndex];
            for (int curInstruction = 0; curInstruction < instructionStream.Length; curInstruction++)
            {
                switch (instructionStream[curInstruction])
                {
                case "BP":
                    tesselator.BeginPolygon();
                    break;

                case "BC":
                    tesselator.BeginContour();
                    break;

                case "V":
                    double x = Convert.ToDouble(instructionStream[curInstruction + 1]);
                    double y = Convert.ToDouble(instructionStream[curInstruction + 2]);
                    curInstruction += 2;

                    tesselator.AddVertex(x, y, 0, m_VertexList.Count);
                    m_VertexList.Add(new Vertex(x, y));
                    break;

                case "EC":
                    tesselator.EndContour();
                    break;

                case "EP":
                    tesselator.EndPolygon();
                    break;

                default:
                    throw new Exception();
                }
            }


            //---------------
            //test
            //------------------
            //int a = m_VertexList.Count;
            ////test draw
            //Bitmap bmp = new Bitmap(300, 300);
            //Graphics g = Graphics.FromImage(bmp);
            //g.Clear(Color.White);
            //int j = m_VertexList.Count;
            //int lim = j - 1;
            //for (int i = 0; i < lim; i++)
            //{
            //    var v1 = m_VertexList[i];
            //    var v2 = m_VertexList[i + 1];
            //    g.DrawLine(Pens.Black,
            //        new PointF((float)v1.m_X, (float)v1.m_Y),
            //        new PointF((float)v2.m_X, (float)v2.m_Y));

            //}
            //g.Dispose();
            //bmp.Save("tess" + (totalSampleCount++) + ".bmp");
        }