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


C++ Vector4::Multiply方法代码示例

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


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

示例1: CalculateFlatLightingDirectional

void Mesh::CalculateFlatLightingDirectional(const LightDirectional &light, int numLights, const Vector4& cameraPos, const Matrix4& view)
{
	Maths::Vector4 total, temp;
	Maths::Vector4 reflect;
	Maths::Vector4 v = cameraPos;
	Maths::Vector4 l( light.Position.X, light.Position.Y, light.Position.Z, 1.0f  ); 
	Maths::Vector4 n( 0, 0, 0 );
	Maths::Vector4 t, halfWay;
	BYTE r, g, b;
	float spec = 0;
	float diff = 0;
	float ave = 0;

	m_noLight = false;

	//workout the "halfway" vector for specularity
	ave = v.Length();
	//halfWay = ( v + l ) / ave;
	//halfWay.Normalize();

	//normalize the light position
	l.Normalize();

	for ( int i = 0; i < m_numPolys; ++i )
	{
		if ( !m_polys[i].IsCulled )
		{
			//reset the colout to black
			total.X = 0; //Red
			total.Y = 0; //green
			total.Z = 0; //blue

			for ( int j = 0; j < numLights; ++j )
			{
				//store intensity to corresponding variables
				//modulate intensity with coresponding reflectance co-efficient values
				temp.X = light.Colour.GetR() * light.Intensity.X;
				temp.Y = light.Colour.GetG() * light.Intensity.Y;
				temp.Z = light.Colour.GetB() * light.Intensity.Z;

				//reflect = ( 2 * ( m_polys[i]._normal.DotProduct( light._position ) ) * ( m_polys[i]._normal - light );
				n.SetValues( m_polys[i].Normal.X, m_polys[i].Normal.Y, m_polys[i].Normal.Z, 1.0f );
				n.Normalize();

				//attentuate the rgb values with lambertian attenuation
				diff = max( 0.0f, l.DotProduct( n ) );

				//calculate specular coponent
				Vector4 toEye;
				Matrix4::Transform( view, m_transformed[ m_polys[i].Indices[0] ].Position, toEye );
				toEye.Normalize();

				float r = max( 0, m_transformed[ m_polys[i].Indices[0] ].Normal.DotProduct( l ) );
				Vector4 reflect = m_transformed[ m_polys[i].Indices[0] ].Normal;
				reflect.Multiply( 2 * r );
				reflect.Subtract( l );
			
				//Vector4 toEye = m_transformed[ m_polys[i]._indices[0] ]._position - viewer;
				//Vector4 reflect = ( n - l ) * ( 2 * ( n.DotProduct( l ) ) );
				toEye.Normalize();
				reflect.Normalize();
				float specPower = 1.0f;
				float spec = 0; //max( 0, pow( max( 0.0f, reflect.DotProduct( toEye ) ), specPower ) ) * m_specular;

				if ( diff <= 0.0f )
					spec = 0.0f;

				temp.X =  temp.X * ( (diff + spec) * m_kd_red );
				temp.Y =  temp.Y * ( (diff + spec) * m_kd_green );
				temp.Z =  temp.Z * ( (diff + spec) * m_kd_blue );

				total = total + temp;
			}

			//clamp the values
			if (total.X > 255) total.X = 255;
			if (total.Y > 255) total.Y = 255;
			if (total.Z > 255) total.Z = 255;
			if (total.X < 0) total.X = 0;
			if (total.Y < 0) total.Y = 0;
			if (total.Z < 0) total.Z = 0;

			r = (BYTE)total.X;
			g = (BYTE)total.Y;
			b = (BYTE)total.Z;

			m_polys[i].Colour = Gdiplus::Color::MakeARGB(255, r, g, b);
		}
	}
}
开发者ID:ookumaneko,项目名称:Software-Renderer,代码行数:90,代码来源:Mesh.cpp


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