DeferredRenderer 1.0
|
00001 #include "ShadowSpot.h" 00002 #include "ngl/ShaderManager.h" 00003 #include "ngl/VBOPrimitives.h" 00004 #include "NGLMath.h" 00005 #include "ngl/Matrix.h" 00006 #include "ngl/Util.h" 00007 00008 ShadowSpot::ShadowSpot(const ngl::Vector &_position, 00009 const ngl::Vector &_target, 00010 const float &_distance, 00011 const float &_angle, 00012 const ngl::Vector &_col, 00013 const ngl::Vector &_up) 00014 { 00015 //m_shadowMapId = 0; 00016 this->set(_position,_target,_distance,_angle,_col,_up); 00017 m_shadowView = m_matrixCam.getModelView();//Lookat(_position, _target, _up, true); 00018 m_angle = _angle; 00019 00020 generateProjMatrices(); 00021 } 00022 00023 00025 void ShadowSpot::generateProjMatrices() 00026 { 00027 float aspectRatio = float(1024/768); 00028 00029 float near = 0.1; 00030 float far = 300.0; 00031 00032 // note 1/tan == cotangent 00033 float f= 1.0/tan(ngl::radians(m_angle)/2.0); 00034 00035 m_proj.identity(); 00036 00037 m_proj.m_m[0][0]=f/aspectRatio; 00038 m_proj.m_m[1][1]=f; 00039 00040 m_proj.m_m[2][2]=(far+near)/(near-far); 00041 m_proj.m_m[3][2]=(2*far*near)/(near-far); 00042 00043 m_proj.m_m[2][3]=-1; 00044 00045 m_projView = m_proj * m_lightView; 00046 m_frustum.generate(m_projView); 00047 }