PhongReflection.cc

Go to the documentation of this file.
00001 #include <gra/reflection/PhongReflection.h>
00002 #include <gra/reflection/LocalReflection.h>
00003 #include <esg/brdf/PhongBRDF.h>
00004 #include <esg/brdf/BlinnBRDF.h>
00005 #include <esg/brdf/LambertianBRDF.h>
00006 #include <esg/SceneGraphObject.h>
00007 
00008 using namespace gra;
00009 
00010 PhongReflection::PhongReflection(Emittance     * e,
00011                                  SpecularEval    s,
00012                                  const Color3f&  c)
00013     : LocalReflection(NULL, NULL, e), _globalAmbient(c)
00014 {
00015     switch (s) {
00016     case PHONG:
00017         _pDiffuseBRDF  = new LambertianBRDF();
00018         _pSpecularBRDF = new PhongBRDF();
00019         break;
00020     case BLINN:
00021         _pDiffuseBRDF  = new LambertianBRDF();
00022         _pSpecularBRDF = new BlinnBRDF();
00023         break;
00024     default:
00025         fprintf(stderr,"PhongReflection: Uknown BRDF, using Phong + Lambert\n");
00026         _pDiffuseBRDF  = new LambertianBRDF();
00027         _pSpecularBRDF = new PhongBRDF();
00028     }
00029 }
00030 
00031 PhongReflection::~PhongReflection()
00032 {
00033     if (_pSpecularBRDF) delete _pSpecularBRDF;
00034     if (_pDiffuseBRDF)  delete _pDiffuseBRDF;
00035 }
00036 
00037 Color3f* PhongReflection::illuminatePoint(PointEnv & env, MatVisitor& visitor)
00038 {
00039     // compute light contributions except the global ambient
00040     Color3f* pColor = LocalReflection::illuminatePoint(env,visitor);
00041     
00042     // append the global ambient contribution
00043     Vector3 aux(visitor.ambient());
00044     aux.x *= _globalAmbient.x;
00045     aux.y *= _globalAmbient.y;
00046     aux.z *= _globalAmbient.z;
00047     if (pColor) pColor->add(aux);
00048     else pColor = new Color3f(aux);
00049 
00050     return pColor;    
00051 }

Generated on Tue Nov 21 15:11:42 2006 for gra by  doxygen 1.4.6