예제 #1
0
        public static World GetManyBallWorld(int width, int height)
        {
            var world = GetDefaultWorld(width, height);
            // world.objects = new List<Shape3D>();
            PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world);
            var r      = new Random();
            var center = Vector.Build.DenseOfArray(new float[] { 0.0f, -0.3f, 3.5f });
            var radius = 0.3f;
            var mir    = Mirror.GetMirror(illuminationModel);
            var glass  = TransmissiveMaterial.GetTransmissiveMaterial(illuminationModel);
            var blue   = PhongMaterial.Blue(illuminationModel);

            for (int i = 0; i < 100; i++)
            {
                var rVec = Vector.Build.DenseOfArray(new float[] {
                    (float)(r.NextDouble() * 2) - 1,
                    (float)(r.NextDouble() * 2) - 1,
                    (float)(r.NextDouble() * 2) - 1
                });
                rVec = rVec.Normalize();
                var rC = center + (rVec * radius);
                // PhongMaterial mat = mir;
                PhongMaterial mat  = (i % 2 == 0) ? mir : blue;//(PhongMaterial)glass;
                Sphere        ball = new Sphere(rC, (float)(r.NextDouble() * 0.01f), mat);
                world.AddObject(ball);
            }
            return(world);
        }
예제 #2
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);
        }
예제 #3
0
        public static World GetBlackHoleWorld(int width, int height)
        {
            World world = new World(width, height, Rgba32.Black);
            // initialize light source
            Vector      lightPos = Vector.Build.DenseOfArray(new float[] { -15.0f, 0f, 130.0f });
            LightSource l1       = new LightSource(lightPos, Rgba32.White, 150.0f);

            world.AddLightSource(l1);

            Vector      lightPos2 = Vector.Build.DenseOfArray(new float[] { 15.0f, 0f, 130.0f });
            LightSource l2        = new LightSource(lightPos2, Rgba32.White, 150.0f);

            world.AddLightSource(l2);

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

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

            PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world);

            var   max_z1_c = Vector.Build.DenseOfArray(new float[] { -50.0f, 0.0f, 150.0f });
            var   max_z1_n = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, -1.0f });
            var   mat1     = PhongMaterial.Red(illuminationModel);
            Plane max_z1   = new Plane(max_z1_c, max_z1_n, 100.0f, 100.0f, mat1);

            var   max_z2_c = Vector.Build.DenseOfArray(new float[] { 50.0f, 0.0f, 150.0f });
            var   max_z2_n = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, -1.0f });
            var   mat2     = PhongMaterial.Blue(illuminationModel);
            Plane max_z2   = new Plane(max_z2_c, max_z2_n, 100.0f, 100.0f, mat2);

            var       bh_c  = Vector.Build.DenseOfArray(new float[] { 0.0f, 0.0f, 50.0f });
            var       bh_sr = 1.5f;
            BlackHole bh    = new BlackHole(bh_c, 3.0f, bh_sr);

            bh.material = new LenseMaterial(illuminationModel);
            world.AddObject(bh);
            world.AddObject(max_z1);
            world.AddObject(max_z2);
            return(world);
        }