src/rcrt/materials/Material.cpp

Go to the documentation of this file.
00001 #include "Material.h"
00002 
00003 using namespace std;
00004 
00005 namespace rcrt
00006 {
00007 
00008 Material::Material(float iorR, float iorI, const RGBColor& absorb):ior(iorR,iorI),absorbance(absorb),bumpMap(0)
00009 {
00010 }
00011 
00012 Material::Material(const complex<float>& IOR, const RGBColor& absorb):ior(IOR),absorbance(absorb),bumpMap(0)
00013 {
00014 }
00015 
00016 Material::~Material()
00017 {
00018 }
00019 /*
00020 float Material::getConvertedIOR() const
00021 {
00022         float f1 = (ior.real() - 1.0); 
00023         f1 = f1*f1 + ior.imag() * ior.imag();
00024 
00025         float f2 = (ior.real() + 1.0); 
00026          f2 = f2*f2 + ior.imag() * ior.imag();
00027 
00028         float sqrtF = sqrt(f1 / f2);
00029 
00030         return (1.0 + sqrtF) / (1.0 - sqrtF);
00031 }*/
00032 
00033 const float& Material::getRealIORPart() const
00034 {
00035         return ior.real();
00036 }
00037 
00038 const float& Material::getImagIORPart() const
00039 {
00040         return ior.imag();
00041 }
00042 
00043 bool Material::refracts() const
00044 {
00045         return ior.imag() == 0;
00046 }
00047 
00048 const std::complex<float> Material::getIOR() const
00049 {
00050         return ior;
00051 }
00052 
00053 Vec3D Material::getShadingNormal(Intersection& is) const
00054 {
00055         int flip = is.backSide() ? -1 : 1;
00056         if(bumpMap) {
00057                 //std::cout << "getting bumped shading normal" << std::endl;
00058                 Matrix4D m = Matrix4D::getOrthoNormalBasis(is.getSNormalW() * flip,
00059                                 is.getPrimitive()->getTangent(is.getUV()[0],is.getUV()[1]));
00060                 //std::cout << m << std::endl;
00061                 Point2D uv = is.getUV();
00062                 //std::cout << uv[0] << "," << uv[1] << std::endl;
00063                 //std::cout << bumpFactor << std::endl;
00064                 return bumpMap->getBump(is.getUV(), bumpFactor, m);
00065         }
00066         else {
00067                 return is.getSNormalW() * flip;
00068         }
00069 }
00070 
00071 void Material::setBumpMap(Texture2D* tex)
00072 {
00073         bumpMap = tex;
00074 }
00075 
00076 void Material::setBumpFactor(const float& f)
00077 {
00078         bumpFactor = f;
00079 }
00080 
00081 const RGBColor& Material::getAbsorbance() const
00082 {
00083         return absorbance;
00084 }
00085 
00086 void Material::setFrame(const int& n)
00087 {
00088         frame = n;
00089 }
00090 
00091 }

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