예제 #1
0
        /// <summary>
        /// Camera Setup
        /// </summary>
        /// <param name="image">Bitmap</param>
        /// <param name="sfera">Primitives List</param>

        public override void RenderTo(ref Bitmap image)
        {
            int imageWidth  = image.Width;
            int imageHeight = image.Height;

            double aspectRatio = imageWidth / (double)imageHeight;
            double tang        = Math.Tan(fov * 0.5 * 3.141f / 180.0);
            double height      = 2 * nearPlane * tang;
            double width       = height * aspectRatio;

            double widthPixel  = width / imageWidth;
            double heightPixel = height / imageHeight;

            minimumPixelSizeForAdaptive = heightPixel / (double)Math.Pow(2.0, adaptiveDepth);

            Vector3 w = -direction.GetNormalized();

            u = -(up.cross(w).GetNormalized());
            v = w.cross(u);
            Vector3 c = Position - u * (float)(width * 0.5) - v * (float)(height * 0.5) + direction * nearPlane;

            //Console.WriteLine(heightPixel);
            //base.RenderInternal(ref image, c, (float)widthPixel, (float)heightPixel,sfera);
            base.RenderInternal(ref image, ref c, (float)widthPixel, (float)heightPixel);
        }
예제 #2
0
        public Camera(Vector3 lookfrom, Vector3 lookat, Vector3 vup,
                      float vfov, float aspect, float apeture, float focus_dist,
                      float t0, float t1)
        {
            time0 = t0;
            time1 = t1;

            lens_radius = apeture / 2.0f;

            float theta       = vfov * (float)Math.PI / 180.0f;
            float half_height = (float)Math.Tan(theta / 2.0f);
            float half_width  = half_height * aspect;

            origin = lookfrom;
            w      = (lookfrom - lookat).unit_vector();
            u      = (Vector3.cross(vup, w)).unit_vector();
            v      = Vector3.cross(w, u);

            lower_left = origin - half_width * focus_dist * u - half_height * focus_dist * v - focus_dist * w;
            horizontal = 2.0f * half_width * focus_dist * u;
            vertical   = 2.0f * half_height * focus_dist * v;
        }