public void BuildKDTree()
        {
            var triangles = new List <Triangle>(Triangles);

            foreach (var t in triangles)
            {
                t.CalcCachedData();
            }
            KDTree             = new Common.KDTree <Triangle>();
            KDTree.Intersector = (object a, object b, out object i) =>
            {
                var bc = (Common.Bounding.Chain)a;
                return(Common.Intersection.Intersect((BoundingSphere)bc.Boundings[0], (Ray)b, out i) &&
                       Triangle.Intersect((Triangle)bc.Boundings[1], (Ray)b, out i));
            };
            KDTree.Translation = (object b) =>
            {
                var bc = (Common.Bounding.Chain)b;
                return(Triangle.Translation((Triangle)bc.Boundings[1]));
            };
            KDTree.InitFromList(triangles,
                                (t) => new Common.Bounding.Chain(t.BoundingSphere, t)
            {
                Shallow = true
            }
                                //(t) => t
                                );
        }
 static void TestRandom()
 {
     Random r = new Random();
     List<Vector3> points = new List<Vector3>();
     for(int i=0; i < 1000; i++)
         points.Add(new Vector3((float)((r.NextDouble()*2 - 1)*100),
             (float)((r.NextDouble()*2 - 1)*100),
             (float)((r.NextDouble()*2 - 1)*100)));
     Console.WriteLine("Building tree");
     Common.KDTree<Vector3> tree = new Common.KDTree<Vector3>(points, (p) => new BoundingSphere(p, 1));
 }
Exemple #3
0
        static void TestRandom()
        {
            Random         r      = new Random();
            List <Vector3> points = new List <Vector3>();

            for (int i = 0; i < 1000; i++)
            {
                points.Add(new Vector3((float)((r.NextDouble() * 2 - 1) * 100),
                                       (float)((r.NextDouble() * 2 - 1) * 100),
                                       (float)((r.NextDouble() * 2 - 1) * 100)));
            }
            Console.WriteLine("Building tree");
            Common.KDTree <Vector3> tree = new Common.KDTree <Vector3>(points, (p) => new BoundingSphere(p, 1));
        }