示例#1
0
        public static Camera Create(ParamSet paramSet, AnimatedTransform cam2World, Film film, Medium medium)
        {
            // Extract common camera parameters from _ParamSet_
            double shutteropen  = paramSet.FindOneFloat("shutteropen", 0.0);
            double shutterclose = paramSet.FindOneFloat("shutterclose", 1.0);

            if (shutterclose < shutteropen)
            {
                //Warning("Shutter close time [%f] < shutter open [%f].  Swapping them.",
                //        shutterclose, shutteropen);

                PbrtMath.Swap(ref shutterclose, ref shutteropen);
            }
            double lensradius    = paramSet.FindOneFloat("lensradius", 0.0);
            double focaldistance = paramSet.FindOneFloat("focaldistance", 1e6);
            double frame         = paramSet.FindOneFloat(
                "frameaspectratio",
                Convert.ToDouble(film.FullResolution.X) / Convert.ToDouble(film.FullResolution.Y));
            Bounds2D screen;

            if (frame > 1.0)
            {
                screen = new Bounds2D(new Point2D(-frame, -1.0), new Point2D(frame, 1.0));
            }
            else
            {
                screen = new Bounds2D(new Point2D(-1.0, -1.0 / frame), new Point2D(1.0, 1.0 / frame));
            }
            double[] sw = paramSet.FindFloat("screenwindow");
            if (sw != null)
            {
                if (sw.Length == 4)
                {
                    screen = new Bounds2D(new Point2D(sw[0], sw[2]), new Point2D(sw[1], sw[3]));
                }
                else
                {
                    //Error("\"screenwindow\" should have four values");
                }
            }
            double fov     = paramSet.FindOneFloat("fov", 90.0);
            double halffov = paramSet.FindOneFloat("halffov", -1.0);

            if (halffov > 0.0)
            {
                // hack for structure synth, which exports half of the full fov
                fov = 2.0 * halffov;
            }

            return(new PerspectiveCamera(cam2World, screen, shutteropen, shutterclose,
                                         lensradius, focaldistance, fov, film, medium));
        }