PinholeCamera.cc

Go to the documentation of this file.
00001 
00005 #include "PinholeCamera.h"
00006 #include "Ray.h"
00007 #include "Math.h"
00008 #include <math.h>
00009 
00010 PinholeCamera::PinholeCamera(const Point& eye, const Point& lookat, const Vector& up,
00011                              double hfov)
00012   : eye(eye), lookat(lookat), up(up), hfov(hfov)
00013 {
00014 }
00015 
00016 PinholeCamera::~PinholeCamera()
00017 {
00018 }
00019 
00020 void PinholeCamera::preprocess(double aspect_ratio)
00021 {
00022   lookdir = lookat-eye;
00023   lookdir.normalize();
00024   u = Cross(lookdir, up);
00025   v = Cross(u, lookdir);
00026   double ulen = tan(hfov/2.*M_PI/180.);
00027   u.normalize();
00028   u *= ulen;
00029   double vlen = ulen/aspect_ratio;
00030   v.normalize(); 
00031   v *= vlen;
00032 }
00033 
00034 void PinholeCamera::makeRay(Ray& ray, const RenderContext& context, double x, double y) const
00035 {
00036   Vector direction = lookdir+u*x+v*y;
00037   direction.normalize();
00038   ray = Ray(eye, direction);
00039 }

Generated on Tue Jan 29 21:34:53 2008 for specter by  doxygen 1.4.6