DGLE_RESULT DGLE_API CFixedFunctionPipeline::GetSpotLightConfiguration(uint uiIdx, TPoint3 &stPosition, TVector3 &stDirection, float &fRange, float &fSpotAngle) { E_LIGHT_TYPE type; GetLightType(uiIdx, type); if (uiIdx >= (uint)_iMaxLights || type != LT_SPOT) return E_INVALIDARG; GLfloat pos[4]; glGetLightfv(GL_LIGHT0 + uiIdx, GL_POSITION, pos); glGetLightfv(GL_LIGHT0 + uiIdx, GL_SPOT_DIRECTION, stDirection); // May work wrong when light position was set or changed directly via OpenGL outside this class. const TMatrix4x4 inv_mview = MatrixInverse(_pLights[uiIdx].mview); stPosition = inv_mview.ApplyToPoint(TPoint3(pos[0], pos[1], pos[2])); stDirection = inv_mview.ApplyToVector(stDirection); glGetLightfv(GL_LIGHT0 + uiIdx, GL_SPOT_CUTOFF, &fSpotAngle); fSpotAngle *= 2.f; glGetLightfv(GL_LIGHT0 + uiIdx, GL_LINEAR_ATTENUATION, &fRange); fRange = _c_fAttenuationFactor / fRange; return S_OK; }
LightSquare::LightSquare() { LightDot::LightDot(); lightKind = LIGHT_SQUARE; dir = TVector3( 0, -1, 0 ); location = TPoint3( 0, 500, 0 ); axis1 = TVector3( 1, 0, 0 ); axis2 = TVector3( 0, 0, 1 ); dotGrid = NULL; }
DGLE_RESULT DGLE_API CFixedFunctionPipeline::GetPointLightConfiguration(uint uiIdx, TPoint3 &stPosition, float &fRange) { E_LIGHT_TYPE type; GetLightType(uiIdx, type); if (uiIdx >= (uint)_iMaxLights || type != LT_POINT) return E_INVALIDARG; GLfloat pos[4]; glGetLightfv(GL_LIGHT0 + uiIdx, GL_POSITION, pos); // May work wrong when light position was set or changed directly via OpenGL outside this class. stPosition = MatrixInverse(_pLights[uiIdx].mview).ApplyToPoint(TPoint3(pos[0], pos[1], pos[2])); glGetLightfv(GL_LIGHT0 + uiIdx, GL_LINEAR_ATTENUATION, &fRange); fRange = _c_fAttenuationFactor / fRange; return S_OK; }
CLight::CLight(uint uiInstIdx): CInstancedObj(uiInstIdx), _bEnabled(true), _eType(LT_DIRECTIONAL), _stMainCol(ColorWhite()), _stPos(TPoint3()), _stDir(TVector3(0.f, 0.f, 1.f)), _fRange(100.f), _fIntensity(1.f), _fAngle(90.f) {}