00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _CAMERA_H_
00014 #define _CAMERA_H_
00015
00016 #include <cmath>
00017
00018 #include "General/Types.hh"
00019 #include "Math/Vector.hh"
00020 #include "Render/Ray.hh"
00021
00022 namespace World {
00023
00032 class Camera {
00033 protected:
00035 Double FOV;
00036
00038 Math::Vector Pos;
00039
00041 Math::Vector Dir;
00042
00046 Math::Vector Top;
00047
00048 public:
00050 class View {
00051 friend class Camera;
00052
00053 protected:
00055 const Math::Vector &Pos;
00056
00058 const Math::Vector &Dir;
00059
00062 const Math::Vector XVect;
00063
00066 const Math::Vector YVect;
00067
00069 Double XResHalf, YResHalf;
00073 View(Int XRes, Int YRes,
00074 const Math::Vector &Pos, const Math::Vector &Dir,
00075 const Math::Vector XVect, const Math::Vector YVect)
00076 : Pos(Pos), Dir(Dir), XVect(XVect), YVect(YVect),
00077 XResHalf(XRes/2.0), YResHalf(YRes/2.0)
00078 {
00079 }
00080 public:
00083 Render::Ray At(Int x, Int y) const;
00084 };
00085
00087 static inline Double DegreeToFOV(Double Degree)
00088 {
00089 return (double)Degree / 360.0 * 2 * M_PI;
00090 }
00091
00102 Camera(const Math::Vector &Pos = Math::Vector(0.0, 1.0, -1.0),
00103 const Math::Vector &Dir = Math::Vector(0.0, 0.0, 1.0),
00104 Double FOV = DegreeToFOV(45.0),
00105 Bool AutoTop = true,
00106 const Math::Vector &Top = Math::Vector(0.0, 1.0, 0.0));
00107
00110 View CreateView(Int XRes, Int YRes) const;
00111
00113 friend std::ostream &operator<<(std::ostream &os, const Camera &C);
00114 };
00115 };
00116
00117 #endif