summaryrefslogtreecommitdiff
path: root/src/modules/ray/ray_object_sphere.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-08-08 09:42:30 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-08-15 16:46:40 -0700
commitadb76b79d39a185be4659193baff0cb1fe043506 (patch)
treefdc51e2d986e7ef6bd22d0897bdbca10ed51f550 /src/modules/ray/ray_object_sphere.h
parent760112de102f36ba5aaf16d9e949d0bfa3623175 (diff)
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.
Diffstat (limited to 'src/modules/ray/ray_object_sphere.h')
-rw-r--r--src/modules/ray/ray_object_sphere.h4
1 files changed, 2 insertions, 2 deletions
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);
}
© All Rights Reserved