Ray.cc

00001 /**********************************************************************
00002  * blaRAY -- photon mapper/raytracer
00003  * (C) 2008 by Tomasz bla Fortuna <bla@thera.be>, <bla@af.gliwice.pl>
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * any later version.
00009  *
00010  * See Docs/LICENSE
00011  *********************/
00012 
00013 #include <cmath>
00014 
00015 #include "General/Types.hh"
00016 #include "Math/Vector.hh"
00017 #include "Render/Ray.hh"
00018 
00019 namespace Render {
00020         Ray Ray::RayFromPoints(const Math::Vector &Source,
00021                                const Math::Vector &Destination)
00022         {
00023                 return Ray(Source, (Destination - Source).Normalize());
00024         }
00025 
00026 
00027         Ray Ray::Reflect(const Math::Vector &Normal,
00028                          const Math::Vector &Point) const
00029         {
00034                 const Math::Vector tmp = Normal * (2 * Normal.Dot(this->D));
00035                 return Ray(Point, this->D - tmp);
00036         }
00037 
00038         Ray Ray::Refract(const Math::Vector &Normal,
00039                          const Math::Vector &Point,
00040                          Double FromN, Double IntoN) const
00041         {
00042                 const Double n = FromN / IntoN;
00043                 const Double c1 = - Normal.Dot(this->D);
00044                 const Double c2 = std::sqrt(1.0 - n*n * (1.0 - c1*c1) );
00045                 const Double c3 = n * c1 - c2;
00046                 const Math::Vector Dir = (this->D * n) + (Normal * c3);
00047                 return Ray(Point, Dir);
00048         }
00049 
00050         std::ostream &operator<<(std::ostream &os, const Ray &R)
00051         {
00052                 os << "[Ray Start="
00053                    << R.Start()
00054                    << " Dir="
00055                    << R.Direction()
00056                    << "]";
00057                 return os;
00058         }
00059 
00060 }

Generated on Wed Mar 12 00:34:58 2008 for blaRAY by  doxygen 1.5.5