示例#1
0
        public void ComputeUVW()
        {
            w = Eye - LookAt;
            w.Normalize();
            u = Vector3d.Cross(Up, w);
            v = Vector3d.Cross(w, u);

            if (Eye.X == LookAt.X && Eye.Z == LookAt.Z && Eye.Y > LookAt.Y)
            { // camera looking vertically down
                u = new Vector3d(0, 0, 1);
                v = new Vector3d(1, 0, 0);
                w = new Vector3d(0, 1, 0);
            }

            if (Eye.X == LookAt.X && Eye.Z == LookAt.Z && Eye.Y < LookAt.Y)
            { // camera looking vertically up
                u = new Vector3d(1, 0, 0);
                v = new Vector3d(0, 0, 1);
                w = new Vector3d(0, -1, 0);
            }
        }
示例#2
0
        public static void Build14_21(World world)
        {
            world.ViewPlane = new ViewPlane();
            world.ViewPlane.HRes = 400;
            world.ViewPlane.VRes = 400;
            world.ViewPlane.PixelSize = 1;
            world.ViewPlane.Gamma = 1;
            //world.ViewPlane.SamplesCount = 25;
            world.ViewPlane.Sampler = new Hammersley(1, 16);
            world.BackgroundColor = new RGBColor(0, 0, 0);
            world.Tracer = new RayCast(world);
            world.AmbientLight=new Ambient();

            PinholeCamera pinholeCamera = new PinholeCamera(850);

            pinholeCamera.SetUpCamera(
                new Vector3d(0, 0, 500),
                new Vector3d(5, 0, 0));
            world.Camera = pinholeCamera;

            Point pointLight = new Point();
            pointLight.Location = new Vector3d(100, 50, 150);
            pointLight.LightScale = 3;
            world.AddLight(pointLight);

            //Sphere 1
            Matte matte1 = new Matte();
            matte1.KA = 0.25;
            matte1.KD = 0.65;
            matte1.Color = new RGBColor(1, 1, 0);

            Sphere sphere1 = new Sphere(new Point3d(10,5,0), 27);
            sphere1.Material = matte1;
            world.AddObject(sphere1);

            //Sphere 2
            Matte matte2 = new Matte();
            matte2.KA = 0.15;
            matte2.KD = 0.85;
            matte2.Color = new RGBColor(0.71, 0.40, 0.16);

            Sphere sphere2 = new Sphere(new Point3d(-25, 10, -35), 27);
            sphere2.Material = matte2;
            world.AddObject(sphere2);

            //Plane
            Matte matte3 = new Matte();
            matte3.KA = 0.15;
            matte3.KD = 0.5;
            matte3.Color = new RGBColor(0, 0.4, 0.2);

            Phong phong = new Phong();
            phong.KA = 0;
            phong.KD = 0;
            phong.KS = 1;
            phong.Color = new RGBColor(0, 0.4, 0.2);

            Vector3d normal = new Vector3d(0, 1, 0);
            normal.Normalize();

            Plane plane = new Plane(new Point3d(0, -10, 0),
                                    normal);
            plane.Material = phong;
            world.AddObject(plane);
        }