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