Exemple #1
0
        public void CreateFromTriangleList(List<Triangle> triangles)
        {
            TrianglesIds = new Dictionary<Triangle, int>();
            int i = 0;
            foreach(var t in triangles)
                TrianglesIds.Add(t, i++);

            Vector3 max = new Vector3(0), min = new Vector3(float.PositiveInfinity);
            foreach(var t in triangles)
            {
                foreach(var v in t.Vertices)
                {
                    max.X = Max(max.X, v.Position.X);
                    max.Y = Max(max.Y, v.Position.Y);
                    max.Z = Max(max.Z, v.Position.Z);

                    min.X = Min(min.X, v.Position.X);
                    min.Y = Min(min.Y, v.Position.Y);
                    min.Z = Min(min.Z, v.Position.Z);
                }
            }
            Vector3 center = (max + min) / 2;
            float radius =
                Max(
                    Max(max.X - min.X, max.Y - min.Y)
                    , max.Z - min.Z) / 2;
            BoxTree = new Box(center, radius);
            BoxTree.Triangles = triangles;
            BoxTree.RecursiveDivide();

            Console.WriteLine(TotalNodes);
            Console.WriteLine(TotalLeaves);
        }