00001
00002
00003 #ifndef __EMITTANCE_H
00004 #define __EMITTANCE_H
00005
00006 #include <esg/Definitions.h>
00007 #include <esg/ESGObject.h>
00008 #include <esg/Export>
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace esg {
00035
00036 class OGSCENE_EXPORT Emittance : public ESGObject {
00037 protected:
00038 Vector3 _location;
00039 bool _haveLocation;
00040 Vector3 _direction;
00041 bool _haveDirection;
00042 Color3f _intensity;
00043 double _fadeDistance;
00044 double _fadePower;
00045 bool _attenuate;
00046 bool _fitToGeometry;
00047
00048 protected:
00049 virtual void _duplicate_attributes (const Emittance& src) {
00050 _intensity.set(((Emittance&)src)._intensity);
00051 _direction.set(((Emittance&)src)._direction);
00052 _location.set(((Emittance&)src)._location);
00053 _haveLocation = ((Emittance&)src)._haveLocation;
00054 _haveDirection = ((Emittance&)src)._haveDirection;
00055 _fadeDistance = ((Emittance&)src)._fadeDistance;
00056 _fadePower = ((Emittance&)src)._fadePower;
00057 _attenuate = ((Emittance&)src)._attenuate;
00058 }
00059
00060 Emittance () {}
00061
00062 public:
00063 Emittance (const Vector3& loc,
00064 bool haveLoc,
00065 const Vector3& dir,
00066 bool haveDir,
00067 const Color3f& inten = Color3f(1,1,1),
00068 double fadeDist = .0,
00069 double fadePower = .0,
00070 bool fitToGeom = true)
00071 : _location(loc), _haveLocation(haveLoc),
00072 _direction(dir), _haveDirection(haveDir),
00073 _intensity(inten),
00074 _fadeDistance(fadeDist),
00075 _fadePower(fadePower),
00076 _attenuate((_fadeDistance >= .0 && _fadePower > .0) ? true : false),
00077 _fitToGeometry(fitToGeom) {}
00078
00079 virtual ~Emittance () {}
00080
00081 virtual Emittance* clone () const = 0;
00082
00083 bool intensity (Color3f& c) const {c.set(_intensity); return true;}
00084 virtual bool intensity (const Vector3& ,
00085 Color3f& ) const = 0;
00086 virtual bool intensity (const Vector3& ,
00087 float ,
00088 Color3f& ) const=0;
00089
00090 virtual bool stochasticEmission (Vector3& ) = 0;
00091
00092
00093 bool beamDirection (Vector3& d) const {
00094 if (_haveDirection) d.set(_direction);
00095 return _haveDirection;
00096 }
00097
00098 bool setBeamDirection (const Vector3& d) {
00099 if (_haveDirection) _direction.set(d);
00100 return _haveDirection;
00101 }
00102
00103 bool sourceLocation (Vector3& v) const {
00104 if (_haveLocation) v.set(_location);
00105 return _haveLocation;
00106 }
00107
00108 bool setSourceLocation (const Vector3& v) {
00109 if (_haveLocation) _location.set(v);
00110 return _haveLocation;
00111 }
00112
00113 bool haveLocation (void) const { return _haveLocation; }
00114 bool haveDirection (void) const { return _haveDirection; }
00115 bool fitToGeometry (void) const { return _fitToGeometry; }
00116
00117 double fadeDistance (void) const { return _fadeDistance; }
00118 double fadePower (void) const { return _fadePower; }
00119 };
00120
00121
00122 #define ESG_ATTENUATION(__d, __c) { \
00123 if (_attenuate && (__d > _fadeDistance)) \
00124 (__c).scale(2.0 / (1.0 + pow(((_fadeDistance > 0.) ? (__d) / _fadeDistance : (__d)), _fadePower))); }
00125
00126 };
00127
00128 #endif // __EMITTANCE_H