/// <summary> /// Clone all the time-dependent components, share the others. /// </summary> /// <returns></returns> public virtual object Clone() { AnimatedRayScene sc = new AnimatedRayScene(); ITimeDependent intersectable = Intersectable as ITimeDependent; sc.Intersectable = (intersectable == null) ? Intersectable : (IIntersectable)intersectable.Clone(); sc.BackgroundColor = (double[])BackgroundColor.Clone(); ITimeDependent camera = Camera as ITimeDependent; sc.Camera = (camera == null) ? Camera : (ICamera)camera.Clone(); ILightSource[] tmp = new ILightSource[Sources.Count]; Sources.CopyTo(tmp, 0); for (int i = 0; i < tmp.Length; i++) { ITimeDependent source = tmp[i] as ITimeDependent; if (source != null) { tmp[i] = (ILightSource)source.Clone(); } } sc.Sources = new LinkedList <ILightSource>(tmp); sc.Start = Start; sc.End = End; sc.setTime(Time); // propagates the current time to all time-dependent components.. return(sc); }
/// <summary> /// Clone all the time-dependent components, share the others. /// </summary> /// <returns></returns> public virtual object Clone() { AnimatedRayScene sc = new AnimatedRayScene(); ITimeDependent intersectable = Intersectable as ITimeDependent; sc.Intersectable = (intersectable == null) ? Intersectable : (IIntersectable)intersectable.Clone(); sc.BackgroundColor = (double[])BackgroundColor.Clone(); ITimeDependent camera = Camera as ITimeDependent; sc.Camera = (camera == null) ? Camera : (ICamera)camera.Clone(); ILightSource[] tmp = new ILightSource[ Sources.Count ]; Sources.CopyTo( tmp, 0 ); for ( int i = 0; i < tmp.Length; i++ ) { ITimeDependent source = tmp[ i ] as ITimeDependent; if ( source != null ) tmp[ i ] = (ILightSource)source.Clone(); } sc.Sources = new LinkedList<ILightSource>( tmp ); sc.Start = Start; sc.End = End; sc.setTime( Time ); // propagates the current time to all time-dependent components.. return sc; }
/// <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); }