+#include <limits>
+#include <iostream>
+#include <cassert>
+
#include "PerspectiveCamera.hxx"
PerspectiveCamera::PerspectiveCamera()
m_angle(angle)
{
// preprocess the values and fill the rest of the member variables here
+ m_dir.normalize();
+ m_up.normalize();
+
+ // compute local coordinate system
+ m_zAxis = dir;
+ m_xAxis = dir.cross(up);
+ m_yAxis = m_xAxis.cross(m_zAxis);
+
+ m_xAxis.normalize();
+ m_yAxis.normalize();
+ m_zAxis.normalize();
+
+ m_aspect = resX/static_cast<float>(resY);
+
+ // derive focal length from opening angle
+ float angle_in_rad = angle * M_PI / 180.0f;
+ m_focus = 1.0 / tan(angle_in_rad * 0.5);
}
PerspectiveCamera::~PerspectiveCamera()
PerspectiveCamera&
PerspectiveCamera::operator=(const PerspectiveCamera& )
{
+ assert(!"Not implemented!");
return *this;
}
PerspectiveCamera::InitRay(float x, //!< pixel x-coordinate
float y, //!< pixel y-coordinate
Ray& ray //!< should be filled by this function
- )
+ ) const
{
// define direction,position and maximum hit distance of Ray here
- return false;
+ Vec3f dir = m_xAxis * ( 2.0f * ((x/static_cast<float>(m_resX) - 0.5 ) * m_aspect ) )
+ + m_yAxis * ( 2.0f * (y/static_cast<float>(m_resY) - 0.5 ) )
+ + ( m_zAxis * m_focus );
+ dir.normalize();
+
+ ray.setDir(dir);
+ ray.setOrigin(m_pos);
+ float t = std::numeric_limits<float>::max();
+ ray.setT(t);
+
+ return true;
}