Example #1
0
        public void SetUpCamera(Vector3d eye, Vector3d lookAt, Vector3d up)
        {
            Eye = eye;
            LookAt = lookAt;
            Up = up;

            ComputeUVW();
        }
Example #2
0
 public override RGBColor F(ShadeRec shadeRec, Vector3d wi, Vector3d wo)
 {
     RGBColor L = new RGBColor();
     double NdotWi = Vector3d.Dot(shadeRec.Normal, wi);
     Vector3d r = (-wi + (Vector3d)shadeRec.Normal * NdotWi * 2);
     double RdotWo = Vector3d.Dot(r, wo);
     if (RdotWo > 0)
     {
         L = CS*KS*Math.Pow(RdotWo, Exp);
     }
     return L;
 }
Example #3
0
        public ShadeRec(World world)
        {
            HasHitObject = false;
            Hitpoint = new Point3d();
            Normal = new Normal();
            LocalHitPoint = new Point3d();
            Ray=new Ray();
            Depth = 0;
            Direction = new Vector3d();
            T = 0;

            //Chapter 3 only
            Color = new RGBColor(0, 0, 0); //Black

            World = world;
        }
Example #4
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);
            }
        }
Example #5
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);
        }
Example #6
0
        public static void BuildSingleSphere(World world)
        {
            world.ViewPlane = new ViewPlane();
            world.ViewPlane.HRes = 200;
            world.ViewPlane.VRes = 200;
            world.ViewPlane.PixelSize = 1;
            world.ViewPlane.Gamma = 1;

            world.Camera=new PinholeCamera(50);
            var eye = new Vector3d(0, 0, 100);
            var lookAt = new Vector3d(0, 0, 0);
            world.Camera.SetUpCamera(eye, lookAt);
            //world.ViewPlane.SamplesCount = 64;
            world.ViewPlane.Sampler = new Hammersley(1, 25);
            world.BackgroundColor = new RGBColor(0, 0, 0);
            world.Tracer = new Normals(world);

            world.Sphere = new Sphere(new Point3d(0, 0, 0), 85);
            world.Sphere.Color = new RGBColor(1, 0, 0);
            world.AddObject(world.Sphere);
        }
Example #7
0
 public static double Dot(Vector3d v1, Vector3d v2)
 {
     return v1.X*v2.X + v1.Y*v2.Y + v1.Z*v2.Z;
 }
Example #8
0
 public static Vector3d Cross(Vector3d v1, Vector3d v2)
 {
     return new Vector3d(v1.Y*v2.Z - v1.Z*v2.Y,
                         v1.Z*v2.X - v1.X*v2.Z,
                         v1.X*v2.Y - v1.Y*v2.X);
 }
Example #9
0
 public virtual RGBColor SampleF(ShadeRec shadeRec, Vector3d wi, Vector3d wo)
 {
     return new RGBColor();
 }
Example #10
0
 public virtual RGBColor Rho(ShadeRec shadeRec,Vector3d wo)
 {
     return new RGBColor();
 }
Example #11
0
 public void SetUpCamera(Vector3d eye,Vector3d lookAt)
 {
     SetUpCamera(eye, lookAt, new Vector3d(0, 1, 0));
 }