当前位置: 首页>>代码示例>>C++>>正文


C++ CLight::IsEnable方法代码示例

本文整理汇总了C++中CLight::IsEnable方法的典型用法代码示例。如果您正苦于以下问题:C++ CLight::IsEnable方法的具体用法?C++ CLight::IsEnable怎么用?C++ CLight::IsEnable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CLight的用法示例。


在下文中一共展示了CLight::IsEnable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ProcessLighting

void CRenderObjectsManager::ProcessLighting(CRenderObject* pobj,POLYGON& poly)
{
	VERTICESLIST &pointlist = pobj->m_translateverticesList;
	int v_index1 = poly.v[0];
	int v_index2 = poly.v[1];
	int v_index3 = poly.v[2];
	
	//Get the original r,g,b,a
	bool bHasTexture = poly.state & OBJECT_HAS_TEXTURE;
	UCHAR r_base = bHasTexture ?255:poly.color.r;
	UCHAR g_base = bHasTexture ? 255:poly.color.g;
	UCHAR b_base = bHasTexture?255: poly.color.b;
	UCHAR a_base = bHasTexture?0:poly.color.a;//to do.modify here

	int r_sum=0,g_sum = 0,b_sum = 0;

	int ilightsize = m_pLightingManager->GetLightsCount();
	const LIGHTSLIST& lightslist = m_pLightingManager->GetLights();
	CLight *light = NULL;

	//Get the normal direction
	Vector4D P0P1 = pointlist[v_index2].vertex - pointlist[v_index1].vertex;
	Vector4D P1P2 = pointlist[v_index3].vertex - pointlist[v_index1].vertex;
	Vector4D N = P0P1.CrossProduct(P1P2);
	N.Normalize();

	for(int i = 0; i < ilightsize;++i)
	{
		light = lightslist[i];
		if(!light->IsEnable()) continue;
		
		//Get the cos value of the angle between the light and normal
        Vector4D lightdir = light->m_lightdir;
		float coslight2normal = N.DotProduct(-1*lightdir);

		const CLight::LightType lighttype = light->GetLightType();

		if(lighttype == CLight::kAmbientLight)
		{
             r_sum += ((light->m_amblient.r * r_base)/256);
			 g_sum += ((light->m_amblient.g * g_base)/256);
			 b_sum += ((light->m_amblient.b * b_base)/256);
		}
		if(lighttype == CLight::kInfiniteLigtht)
		{
			if(coslight2normal>0)
			{
				r_sum += ((light->m_diffuse.r * r_base *coslight2normal)/256);
				g_sum += ((light->m_diffuse.g * g_base*coslight2normal)/256);
				b_sum += ((light->m_diffuse.b * b_base*coslight2normal)/256);
			}
		
		}
		if(lighttype == CLight::kPointLight)
		{
			// c = c_diffuse * I/(kc+kl*d+kq*d^2);
			//
			Vector4D vertex2lightpos = Vector4D(light->m_lightpos- pointlist[v_index1].vertex);
			float d = vertex2lightpos.GetLength();
			float l = vertex2lightpos.DotProduct(N);
			float cosv = N.DotProduct(vertex2lightpos);
			if(cosv >0)
			{
                cosv = cosv/d;
				float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d;
				float fDiv = k*256;//k*256
				r_sum += ((light->m_diffuse.r * r_base *cosv)/fDiv);
				g_sum += ((light->m_diffuse.g * g_base*cosv)/fDiv);
				b_sum += ((light->m_diffuse.b * b_base*cosv)/fDiv);
				

			}
		
		}
		if(lighttype == CLight::kSpotLight)
		{
           //use this model
		   // c = c_diffuse * I*MAX(COSa,0)^pf/(kc+kl*d+kq*d^2)
			float l = N.DotProduct(-1*lightdir);
			if(l >0)
			{
				Vector4D vertex2lightpos = Vector4D(light->m_lightpos-pointlist[v_index1].vertex );
				float d = vertex2lightpos.GetLength();

				//calculate the cos value of light direction and vertext->lightpos

				float l = N.DotProduct(vertex2lightpos);
				if(l > 0)
				{
					float cosv = l/d;
					float dl = cosv;
					for(int i = 1; i < light->m_pf;++i)
						dl *= cosv;

					float k = light->m_kconst + light->m_klinear * d + light->m_kquadratic*d*d;
					float fDiv = k*256;//k*256

					r_sum += ((light->m_diffuse.r * r_base *dl)/fDiv);
					g_sum += ((light->m_diffuse.g * g_base*dl)/fDiv);
					b_sum += ((light->m_diffuse.b * b_base*dl)/fDiv);
//.........这里部分代码省略.........
开发者ID:orbv,项目名称:Simple-3D-Software-Render,代码行数:101,代码来源:Projection.cpp


注:本文中的CLight::IsEnable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。