Esempio n. 1
0
 public Node(PartitionPlane P, Voxel V, Node L = null, Node R = null)
 {
     partition = P;
     bounds    = V;
     left      = L;
     right     = R;
 }
Esempio n. 2
0
        public Voxel[] Split(PartitionPlane P)
        {
            int cd = P.axis;

            float maxBound = max[cd];
            float minBound = min[cd];

            float c1d, c2d;

            c1d = P.center[cd] + ((maxBound - P.center[cd]) / 2);
            c2d = P.center[cd] + ((minBound - P.center[cd]) / 2);

            Vector c1 = Vector.Build.DenseOfVector(center);
            Vector c2 = Vector.Build.DenseOfVector(center);

            c1[cd] = c1d;
            c2[cd] = c2d;

            Vector s1 = Vector.Build.DenseOfVector(size);
            Vector s2 = Vector.Build.DenseOfVector(size);

            s1[cd] = Math.Abs(maxBound - P.center[cd]);
            s2[cd] = Math.Abs(minBound - P.center[cd]);

            Voxel v1 = new Voxel(c1, s1);
            Voxel v2 = new Voxel(c2, s2);

            return(new Voxel[] { v1, v2 });
        }
Esempio n. 3
0
        private static PartitionPlane ComputePartitionPlane(List <Shape3D> L, Voxel V, int splitAxis)
        {
            L.Sort((a, b) =>
            {
                return((int)(a.center[splitAxis] - b.center[splitAxis]));
            });
            int i_m   = (L.Count - 1) / 2;
            var split = new PartitionPlane(L[i_m].center, splitAxis);

            return(split);
        }
Esempio n. 4
0
        public static World GetVoxelTestWorld(int width, int height)
        {
            // World world = GetDefaultWorld(width, height);
            World world = new World(width, height);
            // initialize light source
            Vector      lightPos = Vector.Build.DenseOfArray(new float[] { -3.0f, -3.0f, -3.0f });
            LightSource l1       = new LightSource(lightPos, Rgba32.White, 95.5f);

            world.AddLightSource(l1);

            // initialize camera
            Vector cameraPos    = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, -3.0f });
            Vector cameraUp     = Vector.Build.DenseOfArray(new float[] { 0.0f, -1.0f, 0.0f });
            Vector cameraLookAt = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, 0.0f });

            world.cameras.Add(new Camera(cameraPos, cameraLookAt, cameraUp, world));

            PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world);

            var c = Vector.Build.Dense(3);

            c[0] = 0.0f;
            c[1] = 0.0f;
            c[2] = 0.0f;
            var s    = Vector.Build.DenseOfArray(new float[] { 1.0f, 1.0f, 1.0f });
            var rmat = PhongMaterial.Red(illuminationModel);
            var bmat = PhongMaterial.Blue(illuminationModel);
            var gmat = PhongMaterial.Green(illuminationModel);

            var p = new PartitionPlane(c, 1);

            Voxel main = new Voxel(c, s);

            Voxel[] split = main.Split(p);
            Voxel   left  = new Voxel(split[0].center, split[0].size, rmat);
            Voxel   right = new Voxel(split[1].center, split[1].size, bmat);

            for (int i = 0; i < 6; i++)
            {
                world.AddObject(left.planes[i]);
                world.AddObject(right.planes[i]);
            }

            var smax = new Sphere(main.max, 0.05f, gmat);
            var smin = new Sphere(main.min, 0.05f, gmat);

            world.AddObject(smax);
            world.AddObject(smin);
            return(world);
        }