Exemplo n.º 1
0
        private static void PrintTriangles(List <Vector3m> points)
        {
            var map = new Dictionary <Vector3m, int>();
            int mapValue;

            Console.WriteLine("Polygon:");
            for (int i = 0; i < points.Count; i += 3)
            {
                if (map.TryGetValue(points[i], out mapValue))
                {
                    //map[points[0]]
                    //Console.WriteLine(mapValue);
                }
                else
                {
                    map.Add(points[i], 1);
                }
                Console.WriteLine("Face{0}: {1} {2} {3}", i / 3, points[i], points[i + 1], points[i + 2]);
            }
            Console.WriteLine();
            foreach (var pair in map)
            {
                Vector3m key = pair.Key;
                //string value = pair.Value;
                Console.WriteLine("{0}", key);
            }
            Console.WriteLine();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Helper TheHelper = new Helper();

            TheHelper.AddVertex(-1.282, 15.245, -0.080);
            TheHelper.AddVertex(-8.292, 15.245, 5.406);
            TheHelper.AddVertex(-8.292, 15.346, 5.406);
            TheHelper.AddVertex(-1.282, 15.346, -0.080);

            TheHelper.SetNormal(-0.788, 0.000, 0.616);

            List <short> Indices = TheHelper.TriangulateAndReturnIndices();

            // specify polygon points in CCW order
            List <Vector3m> Points = new List <Vector3m>()
            {
                new Vector3m(-1.282, 15.245, -0.080),
                new Vector3m(-8.292, 15.245, 5.406),
                new Vector3m(-8.292, 15.346, 5.406),
                new Vector3m(-1.282, 15.346, -0.080)
            };

            EarClipping earClipping = new EarClipping();

            earClipping.SetPoints(Points, null, new Vector3m(-0.788, 0.000, 0.616));
            earClipping.Triangulate();
            var Result = earClipping.Result;

            Indices = new List <int>();
            for (int Index = 0; Index < Result.Count; Index++)
            {
                Vector3m Vertex = Result[Index];
                for (int IndexPoint = 0; IndexPoint < Points.Count; IndexPoint++)
                {
                    if (Vertex.Equals(Points[IndexPoint]))
                    {
                        Indices.Add(IndexPoint);
                    }
                }
            }
        }