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
00026 #include "stdafx.h"
00027 #include "camera.h"
00028 #include "film.h"
00029 #include "montecarlo.h"
00030 #include "sampler.h"
00031
00032
00033 Camera::~Camera() {
00034 delete film;
00035 }
00036
00037
00038 Camera::Camera(const AnimatedTransform &cam2world,
00039 float sopen, float sclose, Film *f)
00040 : CameraToWorld(cam2world), shutterOpen(sopen), shutterClose(sclose) {
00041 film = f;
00042 if (CameraToWorld.HasScale())
00043 Warning("Scaling detected in world-to-camera transformation!\n"
00044 "The system has numerous assumptions, implicit and explicit,\n"
00045 "that this transform will have no scale factors in it.\n"
00046 "Proceed at your own risk; your image may have errors or\n"
00047 "the system may crash as a result of this.");
00048 }
00049
00050
00051 float Camera::GenerateRayDifferential(const CameraSample &sample,
00052 RayDifferential *rd) const {
00053 float wt = GenerateRay(sample, rd);
00054
00055 CameraSample sshift = sample;
00056 ++(sshift.imageX);
00057 Ray rx;
00058 float wtx = GenerateRay(sshift, &rx);
00059 rd->rxOrigin = rx.o;
00060 rd->rxDirection = rx.d;
00061
00062
00063 --(sshift.imageX);
00064 ++(sshift.imageY);
00065 Ray ry;
00066 float wty = GenerateRay(sshift, &ry);
00067 rd->ryOrigin = ry.o;
00068 rd->ryDirection = ry.d;
00069 if (wtx == 0.f || wty == 0.f) return 0.f;
00070 rd->hasDifferentials = true;
00071 return wt;
00072 }
00073
00074
00075 ProjectiveCamera::ProjectiveCamera(const AnimatedTransform &cam2world,
00076 const Transform &proj, const float screenWindow[4], float sopen,
00077 float sclose, float lensr, float focald, Film *f)
00078 : Camera(cam2world, sopen, sclose, f) {
00079
00080 lensRadius = lensr;
00081 focalDistance = focald;
00082
00083
00084 CameraToScreen = proj;
00085
00086
00087 ScreenToRaster = Scale(float(film->xResolution),
00088 float(film->yResolution), 1.f) *
00089 Scale(1.f / (screenWindow[1] - screenWindow[0]),
00090 1.f / (screenWindow[2] - screenWindow[3]), 1.f) *
00091 Translate(Vector(-screenWindow[0], -screenWindow[3], 0.f));
00092 RasterToScreen = Inverse(ScreenToRaster);
00093 RasterToCamera = Inverse(CameraToScreen) * RasterToScreen;
00094 }
00095
00096