#include <light.h>
Warning: nothing is initialized by default.
To use this light you must initialize the MODE (setMode), the COLORS and the 3 ATTENUATION FACTORS. If the mode is spotlight or pointlight, you must initialize the POSITION. If the mode is spotlight or directionallight, you must initialize the DIRECTION. If the mode is spotlight, you must intialize the EXPONENT and the CUTOFF.
To do so, you can use one of the three methods: setupDirectional, setupPointLight, setupSpotLight or use the specifics methods.
Nevrax France
Definition at line 55 of file light.h.
Public Types | |
enum | TLightMode { DirectionalLight, PointLight, SpotLight } |
Public Member Functions | |
Get methods. | |
NLMISC::CRGBA | getAmbiant () const |
float | getConstantAttenuation () const |
float | getCutoff () const |
NLMISC::CRGBA | getDiffuse () const |
NLMISC::CVector | getDirection () const |
float | getExponent () const |
float | getLinearAttenuation () const |
TLightMode | getMode () const |
NLMISC::CVector | getPosition () const |
float | getQuadraticAttenuation () const |
NLMISC::CRGBA | getSpecular () const |
Set methods. | |
void | setAmbiant (const NLMISC::CRGBA &ambiant) |
void | setConstantAttenuation (float constant) |
void | setCutoff (float cutoff) |
void | setDiffuse (const NLMISC::CRGBA &diffuse) |
void | setDirection (const NLMISC::CVector &direction) |
void | setExponent (float exponent) |
void | setLinearAttenuation (float linear) |
void | setMode (TLightMode mode) |
void | setPosition (const NLMISC::CVector &position) |
void | setQuadraticAttenuation (float quadratic) |
void | setSpecular (const NLMISC::CRGBA &specular) |
Quick setup. | |
void | setNoAttenuation () |
void | setupAttenuation (float farAttenuationBegin, float farAttenuationEnd) |
void | setupDirectional (const NLMISC::CRGBA &ambiant, const NLMISC::CRGBA &diffuse, const NLMISC::CRGBA &specular, const NLMISC::CVector &direction, float constant=1, float linear=0, float quadratic=0) |
Quick setup a directional light. | |
void | setupPointLight (const NLMISC::CRGBA &ambiant, const NLMISC::CRGBA &diffuse, const NLMISC::CRGBA &specular, const NLMISC::CVector &position, const NLMISC::CVector &direction, float constant=1, float linear=0, float quadratic=0) |
Quick setup a point light. | |
void | setupSpotExponent (float hotSpotAngle) |
void | setupSpotLight (const NLMISC::CRGBA &ambiant, const NLMISC::CRGBA &diffuse, const NLMISC::CRGBA &specular, const NLMISC::CVector &position, const NLMISC::CVector &direction, float exponent, float cutoff, float constant=1, float linear=0, float quadratic=0) |
Quick setup a spotlight. | |
Private Attributes | |
NLMISC::CRGBA | _Ambiant |
float | _ConstantAttenuation |
float | _Cutoff |
NLMISC::CRGBA | _Diffuse |
NLMISC::CVector | _Direction |
float | _Exponent |
float | _LinearAttenuation |
TLightMode | _Mode |
NLMISC::CVector | _Position |
float | _QuadraticAttenuation |
NLMISC::CRGBA | _Specular |
|
Definition at line 59 of file light.h. Referenced by getMode().
00060 { 00061 // The light is directional. 00062 DirectionalLight, 00063 00064 // The light is a point. 00065 PointLight, 00066 00067 // The light is a spotlight with a cone. 00068 SpotLight 00069 }; |
|
Get the ambiant color of the light. Definition at line 232 of file light.h. References _Ambiant. Referenced by NL3D::CRenderTrav::beginVPLightSetup(), NL3D::CLightUser::getAmbiant(), and NL3D::CDriverGL::setLight().
00233 { 00234 return _Ambiant; 00235 } |
|
Get constant attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 292 of file light.h. References _ConstantAttenuation. Referenced by NL3D::CPointLight::computeAttenuationFactors(), NL3D::CLightUser::getConstantAttenuation(), and NL3D::CDriverGL::setLight().
00293 { 00294 return _ConstantAttenuation; 00295 } |
|
Get the cutoff of the light in radian. Should be between [0, Pi/2]. Used only for SpotLight. Definition at line 280 of file light.h. References _Cutoff. Referenced by NL3D::CLightUser::getCutoff(), and NL3D::CDriverGL::setLight().
00281 { 00282 return _Cutoff; 00283 } |
|
Get the diffuse color of the light. Definition at line 240 of file light.h. Referenced by NL3D::CRenderTrav::beginVPLightSetup(), NL3D::CLightUser::getDiffuse(), and NL3D::CDriverGL::setLight().
00241 { 00242 return _Diffuse; 00243 } |
|
Get the direction of the light. Used only for DirectionalLight and SpotLight. Definition at line 264 of file light.h. References _Direction. Referenced by NL3D::CMeshVPPerPixelLight::begin(), NL3D::CLightUser::getDirection(), and NL3D::CDriverGL::setLight().
00265 { 00266 return _Direction; 00267 } |
|
Get the exponent of the light. Used only for SpotLight. Definition at line 272 of file light.h. References _Exponent. Referenced by NL3D::CLightUser::getExponent(), and NL3D::CDriverGL::setLight().
00273 { 00274 return _Exponent; 00275 } |
|
Get linear attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 304 of file light.h. References _LinearAttenuation. Referenced by NL3D::CPointLight::computeAttenuationFactors(), NL3D::CLightUser::getLinearAttenuation(), and NL3D::CDriverGL::setLight().
00305 { 00306 return _LinearAttenuation; 00307 } |
|
Get the light mode. Definition at line 224 of file light.h. References _Mode, and TLightMode. Referenced by NL3D::CMeshVPPerPixelLight::begin(), NL3D::CLightUser::getMode(), and NL3D::CDriverGL::setLight().
00225 { 00226 return _Mode; 00227 } |
|
Get the position of the light. Used only for SpotLight and PointLight. Definition at line 256 of file light.h. References _Position. Referenced by NL3D::CMeshVPPerPixelLight::begin(), NL3D::CRenderTrav::beginVPLightSetup(), NL3D::CLightUser::getPosition(), and NL3D::CDriverGL::setLight().
00257 { 00258 return _Position; 00259 } |
|
Get quadratic attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 316 of file light.h. References _QuadraticAttenuation. Referenced by NL3D::CPointLight::computeAttenuationFactors(), NL3D::CLightUser::getQuadraticAttenuation(), and NL3D::CDriverGL::setLight().
00317 { 00318 return _QuadraticAttenuation; 00319 } |
|
Get the specular color of the light. Definition at line 248 of file light.h. Referenced by NL3D::CRenderTrav::beginVPLightSetup(), NL3D::CLightUser::getSpecular(), and NL3D::CDriverGL::setLight().
00249 { 00250 return _Specular; 00251 } |
|
Set the ambiant color of the light. Definition at line 127 of file light.h. References _Ambiant. Referenced by NL3D::CLightUser::setAmbiant(), setupDirectional(), setupPointLight(), and setupSpotLight().
00128 { 00129 _Ambiant=ambiant; 00130 } |
|
Set constant attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 187 of file light.h. References _ConstantAttenuation. Referenced by NL3D::CLightUser::setConstantAttenuation(), setupDirectional(), setupPointLight(), and setupSpotLight().
00188 { 00189 _ConstantAttenuation=constant; 00190 } |
|
Set the cutoff of the light in radian. Should be between [0, Pi/2]. Used only for SpotLight. Definition at line 175 of file light.h. References _Cutoff. Referenced by NL3D::CLightUser::setCutoff(), and setupSpotLight().
00176 { 00177 _Cutoff=cutoff; 00178 } |
|
Set the diffuse color of the light. Definition at line 135 of file light.h. Referenced by NL3D::CLightUser::setDiffuse(), setupDirectional(), setupPointLight(), and setupSpotLight().
00136 { 00137 _Diffuse=diffuse; 00138 } |
|
Set the direction of the light. Used only for DirectionalLight and SpotLight. Definition at line 159 of file light.h. References _Direction. Referenced by NL3D::CLightUser::setDirection(), setupDirectional(), setupPointLight(), and setupSpotLight().
00160 { 00161 _Direction=direction; 00162 } |
|
Set the Intensity distribution of the light. Should be between [0, 1]. Used only for SpotLight. Definition at line 167 of file light.h. References _Exponent. Referenced by NL3D::CLightUser::setExponent(), setupSpotExponent(), and setupSpotLight().
00168 { 00169 _Exponent=exponent; 00170 } |
|
Set linear attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 199 of file light.h. References _LinearAttenuation. Referenced by NL3D::CLightUser::setLinearAttenuation(), setupDirectional(), setupPointLight(), and setupSpotLight().
00200 { 00201 _LinearAttenuation=linear; 00202 } |
|
Set the light mode. Definition at line 119 of file light.h. References _Mode. Referenced by NL3D::CLightUser::setMode(), setupDirectional(), setupPointLight(), and setupSpotLight().
00120 { 00121 _Mode=mode; 00122 } |
|
Set no attenuation. The light will not use attenuation. Definition at line 160 of file light.cpp. References _ConstantAttenuation, _LinearAttenuation, and _QuadraticAttenuation. Referenced by NL3D::CLightUser::setNoAttenuation().
00161 { 00162 _ConstantAttenuation=1.f; 00163 _QuadraticAttenuation=0.f; 00164 _LinearAttenuation=0.f; 00165 } |
|
Set the position of the light. Used only for SpotLight and PointLight. Definition at line 151 of file light.h. References _Position. Referenced by NL3D::CLightUser::setPosition(), setupPointLight(), and setupSpotLight().
00152 { 00153 _Position=position; 00154 } |
|
Set quadratic attenuation. The intensity of the light is attenuated this way: light_intensity = light_intensity / ( CONSTANT_ATTENUATION + vertex_light_distance * LINEAR_ATTENUATION + vertex_light_distance * vertex_light_distance * QUADRATIC_ATTENUATION ); Definition at line 211 of file light.h. References _QuadraticAttenuation. Referenced by NL3D::CLightUser::setQuadraticAttenuation(), setupDirectional(), setupPointLight(), and setupSpotLight().
00212 { 00213 _QuadraticAttenuation=quadratic; 00214 } |
|
Set the specular color of the light. Definition at line 143 of file light.h. Referenced by NL3D::CLightUser::setSpecular(), setupDirectional(), setupPointLight(), and setupSpotLight().
00144 { 00145 _Specular=specular; 00146 } |
|
Setup attenuation with begin and end attenuation distance.
Definition at line 109 of file light.cpp. References _ConstantAttenuation, _LinearAttenuation, and _QuadraticAttenuation. Referenced by NL3D::CPointLight::computeAttenuationFactors(), and NL3D::CLightUser::setupAttenuation().
00110 { 00111 _ConstantAttenuation=1.f; 00112 _QuadraticAttenuation=(float)(0.1/(0.9*farAttenuationBegin*farAttenuationBegin)); 00113 _LinearAttenuation=(float)(0.1/(0.9*farAttenuationBegin)); 00114 00115 // blend factor 00116 float factor = (0.1f*_LinearAttenuation*farAttenuationEnd-0.1f*_QuadraticAttenuation*farAttenuationEnd*farAttenuationEnd); 00117 00118 if (factor == 0.0f) 00119 factor = 0.0001f; 00120 factor = (0.9f-0.1f*_QuadraticAttenuation*farAttenuationEnd*farAttenuationEnd)/factor; 00121 00122 if ((factor<0.f)||(factor>1.f)) 00123 { 00124 // Better factor 00125 float d0_1Lin=1.f / ( _ConstantAttenuation + _LinearAttenuation*farAttenuationEnd ); 00126 float d0_1Quad=1.f / ( _ConstantAttenuation + _QuadraticAttenuation*farAttenuationEnd*farAttenuationEnd ); 00127 00128 // Better 00129 if (fabs (d0_1Lin-0.1f)<fabs (d0_1Quad-0.1f)) 00130 _QuadraticAttenuation=0.f; 00131 else 00132 _LinearAttenuation=0.f; 00133 } 00134 else 00135 { 00136 _LinearAttenuation*=factor; 00137 _QuadraticAttenuation*=(1.f-factor); 00138 } 00139 00140 #ifdef NL_DEBUG 00141 // Should be near previous result 00142 float d1_0=1.f / ( _ConstantAttenuation + _LinearAttenuation*0.f + _QuadraticAttenuation*0.f*0.f ); 00143 float d0_9=1.f / ( _ConstantAttenuation + _LinearAttenuation*farAttenuationBegin + _QuadraticAttenuation*farAttenuationBegin*farAttenuationBegin ); 00144 float d0_1=1.f / ( _ConstantAttenuation + _LinearAttenuation*farAttenuationEnd + _QuadraticAttenuation*farAttenuationEnd*farAttenuationEnd ); 00145 #endif // NL_DEBUG*/ 00146 } |
|
Quick setup a directional light.
Definition at line 37 of file light.cpp. References DirectionalLight, setAmbiant(), setConstantAttenuation(), setDiffuse(), setDirection(), setLinearAttenuation(), setMode(), setQuadraticAttenuation(), and setSpecular(). Referenced by NL3D::CRenderTrav::changeLightSetup(), NL3D::CRenderTrav::resetLightSetup(), and NL3D::CLightUser::setupDirectional().
00039 { 00040 // Set the mode 00041 setMode (DirectionalLight); 00042 00043 // Set the colors 00044 setAmbiant (ambiant); 00045 setDiffuse (diffuse); 00046 setSpecular (specular); 00047 00048 // Set the direction 00049 setDirection (direction); 00050 00051 // Set attenuation 00052 setConstantAttenuation (constant); 00053 setLinearAttenuation (linear); 00054 setQuadraticAttenuation (quadratic); 00055 } |
|
Quick setup a point light.
Definition at line 59 of file light.cpp. References setAmbiant(), setConstantAttenuation(), setDiffuse(), setDirection(), setLinearAttenuation(), setMode(), setPosition(), setQuadraticAttenuation(), and setSpecular(). Referenced by NL3D::CPointLight::setupDriverLight(), NL3D::CPointLight::setupDriverLightUserAttenuation(), and NL3D::CLightUser::setupPointLight().
00061 { 00062 // Set the mode 00063 setMode (PointLight); 00064 00065 // Set the colors 00066 setAmbiant (ambiant); 00067 setDiffuse (diffuse); 00068 setSpecular (specular); 00069 00070 // Set the position and direction 00071 setPosition (position); 00072 setDirection (direction); 00073 00074 // Set attenuation 00075 setConstantAttenuation (constant); 00076 setLinearAttenuation (linear); 00077 setQuadraticAttenuation (quadratic); 00078 } |
|
Setup spot exponent with angle of the hotspot.
Definition at line 150 of file light.cpp. References setExponent(). Referenced by NL3D::CLightUser::setupSpotExponent().
00151 { 00152 float divid=(float)log (cos (hotSpotAngle)); 00153 if (divid==0.f) 00154 divid=0.0001f; 00155 setExponent ((float)(log (0.9)/divid)); 00156 } |
|
Quick setup a spotlight.
Definition at line 82 of file light.cpp. References setAmbiant(), setConstantAttenuation(), setCutoff(), setDiffuse(), setDirection(), setExponent(), setLinearAttenuation(), setMode(), setPosition(), setQuadraticAttenuation(), setSpecular(), and SpotLight. Referenced by NL3D::CPointLight::setupDriverLight(), and NL3D::CLightUser::setupSpotLight().
00084 { 00085 // Set the mode 00086 setMode (SpotLight); 00087 00088 // Set the colors 00089 setAmbiant (ambiant); 00090 setDiffuse (diffuse); 00091 setSpecular (specular); 00092 00093 // Set the position and direction 00094 setPosition (position); 00095 setDirection (direction); 00096 00097 // Set spotlight parameters 00098 setExponent (exponent); 00099 setCutoff (cutoff); 00100 00101 // Set attenuation 00102 setConstantAttenuation (constant); 00103 setLinearAttenuation (linear); 00104 setQuadraticAttenuation (quadratic); 00105 } |
|
Definition at line 327 of file light.h. Referenced by getAmbiant(), and setAmbiant(). |
|
Definition at line 340 of file light.h. Referenced by getConstantAttenuation(), setConstantAttenuation(), setNoAttenuation(), and setupAttenuation(). |
|
Definition at line 337 of file light.h. Referenced by getCutoff(), and setCutoff(). |
|
|
|
Definition at line 333 of file light.h. Referenced by getDirection(), and setDirection(). |
|
Definition at line 336 of file light.h. Referenced by getExponent(), and setExponent(). |
|
Definition at line 341 of file light.h. Referenced by getLinearAttenuation(), setLinearAttenuation(), setNoAttenuation(), and setupAttenuation(). |
|
|
|
Definition at line 332 of file light.h. Referenced by getPosition(), and setPosition(). |
|
Definition at line 342 of file light.h. Referenced by getQuadraticAttenuation(), setNoAttenuation(), setQuadraticAttenuation(), and setupAttenuation(). |
|
|