From 1eee61002e14422af3c79ae0a37b27937e6af3d5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 11 Oct 2010 15:21:50 +0000 Subject: [PATCH] reworked Vector::reflect() to reflect an INCOMING ray git-svn-id: svn://anubis/fart/trunk@371 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- main/Scene.cc | 4 ++-- util/Vector.h | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main/Scene.cc b/main/Scene.cc index deb3690..43afa9b 100644 --- a/main/Scene.cc +++ b/main/Scene.cc @@ -155,7 +155,7 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor) { color *= (1.0 - reflectance); Vector reflected_direction = - (-ray.getDirection()).reflect(hit.normal); + ray.getDirection().reflect(hit.normal); Ray newRay(hit.position, reflected_direction); Vector jitter_surface_point = newRay[0.0001]; Ray jitterNewRay(jitter_surface_point, reflected_direction); @@ -257,7 +257,7 @@ Color Scene::computePhong(const refptr material, Vector directionToLight = jitterPosition - surfacePoint; directionToLight.normalize(); Vector reflectedLightDirection = - directionToLight.reflect(surfaceNormal); + (-directionToLight).reflect(surfaceNormal); Ray surfaceToLight(surfacePoint, directionToLight); Color light_contribution = diff --git a/util/Vector.h b/util/Vector.h index 7fac54c..fe15fa8 100644 --- a/util/Vector.h +++ b/util/Vector.h @@ -60,9 +60,7 @@ class Vector Vector reflect(const Vector & target) const { - Vector projected = proj(target); - Vector me_to_proj = projected - (*this); - return (*this) + me_to_proj * 2.0; + return (*this) - target * (2 * dot(target)); } Vector getPerpendicular() const @@ -102,21 +100,23 @@ class Vector } /* Compute the dot-product of two vectors */ - double operator%(const Vector & v2) const + double dot(const Vector & v2) const { return m_array[0] * v2.m_array[0] + m_array[1] * v2.m_array[1] + m_array[2] * v2.m_array[2]; } + double operator%(const Vector & v2) const { return dot(v2); } /* Compute the cross-product of two vectors */ - Vector operator*(const Vector & v2) const + Vector cross(const Vector & v2) const { return Vector( m_array[1] * v2.m_array[2] - m_array[2] * v2.m_array[1], m_array[2] * v2.m_array[0] - m_array[0] * v2.m_array[2], m_array[0] * v2.m_array[1] - m_array[1] * v2.m_array[0]); } + Vector operator*(const Vector & v2) const { return cross(v2); } Vector operator+(const Vector & v2) const {