00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "lux.h"
00025 #include "camera.h"
00026 #include "film.h"
00027 #include "sampling.h"
00028 #include "error.h"
00029
00030 using namespace lux;
00031
00032
00033 Camera::~Camera() {
00034 delete film;
00035 }
00036 Camera::Camera(const Transform &w2cstart,
00037 const Transform &w2cend,
00038 float hither, float yon,
00039 float sopen, float sclose, int sdist, Film *f)
00040 : CameraMotion(sopen, sclose, w2cstart, w2cend) {
00041 WorldToCamera = w2cstart;
00042 CameraToWorld = WorldToCamera.GetInverse();
00043 ClipHither = hither;
00044 ClipYon = yon;
00045 ShutterOpen = sopen;
00046 ShutterClose = sclose;
00047 ShutterDistribution = sdist;
00048 film = f;
00049 warnOnce = false;
00050 }
00051 bool Camera::IsDelta() const {
00052 luxError(LUX_BUG,LUX_SEVERE,"Unimplemented Camera::IsDelta() method called");
00053 return true;
00054 }
00055 void Camera::SampleMotion(float time) {
00056 if (!CameraMotion.isActive)
00057 return;
00058
00059 WorldToCamera = CameraMotion.Sample(time);
00060 CameraToWorld = WorldToCamera.GetInverse();
00061 }
00062 float Camera::GetTime(float u1) const {
00063 if(ShutterDistribution == 0)
00064 return Lerp(u1, ShutterOpen, ShutterClose);
00065 else {
00066
00067 }
00068
00069 return 0.f;
00070 }
00071
00072 ProjectiveCamera::ProjectiveCamera(const Transform &w2cs,
00073 const Transform &w2ce,
00074 const Transform &proj, const float Screen[4],
00075 float hither, float yon, float sopen,
00076 float sclose, int sdist, float lensr, float focald, Film *f)
00077 : Camera(w2cs, w2ce, hither, yon, sopen, sclose, sdist, f) {
00078
00079 LensRadius = lensr;
00080 FocalDistance = focald;
00081
00082 CameraToScreen = proj;
00083 WorldToScreen = CameraToScreen * WorldToCamera;
00084
00085 ScreenToRaster = Scale(float(film->xResolution),
00086 float(film->yResolution), 1.f) *
00087 Scale(1.f / (Screen[1] - Screen[0]),
00088 1.f / (Screen[2] - Screen[3]), 1.f) *
00089 Translate(Vector(-Screen[0], -Screen[3], 0.f));
00090 RasterToScreen = ScreenToRaster.GetInverse();
00091 RasterToCamera = CameraToScreen.GetInverse() * RasterToScreen;
00092 WorldToRaster = ScreenToRaster * WorldToScreen;
00093 RasterToWorld = WorldToRaster.GetInverse();
00094 }
00095 void ProjectiveCamera::SampleMotion(float time) {
00096
00097 if (!CameraMotion.isActive)
00098 return;
00099
00100
00101 Camera::SampleMotion(time);
00102
00103 WorldToScreen = CameraToScreen * WorldToCamera;
00104 WorldToRaster = ScreenToRaster * WorldToScreen;
00105 RasterToWorld = WorldToRaster.GetInverse();
00106 }
00107 bool ProjectiveCamera::GenerateSample(const Point &p, Sample *sample) const
00108 {
00109 Point p_raster = WorldToRaster(p);
00110 sample->imageX = p_raster.x;
00111 sample->imageY = p_raster.y;
00112
00113
00114
00115 if (sample->imageX>=0 && sample->imageX<film->xResolution &&
00116 sample->imageY>=0 && sample->imageY<film->yResolution )
00117 return true;
00118 else
00119 return false;
00120
00121 return true;
00122 }