00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "camera.h"
00026 #include "film.h"
00027 #include "paramset.h"
00028
00029 class OrthoCamera : public ProjectiveCamera {
00030 public:
00031
00032 OrthoCamera(const Transform &world2cam,
00033 const float Screen[4],
00034 float hither, float yon,
00035 float sopen, float sclose,
00036 float lensr, float focald, Film *film);
00037 float GenerateRay(const Sample &sample, Ray *) const;
00038 };
00039
00040 OrthoCamera::OrthoCamera(const Transform &world2cam,
00041 const float Screen[4], float hither, float yon,
00042 float sopen, float sclose, float lensr,
00043 float focald, Film *f)
00044 : ProjectiveCamera(world2cam, Orthographic(hither, yon),
00045 Screen, hither, yon, sopen, sclose,
00046 lensr, focald, f) {
00047 }
00048 float OrthoCamera::GenerateRay(const Sample &sample,
00049 Ray *ray) const {
00050
00051 Point Pras(sample.imageX, sample.imageY, 0);
00052 Point Pcamera;
00053 RasterToCamera(Pras, &Pcamera);
00054 ray->o = Pcamera;
00055 ray->d = Vector(0,0,1);
00056
00057 ray->time = Lerp(sample.time, ShutterOpen, ShutterClose);
00058
00059 if (LensRadius > 0.) {
00060
00061 float lensU, lensV;
00062 ConcentricSampleDisk(sample.lensU, sample.lensV,
00063 &lensU, &lensV);
00064 lensU *= LensRadius;
00065 lensV *= LensRadius;
00066
00067 float ft = (FocalDistance - ClipHither) / ray->d.z;
00068 Point Pfocus = (*ray)(ft);
00069
00070 ray->o.x = lensU * (FocalDistance - ClipHither) / FocalDistance;
00071 ray->o.y = lensV * (FocalDistance - ClipHither) / FocalDistance;
00072 ray->d = Pfocus - ray->o;
00073 }
00074 ray->mint = 0.;
00075 ray->maxt = ClipYon - ClipHither;
00076 ray->d = Normalize(ray->d);
00077 CameraToWorld(*ray, ray);
00078 return 1.f;
00079 }
00080 extern "C" DLLEXPORT Camera *CreateCamera(const ParamSet ¶ms,
00081 const Transform &world2cam, Film *film) {
00082
00083 float hither = max(1e-4f, params.FindOneFloat("hither", 1e-3f));
00084 float yon = min(params.FindOneFloat("yon", 1e30f), 1e30f);
00085 float shutteropen = params.FindOneFloat("shutteropen", 0.f);
00086 float shutterclose = params.FindOneFloat("shutterclose", 1.f);
00087 float lensradius = params.FindOneFloat("lensradius", 0.f);
00088 float focaldistance = params.FindOneFloat("focaldistance", 1e30f);
00089 float frame = params.FindOneFloat("frameaspectratio",
00090 float(film->xResolution)/float(film->yResolution));
00091 float screen[4];
00092 if (frame > 1.f) {
00093 screen[0] = -frame;
00094 screen[1] = frame;
00095 screen[2] = -1.f;
00096 screen[3] = 1.f;
00097 }
00098 else {
00099 screen[0] = -1.f;
00100 screen[1] = 1.f;
00101 screen[2] = -1.f / frame;
00102 screen[3] = 1.f / frame;
00103 }
00104 int swi;
00105 const float *sw = params.FindFloat("screenwindow", &swi);
00106 if (sw && swi == 4)
00107 memcpy(screen, sw, 4*sizeof(float));
00108 return new OrthoCamera(world2cam, screen, hither, yon,
00109 shutteropen, shutterclose, lensradius, focaldistance,
00110 film);
00111 }