Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 khor 1
#include "camera.h"
2
 
3
using namespace CGLA;
4
 
5
camera::camera(const CGLA::Vec3f& eye,
6
               const CGLA::Vec3f& cnt,
7
               const CGLA::Vec3f& up,
8
               float focal)
9
{
10
    eye_ = eye;
11
 
12
    z_ = normalize(eye - cnt);
13
 
14
    x_ = normalize(cross(up, z_));
15
    y_ = cross(z_, x_);
16
 
17
    x_ *= 0.012f;
18
    y_ *= 0.012f;
19
 
20
    focal_ = focal;
21
}
22
 
23
ray camera::generate(const Vec2f& uv) const
24
{
25
    Vec2f xy = 2.f * uv - Vec2f(1.f);
26
 
27
    ray r;
28
    r.origin = eye_;
29
    r.direction = normalize(-focal_*z_ + xy[0]*x_ + xy[1]*y_);
30
    r.depth = 0;
31
    r.distance = std::numeric_limits<float>::infinity();
32
    return r;
33
}
34
 
35
//02566 framework, Anders Wang Kristensen, awk@imm.dtu.dk, 2007