Example #1
0
        public void InitializeWorld2()
        {
            // カメラ
            var from = new Vector3(0, -1.5f, 15);
            var dir = new Vector3(0, 0, -1);
            cam = new Camera(new Ray(from, dir));

            var offset = -3;
            var z0 = -2;
            // シェーディング
            shader = new Shader(new Vector3(0, -1, 0), new Vector3(10, 10, 10));

            // 床
            actors.Add(
                new CheckerPlain(
                    new Vector3(0, 1, 0),
                    new Vector3(0, -1, 0),
                    material2,
                    material3
                )
            );

            // 左側の鏡
            var angle = MathHelper.ToRadians(45.0f);
            var dx = -0.5f * (float)Math.Cos(angle);
            var vertice = new[] {
                new Vector3(-0.5f, 0, 0),
                new Vector3(-0.5f, 1, 0),
                new Vector3(0.5f, 1, 0),
                new Vector3(0.5f, 0, 0)
            };
            var m = Matrix.CreateRotationY(angle);
            Vector3.Transform(vertice, ref m, vertice);
            m = Matrix.CreateTranslation(new Vector3(dx, 0, offset + z0));
            Vector3.Transform(vertice, ref m, vertice);

            actors.Add(
                new QuadMesh(
                    vertice[0],
                    vertice[1],
                    vertice[2],
                    vertice[3],
                    material7
                )
            );

            // 右側の鏡
            vertice = new[] {
                new Vector3(-0.5f, 0, 0),
                new Vector3(-0.5f, 1, 0),
                new Vector3(0.5f, 1, 0),
                new Vector3(0.5f, 0, 0)
            };
            m = Matrix.CreateRotationY(-angle);
            Vector3.Transform(vertice, ref m, vertice);
            m = Matrix.CreateTranslation(new Vector3(-dx, 0, offset + z0));
            Vector3.Transform(vertice, ref m, vertice);

            actors.Add(
                new QuadMesh(
                    vertice[0],
                    vertice[1],
                    vertice[2],
                    vertice[3],
                    material7
                )
            );

            // 球
            actors.Add(
                new Sphere(
                    0.3f,
                    new Vector3(0, 0.6f, offset),
                    material3
                )
            );
        }
Example #2
0
        public void InitializeWorld1()
        {
            var offset = -3;
            var z0 = -5;

            // カメラ
            var from = new Vector3(0, -0.5f, 15);
            var dir = new Vector3(0, 0, -1);
            cam = new Camera(new Ray(from, dir));

            // シェーディング
            shader = new Shader(new Vector3(0, -1, offset + 0.5f * z0), new Vector3(10, 10, 10));

            // 左壁
            actors.Add(
                new QuadMesh(
                    new Vector3(-1, 1, offset),
                    new Vector3(-1, 1, offset + z0),
                    new Vector3(-1, -1, offset + z0),
                    new Vector3(-1, -1, offset),
                    material1
                )
            );

            // 右壁
            actors.Add(
                new QuadMesh(
                    new Vector3(1, 1, offset),
                    new Vector3(1, -1, offset),
                    new Vector3(1, -1, offset + z0),
                    new Vector3(1, 1, offset + z0),
                    material2
                )
            );

            // 奥壁
            actors.Add(
                new QuadMesh(
                    new Vector3(-1, -1, offset + z0),
                    new Vector3(-1, 1, offset + z0),
                    new Vector3(1, 1, offset + z0),
                    new Vector3(1, -1, offset + z0),
                    material5
                )
            );

            // 床
            actors.Add(
                new QuadMesh(
                    new Vector3(-1, 1, offset),
                    new Vector3(1, 1, offset),
                    new Vector3(1, 1, offset + z0),
                    new Vector3(-1, 1, offset + z0),
                    material3
                )
            );

            // 玉1
            actors.Add(
                new Sphere(
                    0.2f,
                    new Vector3(-0.3f, 0.2f, offset + 0.5f * z0),
                    material5
                )
            );

            // 玉2
            actors.Add(
                new Sphere(
                    0.2f,
                    new Vector3(0.5f, 0.8f, offset + 0.2f * z0),
                    material6
                )
            );

            // 玉3
            actors.Add(
                new Sphere(
                    0.3f,
                    new Vector3(0, 0.7f, offset + 0.5f * z0),
                    material4
                )
            );
        }