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;
}
Exemple #2
0
DGLE_RESULT DGLE_API CMesh::TransformVertices(const TMatrix4x4 &stTransMatrix)
{
	if (!_pBuffer)
		return S_FALSE;

	TDrawDataDesc desc;
	uint stride, verts_data_size, verts_count, idxs_data_size, idxs_count;
	_CopyMeshData(desc, stride, verts_data_size, verts_count, idxs_data_size, idxs_count);

	for (uint i = 0; i < verts_count; ++i)
	{
		TPoint3 *p = reinterpret_cast<TPoint3 *>(&desc.pData[stride * i]);
		*p = stTransMatrix.ApplyToPoint(*p);
	}

	PARANOIC_CHECK_RES(_pBuffer->Reallocate(desc, verts_count, idxs_count, CRDM_TRIANGLES));

	delete[] desc.pData;

	return S_OK;
}