Example #1
0
        public static World GetComplexWorld(int width, int height)
        {
            // World world = GetDefaultWorld(width, height);
            World       world     = new World(width, height);
            Vector      lightPos2 = Vector.Build.DenseOfArray(new float[] { 1.0f, -3.0f, -3.0f });
            LightSource l2        = new LightSource(lightPos2, Rgba32.White, 95.5f);

            world.AddLightSource(l2);

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

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

            PhongIlluminationModel illuminationModel = new PhongIlluminationModel(world);

            var complex = OBJParser.LoadObjFile("./data/gourd.obj");

            // complex.Translate(0.0f, -0.5f, 0.0f);
            System.Console.WriteLine(complex.shapes.Count);
            // complex.RotateZ((float)Math.PI);
            // complex.Translate(0.0f, 0.2f, -2.0f);
            // complex.Scale(1.2f, 1.2f, 1.2f);
            var mat = PhongMaterial.Red(illuminationModel);

            mat.kSpecular = 0.01f;
            complex.SetMaterial(mat);
            world.AddObject(complex);
            return(world);
        }
Example #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);
        }
Example #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);
        }