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:
parent
15e4aa1dc0
commit
1eee61002e
@ -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> material,
|
||||
Vector directionToLight = jitterPosition - surfacePoint;
|
||||
directionToLight.normalize();
|
||||
Vector reflectedLightDirection =
|
||||
directionToLight.reflect(surfaceNormal);
|
||||
(-directionToLight).reflect(surfaceNormal);
|
||||
|
||||
Ray surfaceToLight(surfacePoint, directionToLight);
|
||||
Color light_contribution =
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user