Пример #1
0
        public static void TestScene(IRayScene sc, string param)
        {
            Debug.Assert(sc != null);

            // CSG scene:
            CSGInnerNode root = new CSGInnerNode(SetOperation.Union);

            root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel());
            root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 1.0, 0.8, 0.1 }, 0.1, 0.7, 0.2, 128));
            sc.Intersectable = root;

            // Background color:
            sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 };

            // Camera:
            sc.Camera = new StaticCamera(new Vector3d(0.7, 0.5, -5.0),
                                         new Vector3d(0.0, -0.28, 1.0),
                                         50.0);

            // Light sources:
            sc.Sources = new LinkedList <ILightSource>();
            sc.Sources.Add(new AmbientLightSource(0.8));
            //sc.Sources.Add( new PointLightSource( new Vector3d( -5.0, 4.0, -3.0 ), 1.2 ) );

            /* */
            // horizontal stick source:
            //RectangleLightSource rls = new RectangleLightSource( new Vector3d( -5.0, 4.0, -6.0 ),
            //                                                     new Vector3d( 0.0, 0.0, 6.0 ),
            //                                                     new Vector3d( 0.0, 0.1, 0.0 ), 1.8 );
            // vertical stick source:
            RectangleLightSource rls = new RectangleLightSource(new Vector3d(-5.0, 1.0, -3.0),
                                                                new Vector3d(0.0, 0.0, 0.1),
                                                                new Vector3d(0.0, 6.0, 0.0), 1.8);

            // rectangle source:
            //RectangleLightSource rls = new RectangleLightSource( new Vector3d( -5.0, 1.0, -6.0 ),
            //                                                     new Vector3d( 0.0, 0.0, 6.0 ),
            //                                                     new Vector3d( 0.0, 6.0, 0.0 ), 1.8 );
            rls.Dim = new double[] { 1.0, 0.05, 0.0 };
            sc.Sources.Add(rls);
            /* */

            // --- NODE DEFINITIONS ----------------------------------------------------

            // Sphere:
            Sphere s = new Sphere();

            root.InsertChild(s, Matrix4d.Identity);

            // Infinite plane with checker:
            Plane pl = new Plane();

            pl.SetAttribute(PropertyName.COLOR, new double[] { 0.3, 0.0, 0.0 });
            pl.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(0.6, 0.6, new double[] { 1.0, 1.0, 1.0 }));
            root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 1.0, 0.8, 0.1 }, 0.1, 0.3, 0.7, 16));
            root.InsertChild(pl, Matrix4d.RotateX(-MathHelper.PiOver2) * Matrix4d.CreateTranslation(0.0, -1.0, 0.0));
        }
Пример #2
0
        public static void TestScene(IRayScene sc, string param)
        {
            Debug.Assert(sc != null);

            // CSG scene:
            CSGInnerNode root = new CSGInnerNode(SetOperation.Union);

            root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel());
            root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 0.6, 0.0, 0.0 }, 0.15, 0.8, 0.15, 16));
            sc.Intersectable = root;

            // Background color:
            sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 };

            // Camera:
            sc.Camera = new StaticCamera(new Vector3d(0.7, 3.0, -10.0),
                                         new Vector3d(0.0, -0.2, 1.0),
                                         50.0);

            // Light sources:
            sc.Sources = new LinkedList <ILightSource>();
            sc.Sources.Add(new AmbientLightSource(0.8));
            sc.Sources.Add(new PointLightSource(new Vector3d(-5.0, 3.0, -3.0), 1.0));

            // --- NODE DEFINITIONS ----------------------------------------------------

            // Base plane
            Plane pl = new Plane();

            pl.SetAttribute(PropertyName.COLOR, new double[] { 0.0, 0.2, 0.0 });
            pl.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(0.5, 0.5, new double[] { 1.0, 1.0, 1.0 }));
            root.InsertChild(pl, Matrix4d.RotateX(-MathHelper.PiOver2) * Matrix4d.CreateTranslation(0.0, -1.0, 0.0));

            // Cylinders
            Cylinder c = new Cylinder();

            root.InsertChild(c, Matrix4d.RotateX(MathHelper.PiOver2) * Matrix4d.CreateTranslation(-2.1, 0.0, 1.0));
            c = new Cylinder();
            c.SetAttribute(PropertyName.COLOR, new double[] { 0.2, 0.0, 0.7 });
            c.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(12.0, 1.0, new double[] { 0.0, 0.0, 0.3 }));
            root.InsertChild(c, Matrix4d.RotateY(-0.4) * Matrix4d.CreateTranslation(1.0, 0.0, 1.0));
            c = new Cylinder(0.0, 100.0);
            c.SetAttribute(PropertyName.COLOR, new double[] { 0.1, 0.7, 0.0 });
            root.InsertChild(c, Matrix4d.RotateY(0.2) * Matrix4d.CreateTranslation(5.0, 0.3, 4.0));
            c = new Cylinder(-0.5, 0.5);
            c.SetAttribute(PropertyName.COLOR, new double[] { 0.8, 0.6, 0.0 });
            root.InsertChild(c, Matrix4d.Scale(2.0) * Matrix4d.RotateX(1.2) * Matrix4d.CreateTranslation(2.0, 1.8, 16.0));
        }
