Subversion Repositories gelsvn

Rev

Rev 346 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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