SpotEmittance.h

Go to the documentation of this file.
00001 /* $Id:$ */
00002 
00003 #ifndef __SPOT_EMITTANCE_H
00004 #define __SPOT_EMITTANCE_H
00005 
00006 #include <esg/emittance/Emittance.h>
00007 
00008 /*
00009  * Emittance attenuating proportionally to spot light parametters.
00010  */
00011 
00012 namespace esg {
00013 
00014 class SpotEmittance : public Emittance {
00015 protected:
00016     float _spreadAngle;    // The angle in rad. between the dir. axis and
00017                            // a ray  along edge of the cone.
00018                            // Range is [0.0, PI/2]
00019     char  _concentration;  // How quickly the light attenuates. Range [0, 128]
00020     float _cosDelta;       // cosinus of spread angle
00021 
00022 protected:
00023     virtual void _duplicate_attributes (const Emittance& src) {
00024         Emittance::_duplicate_attributes(src);
00025         _spreadAngle   = ((SpotEmittance&)src)._spreadAngle;
00026         _concentration = ((SpotEmittance&)src)._concentration;
00027         _cosDelta      = ((SpotEmittance&)src)._cosDelta;
00028     }
00029 
00030     SpotEmittance () {}
00031 
00032 public:
00033     SpotEmittance (const Vector3&  loc,
00034                    const Vector3&  dir,
00035                    const Color3f&  inten = Color3f(1,1,1),
00036                    double          fadeDist      = .0,
00037                    double          fadePower     = .0,
00038                    float           spreadAngle   = PI,
00039                    char            concentration = 0)
00040         : Emittance(loc, true, dir, true, inten, fadeDist, fadePower),
00041           _spreadAngle(spreadAngle),
00042           _concentration(concentration)
00043     {
00044         _cosDelta = cos(_spreadAngle);
00045     }
00046 
00047     virtual Emittance* clone () const {
00048         SpotEmittance * pRet = new SpotEmittance();
00049         pRet->_duplicate_attributes(*this);
00050         return pRet;
00051     }
00052 
00053     virtual bool intensity (const Vector3& v /* view point */,
00054                             Color3f&       c /* intensity  */) const
00055     {
00056         Vector3 dir(v - _location);
00057         float   d = dir.length();
00058 
00059         dir.scale(1.0/d);
00060         
00061         float cosGamma = _direction.dot(dir);
00062         
00063         if (cosGamma <= _cosDelta) return false; // out of area
00064         
00065         c.set(_intensity);
00066         if (_concentration) c.scale(pow(cosGamma, _concentration));
00067 
00068         ESG_ATTENUATION(d,c);
00069 
00070         return true;
00071     }
00072 
00073     virtual bool intensity (const Vector3& v /* emittance direction */,
00074                             float          d /* emittance distance  */,
00075                             Color3f&       c /* intensity           */) const
00076     {
00077         float cosGamma = _direction.dot(v);
00078         
00079         if (cosGamma <= _cosDelta) return false; // out of area
00080         
00081         c.set(_intensity);
00082         if (_concentration) c.scale(pow(cosGamma, _concentration));
00083 
00084         ESG_ATTENUATION(d,c);
00085         
00086         return true;
00087     }
00088 
00089     virtual bool stochasticEmission (Vector3& d)
00090     {
00091         return false; // to do
00092     }
00093 
00094     char  concentration (void) const { return _concentration; }
00095     float spreadAngle   (void) const { return _spreadAngle;   }
00096 };
00097     
00098 }; // namespace
00099 
00100 #endif //__SPOT_EMITTANCE_H

Generated on Wed Jun 28 12:24:28 2006 for esg by  doxygen 1.4.6