rayzor

view src/camera.cc @ 17:79609d482762

the renderer renders, also fixed an unnoticed matrix conversion problem between scenegraph and min3d
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 14 Apr 2014 07:34:45 +0300
parents be616b58df99
children 859ccadca671
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() 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 }