rayzor
view src/camera.cc @ 22:5380ff64e83f
minor changes from dos, and line endings cleanup
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 02 May 2014 14:32:58 +0300 |
parents | 79609d482762 |
children |
line source
1 #include "camera.h"
2 #include "rayzor.h"
4 Camera::Camera()
5 {
6 type = NODE_CAMERA;
7 fov = M_PI / 4.0;
8 set_position(Vector3(0, 0, 10));
9 }
11 void Camera::set_target(const Vector3 &target)
12 {
13 this->target.set_position(target);
14 }
16 Vector3 Camera::get_target() const
17 {
18 return target.get_position();
19 }
21 void Camera::set_fov(float fov)
22 {
23 this->fov = fov;
24 }
26 float Camera::get_fov() const
27 {
28 return fov;
29 }
31 void Camera::calc_matrix() const
32 {
33 if(!xform_valid) {
34 xform.set_identity();
35 xform.lookat(pos, target.get_position(), Vector3(0, 1, 0));
36 xform_valid = true;
37 }
38 }
40 void Camera::draw(bool emph) const
41 {
42 }
44 bool Camera::intersect(const Ray &ray, RayHit *hit) const
45 {
46 return false;
47 }
49 Ray Camera::get_primary_ray(int x, int y) const
50 {
51 calc_inv_matrix();
53 float aspect = (float)fb_width / (float)fb_height;
54 float pwidth = 2.0 * aspect / (float)fb_width;
55 float pheight = 2.0 / (float)fb_height;
57 Vector3 dir;
58 dir.x = (float)x * pwidth - aspect;
59 dir.y = 1.0 - (float)y * pheight;
60 dir.z = -1.0 / tan(fov / 2.0);
61 dir.normalize();
63 return transform(inv_xform, Ray(Vector3(0, 0, 0), dir));
64 }