コード例 #1
0
ファイル: Program.cs プロジェクト: kemptm/RayTracer
        static void Main(string[] args)
        {
            {
                Sphere s = new Sphere();
                RayTracerLib.Vector n = s.NormalAt(new Point(1, 0, 0));
                bool foo = n.Equals(new RayTracerLib.Vector(1, 0, 0));

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            {
                Sphere   s   = new Sphere();
                Material m   = s.Material;
                bool     foo = m.Equals(new Material());

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            {
                Material m        = new Material();
                Point    position = new Point();

                RayTracerLib.Vector eyev    = new RayTracerLib.Vector(0, 0, -1);
                RayTracerLib.Vector normalv = new RayTracerLib.Vector(0, 0, -1);
                Sphere s = new Sphere();

                LightPoint light  = new LightPoint(new Point(0, 0, -10), new Color(1, 1, 1));
                Color      result = Ops.Lighting(m, s, light, position, eyev, normalv);

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            {
                Material m        = new Material();
                Point    position = new Point();

                RayTracerLib.Vector eyev    = new RayTracerLib.Vector(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
                RayTracerLib.Vector normalv = new RayTracerLib.Vector(0, 0, -1);
                Sphere     s      = new Sphere();
                LightPoint light  = new LightPoint(new Point(0, 0, -10), new Color(1, 1, 1));
                Color      result = Ops.Lighting(m, s, light, position, eyev, normalv);

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }
            {
                //SphereNormalScaled() {
                Sphere s = new Sphere();
                s.Transform = MatrixOps.CreateScalingTransform(1, 1, 1);
                Point p = new Point(0, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
                RayTracerLib.Vector n = s.NormalAt(p);
                bool foo = (n.Equals(new RayTracerLib.Vector(0, 0.97014, -0.24254)));


                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }

            Console.Write("Press Enter to finish ... ");
            Console.Read();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: kemptm/RayTracer
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Main entry-point for this application. </summary>
        ///
        /// <remarks>   Kemp, 1/18/2019. </remarks>
        ///
        /// <param name="args"> An array of command-line argument strings. </param>
        ///-------------------------------------------------------------------------------------------------

        static void Main(string[] args)
        {
            World defaultWorld = new World();

            defaultWorld.AddLight(new LightPoint(new Point(-10, 10, -10), new Color(1, 1, 1)));

            Sphere s1 = new Sphere();

            s1.Material          = new Material();
            s1.Material.Color    = new Color(0.8, 1.0, 0.6);
            s1.Material.Diffuse  = new Color(0.7, 0.7, 0.7);
            s1.Material.Specular = new Color(0.2, 0.2, 0.2);

            Sphere s2 = new Sphere();

            s2.Transform = MatrixOps.CreateScalingTransform(0.5, 0.5, 0.5);
            defaultWorld.AddObject(s1);
            defaultWorld.AddObject(s2);

            {
                //ComputingNormalOnTranslatedShape
                TestShape s = new TestShape();
                s.Transform = MatrixOps.CreateTranslationTransform(0, 1, 0);
                RayTracerLib.Vector n = s.NormalAt(new Point(0, 1.70711, -0.70711));
                bool foo = (n.Equals(new RayTracerLib.Vector(0, 0.70711, -0.70711)));

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }

            {
                World w = new World();
                w.AddLight(new LightPoint(new Point(-10, 10, -10), new Color(1, 1, 1)));

                Sphere s3 = new Sphere();
                s3.Material          = new Material();
                s3.Material.Color    = new Color(0.8, 1.0, 0.6);
                s3.Material.Diffuse  = new Color(0.7, 0.7, 0.7);
                s3.Material.Specular = new Color(0.2, 0.2, 0.2);
                w.AddObject(s3);

                Plane p = new Plane();
                p.Transform        = (Matrix)(MatrixOps.CreateTranslationTransform(0, 0, 2) * MatrixOps.CreateRotationXTransform(Math.PI / 2));
                p.Material.Pattern = new CheckedPattern(new Color(0, 0, 1), new Color(1, 0.9, 0.9));
                w.AddObject(p);

                Plane p1 = new Plane();
                p1.Transform        = MatrixOps.CreateTranslationTransform(1, 0, 0);
                p1.Material.Pattern = new GradientPattern(new Color(1, 0, 0), new Color(1, 0.9, 0.9));
                w.AddObject(p1);


                Ray r = new Ray(new Point(1, 1, -5), new RayTracerLib.Vector(0, -0.5, 0));
                List <Intersection> xs = p.Intersect(r);
                bool foo1, foo2, foo3;
                if (xs.Count > 0)
                {
                    foo1 = (xs.Count == 1);
                    foo2 = (xs[0].T >= 1);
                    foo3 = (xs[0].Obj.Equals(p));
                }

                Camera camera = new Camera(400, 200, Math.PI / 2);
                camera.Transform = MatrixOps.CreateViewTransform(new Point(3, 3, -5), new Point(0, 0, 0), new RayTracerLib.Vector(0, 1, 0));

                Canvas image = w.Render(camera);

                String ppm = image.ToPPM();

                System.IO.File.WriteAllText(@"ToPPM.ppm", ppm);

                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~");
            }

            Console.Write("Press Enter to finish ... ");
            Console.Read();
        }