erebus
diff liberebus/src/camera.cc @ 8:e2d9bf168a41
semi-works ...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 24 May 2014 06:12:57 +0300 |
parents | 9621beb22694 |
children | d15ee526daa6 |
line diff
1.1 --- a/liberebus/src/camera.cc Sat May 24 02:27:08 2014 +0300 1.2 +++ b/liberebus/src/camera.cc Sat May 24 06:12:57 2014 +0300 1.3 @@ -2,32 +2,25 @@ 1.4 #include <math.h> 1.5 #include "camera.h" 1.6 1.7 +#define DEFAULT_FOV DEG_TO_RAD(50) 1.8 + 1.9 static void calc_sample_pos_rec(int sidx, float xsz, float ysz, float *pos); 1.10 1.11 Camera::Camera() 1.12 { 1.13 - vfov = M_PI / 4.0; 1.14 + vfov = DEFAULT_FOV; 1.15 cached_matrix_valid = false; 1.16 - 1.17 - rdir_cache_width = rdir_cache_height = 0; 1.18 - rdir_cache_fov = 0; 1.19 - rdir_cache = 0; 1.20 } 1.21 1.22 Camera::Camera(const Vector3 &p) 1.23 : pos(p) 1.24 { 1.25 - vfov = M_PI / 4.0; 1.26 + vfov = DEFAULT_FOV; 1.27 cached_matrix_valid = false; 1.28 - 1.29 - rdir_cache_width = rdir_cache_height = 0; 1.30 - rdir_cache_fov = 0; 1.31 - rdir_cache = 0; 1.32 } 1.33 1.34 Camera::~Camera() 1.35 { 1.36 - delete [] rdir_cache; 1.37 } 1.38 1.39 void Camera::set_fov(float vfov) 1.40 @@ -77,38 +70,14 @@ 1.41 1.42 Ray Camera::get_primary_ray(int x, int y, int xsz, int ysz, int sample) const 1.43 { 1.44 -#pragma omp single 1.45 - { 1.46 - if(!rdir_cache || rdir_cache_width != xsz || rdir_cache_height != ysz || 1.47 - fabs(rdir_cache_fov - vfov) > 1e-4) { 1.48 - printf("calculating primary ray direction cache (%dx%d)\n", xsz, ysz); 1.49 - 1.50 - delete [] rdir_cache; 1.51 - rdir_cache = new Vector3[xsz * ysz]; 1.52 - 1.53 -#pragma omp parallel for 1.54 - for(int i=0; i<ysz; i++) { 1.55 - Vector3 *rdir = rdir_cache + i * xsz; 1.56 - for(int j=0; j<xsz; j++) { 1.57 - Vector2 ppos = calc_sample_pos(j, i, xsz, ysz, 0); 1.58 - 1.59 - rdir->x = ppos.x; 1.60 - rdir->y = ppos.y; 1.61 - rdir->z = 1.0 / tan(vfov / 2.0); 1.62 - rdir->normalize(); 1.63 - 1.64 - rdir++; 1.65 - } 1.66 - } 1.67 - rdir_cache_width = xsz; 1.68 - rdir_cache_height = ysz; 1.69 - rdir_cache_fov = vfov; 1.70 - } 1.71 - } 1.72 + Vector2 ppos = calc_sample_pos(x, y, xsz, ysz, sample); 1.73 1.74 Ray ray; 1.75 ray.origin = pos; 1.76 - ray.dir = rdir_cache[y * xsz + x]; 1.77 + ray.dir.x = ppos.x; 1.78 + ray.dir.y = ppos.y; 1.79 + ray.dir.z = 1.0 / tan(vfov / 2.0); 1.80 + ray.dir.normalize(); 1.81 1.82 // transform the ray direction with the camera matrix 1.83 Matrix4x4 mat = get_matrix();