示例#1
0
        public override void UpdateObjects(List <I3DObject> objects)
        {
            // finding actual bounds for the Octree...

            var spheres = objects.Select(x => x.GetBoundingSphere()).ToArray();

            var min = new Vect3
            {
                X = spheres.Min(x => x.Position.X - x.Radius),
                Y = spheres.Min(x => x.Position.Y - x.Radius),
                Z = spheres.Min(x => x.Position.Z - x.Radius)
            };

            var max = new Vect3
            {
                X = spheres.Max(x => x.Position.X + x.Radius),
                Y = spheres.Max(x => x.Position.Y + x.Radius),
                Z = spheres.Max(x => x.Position.Z + x.Radius)
            };

            var center   = (min + max) / 2;
            var tmp      = max - center;
            var halfSize = System.Math.Max(tmp.X, System.Math.Max(tmp.Y, tmp.Z));

            Tree = new Octree2(center, halfSize);
            Tree.Insert(objects);
        }
示例#2
0
        public void OctreeFromInside()
        {
            var ray = new Ray
            {
                Origin = new Vect3 {
                    X = -5
                },
                Direction = new Vect3 {
                    X = 1
                }
            };

            var octree = new Octree2(new Vect3(), 10);
            var sphere = new Sphere(new Vect3(), 2, Color.Red);

            octree.Insert(sphere);

            var collisionDetails = octree.GetFirstCollision(ray);

            Assert.That(!double.IsInfinity(collisionDetails.Distance));
            Assert.That(collisionDetails.Obj, Is.EqualTo(sphere));
        }