added Vector::refract()
git-svn-id: svn://anubis/fart/trunk@372 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
1eee61002e
commit
ed58d2ec7a
@ -63,6 +63,23 @@ class Vector
|
||||
return (*this) - target * (2 * dot(target));
|
||||
}
|
||||
|
||||
/*
|
||||
* from http://www.flipcode.com/archives/
|
||||
* Reflections_and_Refraction_in_Raytracing.shtml
|
||||
* target: normal vector of surface
|
||||
* n1: refraction index of object we're coming from
|
||||
* n2: refraction index of object we're going into
|
||||
*/
|
||||
Vector refract(const Vector & target, double n1, double n2) const
|
||||
{
|
||||
const double n = n1 / n2;
|
||||
const double cosI = dot(target);
|
||||
const double sinT2 = n * n * (1.0 - cosI * cosI);
|
||||
if (sinT2 > 1.0)
|
||||
return Vector(0.0, 0.0, 0.0);
|
||||
return (*this) * n - target * (n + sqrt(1.0 - sinT2));
|
||||
}
|
||||
|
||||
Vector getPerpendicular() const
|
||||
{
|
||||
Vector t = *this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user