From adb76b79d39a185be4659193baff0cb1fe043506 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 8 Aug 2017 09:42:30 -0700 Subject: ray: misc computational fixups ray:object intersection coordinates were incorrectly being computed relative to the ray origin using a subtraction instead of addition, a silly mistake with surprisingly acceptable results. Those results were a result of other minor complementary mistakes compensating to produce reasonable looking results. In the course of experimenting with an acceleration data structure it became very apparent that 3d space traversal vectors were not behaving as intended, leading to review and correction of this code. --- src/modules/ray/ray_object_sphere.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/modules/ray/ray_object_sphere.h') diff --git a/src/modules/ray/ray_object_sphere.h b/src/modules/ray/ray_object_sphere.h index c07f345..0077a68 100644 --- a/src/modules/ray/ray_object_sphere.h +++ b/src/modules/ray/ray_object_sphere.h @@ -27,7 +27,7 @@ typedef struct ray_object_sphere_t { static void ray_object_sphere_prepare(ray_object_sphere_t *sphere, ray_camera_t *camera) { - sphere->_prepared.primary_v = ray_3f_sub(&camera->position, &sphere->center); + sphere->_prepared.primary_v = ray_3f_sub(&sphere->center, &camera->position); sphere->_prepared.primary_dot_vv = ray_3f_dot(&sphere->_prepared.primary_v, &sphere->_prepared.primary_v); sphere->_prepared.r2 = sphere->radius * sphere->radius; @@ -44,7 +44,7 @@ static inline int ray_object_sphere_intersects_ray(ray_object_sphere_t *sphere, float b, disc; if (depth) { - v = ray_3f_sub(&ray->origin, &sphere->center); + v = ray_3f_sub(&sphere->center, &ray->origin); dot_vv = ray_3f_dot(&v, &v); } -- cgit v1.2.1