src/rcrt/Intersection.cpp

Go to the documentation of this file.
00001 #include "Intersection.h"
00002 
00003 #include <limits>
00004 #include "primitives/Primitive.h"
00005 
00006 using namespace std;
00007 
00008 namespace rcrt
00009 {
00010 
00011 
00012 Intersection::Intersection() : distance(numeric_limits<float>::infinity()),prim(0),position(0),lastIOR(1,0)
00013 {       
00014 }
00015 
00016 Intersection::Intersection(const float dist, const Primitive* p, const Point3D& pos,
00017                 const float param1, const float param2, bool bs)
00018 : distance(dist),prim(p),position(pos), parameters(param1,param2),
00019 shadingNormal(0,0,0), geomNormal(0,0,0), uv(0,0),
00020 initSNo(false), initGNo(false),
00021 initSNoL(false), initGNoL(false), initUV(false), backside(bs),
00022 lastIOR(1,0)
00023 {
00024         
00025 }
00026 
00027 
00028 Intersection::~Intersection()
00029 {
00030 }
00031 
00032 void Intersection::setUV(const Point2D& uvs)
00033 {
00034         uv = uvs;
00035 }
00036 
00037 bool Intersection::isValid() const
00038 {
00039         return prim != 0;
00040 }
00041 
00042 float Intersection::getDistance() const
00043 {
00044         return distance;
00045 }
00046 const Primitive* const Intersection::getPrimitive() const
00047 {
00048         return prim;
00049 }
00050 
00051 const Point3D& Intersection::getPosition() const
00052 {
00053         return position;
00054 }
00055 
00056 const Vec3D& Intersection::getSNormalW()
00057 {
00058         if(!initSNo){
00059                 initSNo = true;
00060                 if(initSNoL){//transform existing shading normals, needed if we can't reconstruct them
00061                         shadingNormal = prim->normalToWorld(shadingNormalLocal);
00062                 }else{
00063                         shadingNormal = prim->getSNormalWorld(parameters.x(), parameters.y());
00064                 }
00065         }
00066         
00067         return shadingNormal;
00068 }
00069 
00070 const Vec3D& Intersection::getGNormalW()
00071 {
00072         if(!initGNo){
00073                 initGNo = true;
00074                 if(initGNoL)//transform existing geometry normals, useful if we can't reconstruct them easily
00075                         //from parameterization
00076                         geomNormal = prim->normalToWorld(geomNormalLocal);
00077                 else
00078                         geomNormal = prim->getGNormalWorld(parameters.x(), parameters.y());
00079         }
00080         return geomNormal;
00081 }
00082 
00083 
00084 const Vec3D& Intersection::getSNormalL()
00085 {
00086         if(!initSNoL){
00087                 initSNoL = true;
00088                 shadingNormalLocal = prim->getSNormal(parameters.x(), parameters.y());
00089         }
00090         return shadingNormalLocal;
00091 }
00092 
00093 const Vec3D& Intersection::getGNormalL()
00094 {
00095         if(!initGNoL){
00096                 initGNoL = true;
00097                 geomNormalLocal = prim->getGNormal(parameters.x(), parameters.y());
00098         }
00099         return geomNormalLocal;
00100 }
00101 
00102 void Intersection::setSNormalW(const Vec3D& no)
00103 {
00104         initSNo = true;
00105         shadingNormal = no;
00106 }
00107 
00108 void Intersection::setGNormalW(const Vec3D& no)
00109 {
00110         initGNo = true;
00111         geomNormal = no;
00112 }
00113 
00114 void Intersection::setSNormalL(const Vec3D& no)
00115 {
00116         initSNoL = true;
00117         shadingNormalLocal= no;
00118 }
00119 
00120 void Intersection::setGNormalL(const Vec3D& no)
00121 {
00122         initGNoL = true;
00123         geomNormalLocal = no;
00124 }
00125 
00126 void Intersection::setPrimitive(const Primitive* p)
00127 {
00128         prim = p;
00129 }
00130 
00131 const Point2D& Intersection::getUV()
00132 {
00133         if(!initUV){
00134                 initUV = true;
00135                 uv = prim->getUV(parameters.x(), parameters.y());
00136         }
00137         return uv;
00138 }
00139 
00140 const Point2D& Intersection::getParams() const
00141 {
00142         return parameters;
00143 }
00144 
00145 const bool& Intersection::backSide() const
00146 {
00147         return backside;
00148 }
00149 
00150 void Intersection::setLastIOR(const complex<float>& ior)
00151 {
00152         lastIOR = ior;
00153 }
00154 
00155 
00156 void Intersection::setLastIOR(const float& real, const float& imag)
00157 {
00158         lastIOR = std::complex<float>(real,imag);
00159 }
00160 
00161 const complex<float>& Intersection::getLastIOR() const
00162 {
00163         return lastIOR;
00164 }
00165 
00166 }

Generated on Thu Jan 31 19:26:19 2008 for RenderingCompetitionRayTracer by  doxygen 1.5.3