readded anti-aliasing
[MicroTrace.git] / PerspectiveCamera.cxx
1 #include <limits>
2 #include <iostream>
3
4 #include "PerspectiveCamera.hxx"
5
6 PerspectiveCamera::PerspectiveCamera()
7 : Camera()
8 {
9 }
10
11 PerspectiveCamera::PerspectiveCamera(const Vec3f& pos,
12 const Vec3f& dir,
13 const Vec3f& up,
14 float angle,
15 int resX,
16 int resY)
17 : Camera(resX,resY),
18 m_pos(pos),
19 m_dir(dir),
20 m_up(up),
21 m_angle(angle)
22 {
23 // preprocess the values and fill the rest of the member variables here
24
25 // compute local coordinate system
26 m_zAxis = dir;
27 m_xAxis = dir.cross(up);
28 m_yAxis = m_xAxis.cross(m_zAxis);
29
30 m_xAxis.normalize();
31 m_yAxis.normalize();
32 m_zAxis.normalize();
33
34 m_aspect = resX/static_cast<float>(resY);
35
36 // derive focal length from opening angle
37 float angle_in_rad = angle * M_PI / 180.0f;
38 m_focus = 1.0 / tan(angle_in_rad * 0.5);
39 }
40
41 PerspectiveCamera::~PerspectiveCamera()
42 {
43 }
44
45 PerspectiveCamera::PerspectiveCamera(const PerspectiveCamera& )
46 {
47
48 }
49
50 PerspectiveCamera&
51 PerspectiveCamera::operator=(const PerspectiveCamera& )
52 {
53 return *this;
54 }
55
56 bool
57 PerspectiveCamera::InitRay(float x, //!< pixel x-coordinate
58 float y, //!< pixel y-coordinate
59 Ray& ray //!< should be filled by this function
60 ) const
61 {
62 // define direction,position and maximum hit distance of Ray here
63 Vec3f dir = m_xAxis * ( 2.0f * ((x/static_cast<float>(m_resX) - 0.5 ) * m_aspect ) )
64 + m_yAxis * ( 2.0f * (y/static_cast<float>(m_resY) - 0.5 ) )
65 + ( m_zAxis * m_focus );
66 dir.normalize();
67
68 ray.setDir(dir);
69 ray.setOrigin(m_pos);
70 float t = std::numeric_limits<float>::max();
71 ray.setT(t);
72
73 return true;
74 }
This page took 0.045872 seconds and 5 git commands to generate.