reworked Vector::reflect() to reflect an INCOMING ray

git-svn-id: svn://anubis/fart/trunk@371 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2010-10-11 15:21:50 +00:00
parent 15e4aa1dc0
commit 1eee61002e
2 changed files with 7 additions and 7 deletions

View File

@ -155,7 +155,7 @@ Color Scene::traceRayRecurse(const Ray & ray, int depth, double factor)
{ {
color *= (1.0 - reflectance); color *= (1.0 - reflectance);
Vector reflected_direction = Vector reflected_direction =
(-ray.getDirection()).reflect(hit.normal); ray.getDirection().reflect(hit.normal);
Ray newRay(hit.position, reflected_direction); Ray newRay(hit.position, reflected_direction);
Vector jitter_surface_point = newRay[0.0001]; Vector jitter_surface_point = newRay[0.0001];
Ray jitterNewRay(jitter_surface_point, reflected_direction); Ray jitterNewRay(jitter_surface_point, reflected_direction);
@ -257,7 +257,7 @@ Color Scene::computePhong(const refptr<Material> material,
Vector directionToLight = jitterPosition - surfacePoint; Vector directionToLight = jitterPosition - surfacePoint;
directionToLight.normalize(); directionToLight.normalize();
Vector reflectedLightDirection = Vector reflectedLightDirection =
directionToLight.reflect(surfaceNormal); (-directionToLight).reflect(surfaceNormal);
Ray surfaceToLight(surfacePoint, directionToLight); Ray surfaceToLight(surfacePoint, directionToLight);
Color light_contribution = Color light_contribution =

View File

@ -60,9 +60,7 @@ class Vector
Vector reflect(const Vector & target) const Vector reflect(const Vector & target) const
{ {
Vector projected = proj(target); return (*this) - target * (2 * dot(target));
Vector me_to_proj = projected - (*this);
return (*this) + me_to_proj * 2.0;
} }
Vector getPerpendicular() const Vector getPerpendicular() const
@ -102,21 +100,23 @@ class Vector
} }
/* Compute the dot-product of two vectors */ /* 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] return m_array[0] * v2.m_array[0]
+ m_array[1] * v2.m_array[1] + m_array[1] * v2.m_array[1]
+ m_array[2] * v2.m_array[2]; + m_array[2] * v2.m_array[2];
} }
double operator%(const Vector & v2) const { return dot(v2); }
/* Compute the cross-product of two vectors */ /* Compute the cross-product of two vectors */
Vector operator*(const Vector & v2) const Vector cross(const Vector & v2) const
{ {
return Vector( return Vector(
m_array[1] * v2.m_array[2] - m_array[2] * v2.m_array[1], 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[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]); 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 Vector operator+(const Vector & v2) const
{ {