Пример #3
0
        /// <summary>
        /// Creates default ray-rendering scene.
        /// </summary>
        public static IRayScene Init(IRayScene sc, string param)
        {
            // !!!{{ TODO: .. and use your time-dependent objects to construct the scene

            // This code is based on Scenes.TwoSpheres():

            // CSG scene:
            CSGInnerNode root = new CSGInnerNode(SetOperation.Union);

            root.SetAttribute(PropertyName.REFLECTANCE_MODEL, new PhongModel());
            root.SetAttribute(PropertyName.MATERIAL, new PhongMaterial(new double[] { 1.0, 0.8, 0.1 }, 0.1, 0.6, 0.4, 128));
            sc.Intersectable = root;

            // Background color:
            sc.BackgroundColor = new double[] { 0.0, 0.05, 0.07 };

            // Camera:
            AnimatedCamera cam = new AnimatedCamera(new Vector3d(0.7, -0.4, 0.0),
                                                    new Vector3d(0.7, 0.8, -6.0),
                                                    50.0);

            cam.End = 20.0;      // one complete turn takes 20.0 seconds
            AnimatedRayScene asc = sc as AnimatedRayScene;

            if (asc != null)
            {
                asc.End = 20.0;
            }
            sc.Camera = cam;

            //sc.Camera = new StaticCamera( new Vector3d( 0.7,  0.5, -5.0 ),
            //                              new Vector3d( 0.0, -0.18, 1.0 ),
            //                              50.0 );

            // Light sources:
            sc.Sources = new LinkedList <ILightSource>();
            sc.Sources.Add(new AmbientLightSource(0.8));
            sc.Sources.Add(new PointLightSource(new Vector3d(-5.0, 4.0, -3.0), 1.2));

            // --- NODE DEFINITIONS ----------------------------------------------------

            // Params dictionary:
            Dictionary <string, string> p = Util.ParseKeyValueList(param);

            // n = <index-of-refraction>
            double n = 1.6;

            Util.TryParse(p, "n", ref n);

            // Transparent sphere:
            Sphere s;

            s = new Sphere();
            PhongMaterial pm = new PhongMaterial(new double[] { 0.0, 0.2, 0.1 }, 0.03, 0.03, 0.08, 128);

            pm.n  = n;
            pm.Kt = 0.9;
            s.SetAttribute(PropertyName.MATERIAL, pm);
            root.InsertChild(s, Matrix4d.Identity);

            // Opaque sphere:
            s = new Sphere();
            root.InsertChild(s, Matrix4d.Scale(1.2) * Matrix4d.CreateTranslation(1.5, 0.2, 2.4));

            // Infinite plane with checker:
            Plane pl = new Plane();

            pl.SetAttribute(PropertyName.COLOR, new double[] { 0.3, 0.0, 0.0 });
            pl.SetAttribute(PropertyName.TEXTURE, new CheckerTexture(0.6, 0.6, new double[] { 1.0, 1.0, 1.0 }));
            root.InsertChild(pl, Matrix4d.RotateX(-MathHelper.PiOver2) * Matrix4d.CreateTranslation(0.0, -1.0, 0.0));

            // !!!}}

            return(sc);
        }