From f8be952a9b32302626d0743c288fde5409d8f7fb Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sun, 1 Jan 2017 17:23:23 -0800 Subject: [PATCH] Fixed the camera coords in the view matrix. Tweaked cam position in kernel, odd off by one error. --- kernels/ray_caster_kernel.cl | 22 ++++++++++------------ src/Hardware_Caster.cpp | 8 +++++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index 078851f..93c90e6 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -105,8 +105,6 @@ __kernel void raycaster( int random_number = rand(&seed); seed_memory[global_id] = seed; - - size_t id = get_global_id(0); int2 pixel = {id % (*resolution).x, id / (*resolution).x}; float3 ray_dir = projection_matrix[pixel.x + (*resolution).x * pixel.y]; @@ -116,13 +114,14 @@ __kernel void raycaster( return; } - ray_dir = (float3)( - // 1.57s are temp fix until view matrix is tweaked - ray_dir.z * sin((*cam_dir).x - 1.57) + ray_dir.x * cos((*cam_dir).x - 1.57), - ray_dir.y, - ray_dir.z * cos((*cam_dir).x - 1.57) - ray_dir.x * sin((*cam_dir).x - 1.57) - ); + // Pitch + ray_dir = (float3)( + ray_dir.z * sin((*cam_dir).x) + ray_dir.x * cos((*cam_dir).x), + ray_dir.y, + ray_dir.z * cos((*cam_dir).x) - ray_dir.x * sin((*cam_dir).x) + ); + // Yaw ray_dir = (float3)( ray_dir.x * cos((*cam_dir).y) - ray_dir.y * sin((*cam_dir).y), ray_dir.x * sin((*cam_dir).y) + ray_dir.y * cos((*cam_dir).y), @@ -134,7 +133,9 @@ __kernel void raycaster( voxel_step *= (ray_dir > 0) - (ray_dir < 0); // Setup the voxel coords from the camera origin - int3 voxel = convert_int3(*cam_pos); + // Off by one error here in regards to the camera position. + // Will need to hunt this down later + int3 voxel = convert_int3(*cam_pos + 1); // Delta T is the units a ray must travel along an axis in order to // traverse an integer split @@ -144,9 +145,6 @@ __kernel void raycaster( float3 offset = ((*cam_pos) - floor(*cam_pos)) * convert_float3(voxel_step); - //offset.x += delta_t.x * convert_float((voxel_step.x < 0)); - //offset -= delta_t * floor(offset / delta_t); - // Intersection T is the collection of the next intersection points // for all 3 axis XYZ. float3 intersection_t = delta_t * offset; diff --git a/src/Hardware_Caster.cpp b/src/Hardware_Caster.cpp index d67c036..769e201 100644 --- a/src/Hardware_Caster.cpp +++ b/src/Hardware_Caster.cpp @@ -132,7 +132,6 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float static_cast(ray.z * cos(y_increment_radians * y) - ray.x * sin(y_increment_radians * y)) ); - // Z axis, yaw ray = sf::Vector3f( static_cast(ray.x * cos(x_increment_radians * x) - ray.y * sin(x_increment_radians * x)), @@ -140,6 +139,13 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float static_cast(ray.z) ); + // correct for the base ray pointing to (1, 0, 0) as (0, 0). Should equal (1.57, 0) + ray = sf::Vector3f( + static_cast(ray.z * sin(-1.57) + ray.x * cos(-1.57)), + static_cast(ray.y), + static_cast(ray.z * cos(-1.57) - ray.x * sin(-1.57)) + ); + int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2); ray = Normalize(ray);