예제 #1
0
        private void decomposeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Vertices verts = new Vertices();

            for (int i = 0; i < polygon.PolyChains.Count; ++i)
            {
                for (int x = 0; x < polygon.PolyChains[i].Connections.Count; ++x)
                {
                    var p = polygon.PolyChains[i].Vertices[polygon.PolyChains[i].Connections[x] - 1];
                    verts.Add(new Microsoft.Xna.Framework.Vector2(p.X, p.Y));
                }
            }

            sw.Reset();
            sw.Start();
            switch (listBox1.SelectedIndex)
            {
            case 0:
                {
                    _decomposedVerts = FarseerPhysics.Common.Decomposition.CDTDecomposer.ConvexPartition(verts);

                    FarseerPhysics.Common.Decomposition.Triangle[] triangles = new FarseerPhysics.Common.Decomposition.Triangle[_decomposedVerts.Count];

                    for (int x = 0; x < triangles.Length; ++x)
                        triangles[x] = new FarseerPhysics.Common.Decomposition.Triangle(_decomposedVerts[x][0].X, _decomposedVerts[x][0].Y, _decomposedVerts[x][1].X, _decomposedVerts[x][1].Y, _decomposedVerts[x][2].X, _decomposedVerts[x][2].Y);

                    _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.PolygonizeTriangles(triangles.ToList(), 100000, 0.001f);
                }
                break;
            case 1:
                {
                    _decomposedVerts = FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(verts);
                }
                break;
            case 2:
                {
                    _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.ConvexPartition(verts);
                }
                break;
            case 3:
                {
                    _decomposedVerts = FarseerPhysics.Common.Decomposition.FlipcodeDecomposer.ConvexPartition(verts);
                }
                break;
            case 4:
                {
                    _decomposedVerts = FarseerPhysics.Common.Decomposition.SeidelDecomposer.ConvexPartition(verts, 0.001f);

                    FarseerPhysics.Common.Decomposition.Triangle[] triangles = new FarseerPhysics.Common.Decomposition.Triangle[_decomposedVerts.Count];

                    for (int x = 0; x < triangles.Length; ++x)
                        triangles[x] = new FarseerPhysics.Common.Decomposition.Triangle(_decomposedVerts[x][0].X, _decomposedVerts[x][0].Y, _decomposedVerts[x][1].X, _decomposedVerts[x][1].Y, _decomposedVerts[x][2].X, _decomposedVerts[x][2].Y);

                    _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.PolygonizeTriangles(triangles.ToList(), 100000, 0.001f);
                }
                break;
            }
            sw.Stop();

            label3.Text = "Num Polygons: " + _decomposedVerts.Count.ToString();

            int count = 0;
            foreach (var x in _decomposedVerts)
                count += x.Count;

            label4.Text = "Total Vertices: "+count.ToString();
            label1.Text = "Time: " + sw.ElapsedMilliseconds.ToString() + "ms";

            pictureBox1.Invalidate();
        }
예제 #2
0
파일: Decomposer.cs 프로젝트: prepare/box2c
        private void decomposeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Vertices verts = new Vertices();

            for (int i = 0; i < polygon.PolyChains.Count; ++i)
            {
                for (int x = 0; x < polygon.PolyChains[i].Connections.Count; ++x)
                {
                    var p = polygon.PolyChains[i].Vertices[polygon.PolyChains[i].Connections[x] - 1];
                    verts.Add(new Microsoft.Xna.Framework.Vector2(p.X, p.Y));
                }
            }

            sw.Reset();
            sw.Start();
            switch (listBox1.SelectedIndex)
            {
            case 0:
            {
                _decomposedVerts = FarseerPhysics.Common.Decomposition.CDTDecomposer.ConvexPartition(verts);

                FarseerPhysics.Common.Decomposition.Triangle[] triangles = new FarseerPhysics.Common.Decomposition.Triangle[_decomposedVerts.Count];

                for (int x = 0; x < triangles.Length; ++x)
                {
                    triangles[x] = new FarseerPhysics.Common.Decomposition.Triangle(_decomposedVerts[x][0].X, _decomposedVerts[x][0].Y, _decomposedVerts[x][1].X, _decomposedVerts[x][1].Y, _decomposedVerts[x][2].X, _decomposedVerts[x][2].Y);
                }

                _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.PolygonizeTriangles(triangles.ToList(), 100000, 0.001f);
            }
            break;

            case 1:
            {
                _decomposedVerts = FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(verts);
            }
            break;

            case 2:
            {
                _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.ConvexPartition(verts);
            }
            break;

            case 3:
            {
                _decomposedVerts = FarseerPhysics.Common.Decomposition.FlipcodeDecomposer.ConvexPartition(verts);
            }
            break;

            case 4:
            {
                _decomposedVerts = FarseerPhysics.Common.Decomposition.SeidelDecomposer.ConvexPartition(verts, 0.001f);

                FarseerPhysics.Common.Decomposition.Triangle[] triangles = new FarseerPhysics.Common.Decomposition.Triangle[_decomposedVerts.Count];

                for (int x = 0; x < triangles.Length; ++x)
                {
                    triangles[x] = new FarseerPhysics.Common.Decomposition.Triangle(_decomposedVerts[x][0].X, _decomposedVerts[x][0].Y, _decomposedVerts[x][1].X, _decomposedVerts[x][1].Y, _decomposedVerts[x][2].X, _decomposedVerts[x][2].Y);
                }

                _decomposedVerts = FarseerPhysics.Common.Decomposition.EarclipDecomposer.PolygonizeTriangles(triangles.ToList(), 100000, 0.001f);
            }
            break;
            }
            sw.Stop();

            label3.Text = "Num Polygons: " + _decomposedVerts.Count.ToString();

            int count = 0;

            foreach (var x in _decomposedVerts)
            {
                count += x.Count;
            }

            label4.Text = "Total Vertices: " + count.ToString();
            label1.Text = "Time: " + sw.ElapsedMilliseconds.ToString() + "ms";

            pictureBox1.Invalidate();
        }