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


C++ Vector4类代码示例

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


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

示例1: GetRotate

Matrix4 Matrix4::GetRotate(const Vector4& from, const Vector4& to) {
	Vector4 axis = from.Cross(to);
	axis.Normalize();
	float degrees = from.GetAngleBetween(to);
	return GetRotate(degrees, axis);
}
开发者ID:forstezt,项目名称:CS455,代码行数:6,代码来源:Matrix4.cpp

示例2: findNormalToTriangle

Vector4* findNormalToTriangle(double xS, double yS, double zS, Triangle& triangle){

	double x0 = triangle.v[0].position[0];
	double y0 = triangle.v[0].position[1];
	double z0 = triangle.v[0].position[2];

	double x1 = triangle.v[1].position[0];
	double y1 = triangle.v[1].position[1];
	double z1 = triangle.v[1].position[2];

	double x2 = triangle.v[2].position[0];
	double y2 = triangle.v[2].position[1];
	double z2 = triangle.v[2].position[2];

	//Calculate the vertices of the triangle.
	auto_ptr<Vector4> P0(new Vector4());
	P0->SetVector4(x0,y0,z0,1.0f);
	auto_ptr<Vector4> P1(new Vector4());
	P1->SetVector4((float)x1,(float)y1,(float)z1,1.0f);
	auto_ptr<Vector4> P2(new Vector4());
	P2->SetVector4((float)x2,(float)y2,(float)z2,1.0f);
	auto_ptr<Vector4> P(new Vector4());
	P->SetVector4((float)xS,(float)yS,(float)zS,1.0f);


	//Vector from one vertex to other vertex.
	auto_ptr<Vector4> Edge01(P0->Subtract(*P1, *P0));
	auto_ptr<Vector4> Edge12(P1->Subtract(*P2, *P1));
	auto_ptr<Vector4> Edge20(P2->Subtract(*P0, *P2));

	//Area of the complete triangle.
	double area_P0P1P2 = (0.5*Edge01->CrossProduct(*Edge01, *Edge20)->GetMagnitude());
	assert(area_P0P1P2 > 0);

	//Area of PP0P2
	auto_ptr<Vector4> EdgePP2(new Vector4());
	EdgePP2->SetVector4(xS-x2, yS-y2, zS-z2,1);
	double area_PP0P2 = (0.5*Edge20->CrossProduct(*Edge20, *EdgePP2)->GetMagnitude());
	assert(area_PP0P2 >= 0.0);

	//Area of PP1P2
	double area_PP1P2 = (0.5 * EdgePP2->CrossProduct(*EdgePP2, *Edge12)->GetMagnitude());
	assert(area_PP1P2 >= 0);

	//Area of PP0P1
	auto_ptr<Vector4> EdgePP0(new Vector4());
	EdgePP0->SetVector4(xS-x0, yS-y0, zS-z0,1);
	double area_PP0P1 = (0.5*Edge01->CrossProduct(*Edge01, *EdgePP0)->GetMagnitude());

	assert(area_PP0P1 >= 0);//I am here

	double alpha = area_PP1P2/area_P0P1P2;
	double beta = area_PP0P2/area_P0P1P2;
	double gamma = area_PP0P1/area_P0P1P2;


	double n0_x = triangle.v[0].normal[0];
	double n0_y = triangle.v[0].normal[1];
	double n0_z = triangle.v[0].normal[2];
	auto_ptr<Vector4> N0(new Vector4());
	N0->SetVector4(n0_x, n0_y, n0_z, 1);

	double n1_x = triangle.v[1].normal[0];
	double n1_y = triangle.v[1].normal[1];
	double n1_z = triangle.v[1].normal[2];
	auto_ptr<Vector4> N1(new Vector4());
	N1->SetVector4(n1_x, n1_y, n1_z, 1);

	double n2_x = triangle.v[2].normal[0];
	double n2_y = triangle.v[2].normal[1];
	double n2_z = triangle.v[2].normal[2];
	auto_ptr<Vector4> N2(new Vector4());
	N2->SetVector4(n2_x, n2_y, n2_z, 1);

	N0->Elongate(alpha);
	N1->Elongate(beta);
	N2->Elongate(gamma);

	Vector4* normalTemp = N0->Add(*N0, *N1);
	Vector4* normal = N0->Add(*normalTemp, *N2);

	delete normalTemp;
	normal->ConvertToUnit();
	return normal;
}
开发者ID:dapurv5,项目名称:csl307-assignments,代码行数:85,代码来源:geometryKernel.cpp

示例3:

		Vector4 Vector4::Normalize(const Vector4& argVec)
		{
			return argVec / argVec.Magnitude();
		};
开发者ID:embooglement,项目名称:Protium,代码行数:4,代码来源:Vector.cpp

示例4: D3DXMatrixScaling

	void GraphicalPlane::Render(const Camera* camera) 
	{
		// 描画しないならここで関数終了
		if(!_renders)
			return;
		// 分割読み込みした場合の画像範囲選択
		if(_previousNumber != _number)
		{
			Vertex* vertex;
			_mesh->GetMesh()->LockVertexBuffer( 0, (void**)&vertex );
			vertex[0]._uv.x = (float)_rects[_number].left		/	_textures[0]->GetImageInfo().Width;
			vertex[0]._uv.y = (float)_rects[_number].bottom	/	_textures[0]->GetImageInfo().Height;
			vertex[1]._uv.x = (float)_rects[_number].right	/	_textures[0]->GetImageInfo().Width;
			vertex[1]._uv.y = (float)_rects[_number].bottom	/	_textures[0]->GetImageInfo().Height;
			vertex[2]._uv.x = (float)_rects[_number].left		/	_textures[0]->GetImageInfo().Width;
			vertex[2]._uv.y = (float)_rects[_number].top		/	_textures[0]->GetImageInfo().Height;
			vertex[3]._uv.x = (float)_rects[_number].right	/	_textures[0]->GetImageInfo().Width;
			vertex[3]._uv.y = (float)_rects[_number].top		/	_textures[0]->GetImageInfo().Height;
			_mesh->GetMesh()->UnlockIndexBuffer();
			_previousNumber = _number;
		}
		// ワールド行列設定
		Matrix SclMtx, RotMtx, PosMtx, WldMtx, WVPMtx;
		// 拡縮
		D3DXMatrixScaling(&SclMtx, _scale.x, _scale.y, _scale.z);
		// 回転
		// クォータニオンか回転行列かXYZ指定か
		this->Evaluate();
		RotMtx = _worldRotationMatrix;
		// ビルボードの場合
		if(_isBillBoard)
		{
			Vector3 cameraPosition = camera->GetEye() ;
			GetBillBoardRotation(&_position, &cameraPosition, &RotMtx);
		}
		// 位置
		D3DXMatrixTranslation(&PosMtx, _position.x, _position.y, _position.z);
		// カリングを設定
		GraphicsManager::_device->SetRenderState(D3DRS_CULLMODE, _cullingState);
		// デバッグ用
		//GraphicsManager::_device->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
		// シェーダを使用する場合カメラのビュー行列(0)、プロジェクション行列(1)をワールド行列に合成
		WldMtx = SclMtx * RotMtx * PosMtx;
		WVPMtx = WldMtx * camera->GetMatrix(ViewBehavior::VIEW) * camera->GetMatrix(ViewBehavior::PROJECTION);
		// カメラの座標をシェーダに使用するための行列変換
		Matrix CamMtx = WldMtx * camera->GetMatrix(ViewBehavior::VIEW);
		D3DXMatrixInverse(&CamMtx, NULL, &CamMtx);
		Vector4 EyePos = Vector4(
			camera->GetEye().x, 
			camera->GetEye().y, 
			camera->GetEye().z, 
			1
			);
		EyePos.Transform(CamMtx);
		D3DXVec4Normalize((D3DXVECTOR4*)&EyePos, (D3DXVECTOR4*)&EyePos);
		// シェーダ設定
		_shader->SetTechnique();
		// シェーダにワールド * ビュー * プロジェクション行列を渡す
		_shader->SetWVPMatrix(WVPMtx);
		// シェーダー特有の値の設定
		_shader->ApplyEffect(RotMtx, EyePos);

		HRESULT hr;
		// 3D モデルのパーツ分ループして描画
		for(size_t i = 0 ; i < _mesh->GetMaterialNumber(); i++)
		{
			// テクスチャが存在しない場合のカラー
			D3DXVECTOR4 vec4 = D3DXVECTOR4(1.0,1.0,1.0,1.0);
			// 格パーツに対応するテクスチャを設定
			// シェーダにテクスチャを渡す
			if(NULL != _textures[i])
			{
				LPDIRECT3DTEXTURE9 texture = _textures[i]->GetTextureData();
				// シェーダにカラーを渡す
				_shader->SetColor(_colorRGBA);
				_shader->SetTexture(texture);
			}else
				_shader->SetColor(vec4);

			// シェーダの使用開始
			_shader->BeginShader();
			// シェーダのパス設定
			_shader->BeginPass(_addsBlend);
			// パーツの描画	
			if(SUCCEEDED(GraphicsManager::_device->BeginScene()))
			{
				_mesh->GetMesh()->DrawSubset(i); 
				V(GraphicsManager::_device->EndScene());
			}
			// パス終了
			_shader->EndPass();
			// シェーダ終了
			_shader->EndShader();
		}
	}
开发者ID:nuponsalt,项目名称:Game001,代码行数:95,代码来源:GraphicalPlane.cpp

示例5: rasterizeTriangle

void Rasterizer::rasterizeTriangle(Vector4 a, Vector4 b, Vector4 c, float c1, float c2, float c3)
{
	float alpha, beta, gamma, denom;

	float x1 = a[0];
	float y1 = a[1];

	float x2 = b[0];
	float y2 = b[1];

	float x3 = c[0];
	float y3 = c[1];

	float top = max(max(y1, y2), y3);
	if (top >= window_height)
		top = window_height - 1;

	float bottom = min(min(y1, y2), y3);
	if (bottom < 0)
		bottom = 0;

	float left = min(min(x1, x2), x3);
	if (left < 0)
		left = 0;

	float right = max(max(x1, x2), x3);
	if (right >= window_width)
		right = window_width - 1;

	for (int row = bottom; row <= top; row++)
	{
		for (int col = left; col <= right; col++)
		{
			Vector3 v0 = Vector3(x3 - x1, y3 - y1, 0);
			Vector3 v1 = Vector3(x2 - x1, y2 - y1, 0);
			Vector3 v2 = Vector3(col - x1, row - y1, 0);

			denom = v0.dot(v0) * v1.dot(v1) - v0.dot(v1) * v1.dot(v0);

			alpha = (v1.dot(v1) * v2.dot(v0) - v1.dot(v0) * v2.dot(v1)) / denom;
			beta = (v0.dot(v0) * v2.dot(v1) - v0.dot(v1) * v2.dot(v0)) / denom;
			gamma = 1 - alpha - beta;

			Vector3 P = a.toVector3() + (c - a).toVector3().scale(alpha) + (b - a).toVector3().scale(beta);
			float z = P[2];

			if (Globals::interp)
			{
				c1 = row / c1;
				c2 = col / c2;
				c3 = z / c3;
			}

			if (alpha > 0 && alpha < 1 && beta > 0 && beta < 1 && gamma > 0 && gamma < 1)
			{
				if (Globals::zbuf)
				{
					update_zbuffer(col, row, c1, c2, c3, z);
				}
				else
					drawPoint(col, row, c1, c2, c3);
			}
		}
	}
}
开发者ID:jordan829,项目名称:GlobalWarming,代码行数:65,代码来源:Rasterizer.cpp

示例6: srand

	// pocitanie funkcie pre vsetky trojuholniky, O(n2)
	void CSDFController::Compute(LinkedList<Face>* triangles, Octree* root)
	{
		float min = FLOAT_MAX;
		float max = 0.0;
		
		unsigned int n_rays = 30;
		float angle = 120.0f;
		unsigned int counter = 0;

		//------------------prealocated variables------------------
		Vector4 tangens, normal, binormal;
		Mat4 t_mat;
		std::vector<float> rays;
		std::vector<float> weights;

		// precompute those N rays
		srand (123);											// initial seed for random number generator
		float* rndy = new float[n_rays];
		float* rndx = new float[n_rays];
		for(unsigned int i = 0; i < n_rays; i++)
		{
			rndy[i] = float(rand()%int(angle / 2));
			rndx[i] = float(rand()%(360));
			if(rndy[i] == 0.0)
				rndy[i] = 0.5;
		}

		float dist = FLOAT_MAX;
		float dist2 = FLOAT_MAX;
		float theta = 0.0f;
		bool intersected = false;

		LinkedList<Face>* face_list = NULL;
		LinkedList<Face>::Cell<Face>* intersected_face = NULL;
		//------------------prealocated variables------------------

		LinkedList<Face>::Cell<Face>* current_face = triangles->start;
		while(current_face != NULL)
		{
			// vypocet TNB vektorov a matice
			ComputeTNB(current_face->data, tangens, normal, binormal);
			t_mat = Mat4(tangens, normal, binormal);

			rays.clear();
			weights.clear();
			for(unsigned int i = 0; i < n_rays; i++)
			{
				Vector4 ray = CalcRayFromAngle(rndx[i], rndy[i]) * t_mat;
				ray.Normalize();

				dist = FLOAT_MAX;
				face_list = GetFaceList(triangles, root, current_face->data->center, ray);
				intersected_face = face_list->start;
				while(intersected_face != NULL)
				{
					if(current_face == intersected_face)
					{
						intersected_face = intersected_face->next;
						continue;
					}

					dist2 = FLOAT_MAX;
					intersected = rayIntersectsTriangle(current_face->data->center, ray, intersected_face->data->v[0]->P, intersected_face->data->v[1]->P, intersected_face->data->v[2]->P, dist2);
					if(intersected == true)
					{
						theta = acos( (ray * intersected_face->data->normal) / (ray.Length() * intersected_face->data->normal.Length()) );
						theta = theta * float(180.0 / M_PI);
						//loggger->logInfo(MarshalString("pridany ray s thetou: " + theta));
						if((theta < 90.0f) && (dist2 < dist))
							dist = dist2;
					}

					intersected_face = intersected_face->next;
				}
				if(dist < (FLOAT_MAX - 1.0f))
				{
					//loggger->logInfo(MarshalString("pridany ray s dlzkou: " + dist));
					rays.push_back(dist);
					weights.push_back(180.0f - rndy[i]);
				}
				//if(root != NULL)
					//delete face_list;						// generated list, bez prealokovania
			}
			if(rays.size() > 0)
			{
				current_face->data->ComputeSDFValue(rays, weights);
				if(current_face->data->diameter->value < min)
					min = current_face->data->diameter->value;
				if(current_face->data->diameter->value > max)
					max = current_face->data->diameter->value;
			}
			counter = counter + 1;
			current_face = current_face->next;
		}
		fc_list->Clear();
		oc_list->Clear();
		delete [] rndy;
		delete [] rndx;

//.........这里部分代码省略.........
开发者ID:zaeraal,项目名称:SDF_Library,代码行数:101,代码来源:SDFController.cpp

示例7: CullPolygons

bool Mesh::CullPolygons(const ViewFrustum& frustum, const Maths::Vector4& camPos)
{
	int cullCount = 0;
	for ( int i = 0; i < m_numPolys; ++i )
	{
		if ( m_polys[i].IsCulled )
		{
			cullCount++;
			continue;
		}

		int count = 0;
		for ( int vv = 0; vv < 3; ++vv )
		{
			//Vector4 point = m_transformed[ m_polys[i].Indices[vv] ].Position - camPos;
			Vector4 point = m_transformed[ m_polys[i].Indices[vv] ].Position - m_verts[ m_polys[i].Indices[vv] ];
			float result = point.DotProduct( frustum.Left.Normal );
			if ( result > 0.0f )
			{
				count++;
				m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
				continue;
			}

			result = point.DotProduct( frustum.Right.Normal );
			if ( result > 0.0f )
			{
				count++;
				m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
				continue;
			}

			result = point.DotProduct( frustum.Top.Normal );
			if ( result > 0.0f )
			{
				count++;
				m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
				continue;
			}

			result = point.DotProduct( frustum.Bottom.Normal );
			if ( result > 0.0f )
			{
				count++;
				m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
				continue;
			}

			//result = point.DotProduct( frustum.Near.Normal );
			//if ( result > 0.0f )
			//{
			//	count++;
			//	m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
			//	continue;
			//}

			//result = point.DotProduct( frustum.Far.Normal );
			//if ( result > 0.0f )
			//{
			//	count++;
			//	m_transformed[ m_polys[i].Indices[vv] ].IsCulled = true;
			//	continue;
			//}
		}

		if ( count == 3 )
		{
			cullCount++;
			m_polys[i].IsCulled = true;
		}
	}

	return ( cullCount == m_numPolys );
}
开发者ID:ookumaneko,项目名称:Software-Renderer,代码行数:74,代码来源:Mesh.cpp

示例8: uniform

void Shader::uniform(const string &nom,const Vector4 &p,int offset) {
  int loc=uniform(nom);
  glUniform4fv(loc+offset,1,p.fv());
}
开发者ID:DherJ,项目名称:Master1,代码行数:4,代码来源:Shader.cpp

示例9: l

void Mesh::CalculateLightingDirectional(const LightDirectional& light, int numLights, const Vector4& camera)
{
	Maths::Vector4 total;
	Maths::Vector4 temp;
	Maths::Vector4 l( light.Position.X, light.Position.Y, light.Position.Z, 1.0f );
	Maths::Vector4 n( 0, 0, 0, 0 );
	BYTE r, g, b;
	float diff, spec = 0;

	m_noLight = false;
	l.Normalize();

	for ( int i = 0; i < m_numVerts; ++i )
	{
		if ( !m_transformed[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 )
			{
				Maths::Vector4 d;
				
				//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;

				n = m_transformed[i].Normal; 
				n.Normalize();

				//attentuate the rgb values with lambertian attenuation
				diff = max(0.0, l.DotProduct( n ));
				
				Vector4 toEye = m_transformed[i].Position - camera;
				Vector4 reflect = ( n - l ) * ( 2 * ( n.DotProduct( l ) ) );
				toEye.Normalize();
				reflect.Normalize();
				float specPower = 1.0f;
				spec = pow( max( reflect.DotProduct( toEye ), 0.0f ), specPower )  * 0.01f;

				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 );

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

			if ( total.X > 255.0f ) total.X = 255.0f;
			if ( total.Y > 255.0f ) total.Y = 255.0f;
			if ( total.Z > 255.0f ) total.Z = 255.0f;
			if ( total.X < 0.0f ) total.X = 0.0f;
			if ( total.Y < 0.0f ) total.Y = 0.0f;
			if ( total.Z < 0.0f ) total.Z = 0.0f;

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

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

示例10: cof

void Mesh::CalculateLightingPoint( const std::vector<LightPoint>& light, int numLight, const Maths::Vector4& camera)
{
	Maths::Vector4 l;
	Maths::Vector4 temp, result, n, p;
	Maths::Vector4 cof( 1.0f, 1.0f, 10.0f );
	BYTE r, g, b;
	float distance = 0;
	float att = 0;
	float a = 0.05f;
	float bb = 0.05f;
	float c = 0.05f;
	float dif, spec;

	m_noLight = false;

	for ( int i = 0; i < m_numVerts; ++i )
	{
		if ( !m_transformed[i].IsCulled )
		{
			result.X = 0; //Red
			result.Y = 0; //green
			result.Z = 0; //blue

			for ( int j = 0; j < numLight; ++j )
			{
				p = light[j].Position;
				l = p - m_transformed[i].Position;
				distance = l.Length();

				//calculate the attenuation value
				att = 1 / (a + ( distance * bb ) + ( distance * distance ) * c );
				if ( att < 0 )
					att = 0;

				temp.X = light[j].Colour.GetR();
				temp.Y = light[j].Colour.GetG();
				temp.Z = light[j].Colour.GetB();
				
				n = m_transformed[i].Normal;
				n.Normalize();

				dif = max( 0.0, l.DotProduct( n ) ) * att;

				// calculate the speculation
				//Vector4 toEye = m_transformed[i].Position - camera;
				//Vector4 half = camera + p / 2;
				//toEye.Normalize();
				//half.Normalize();
				//float specPower = 1.0f;
				//float spec = pow( max( n.DotProduct( half ), 0.0f ), specPower ) * att;
				Vector4 toEye = m_transformed[i].Position - camera;
				Vector4 reflect = ( n - l ) * ( 2 * ( n.DotProduct( l ) ) );
				toEye.Normalize();
				reflect.Normalize();
				float specPower = 1.0f;
				float spec = pow( max( reflect.DotProduct( toEye ), 0.0f ), specPower ) * att;

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

				//temp.X =  temp.X * ( dif * m_kd_red ) );
				//temp.Y =  temp.Y * ( dif * m_kd_green ) );
				//temp.Z =  temp.Z * ( dif * m_kd_blue ) );

				result += temp;
			}

			//set colour
			if ( result.X > 255.0f ) result.X = 255.0f;
			if ( result.Y > 255.0f ) result.Y = 255.0f;
			if ( result.Z > 255.0f ) result.Z = 255.0f;
			if ( result.X < 0.0f ) result.X = 0.0f;
			if ( result.Y < 0.0f ) result.Y = 0.0f;
			if ( result.Z < 0.0f ) result.Z = 0.0f;
			r = (BYTE)result.X;
			g = (BYTE)result.Y;
			b = (BYTE)result.Z;
			m_transformed[i].Colour = Gdiplus::Color::MakeARGB( 255, r, g, b );
		}
	}
}
开发者ID:ookumaneko,项目名称:Software-Renderer,代码行数:82,代码来源:Mesh.cpp

示例11: max

void Mesh::CalculateFlatLightingPoint(const std::vector<LightPoint>& light, int numLights, const Vector4& camera)
{
	Maths::Vector4 l;
	Maths::Vector4 temp, result, n, p;
	BYTE r, g, b;
	float distance = 0;
	float att = 0;
	float a = 0.05f;
	float bb = 0.05f;
	float c = 0.05f;
	float dif, spec;
	m_noLight = false;

	for ( int i = 0; i < m_numPolys; ++i )
	{
		result.X = 0; //Red
		result.Y = 0; //green
		result.Z = 0; //blue

		if ( !m_polys[i].IsCulled )
		{
			for ( int j = 0; j < numLights; ++j )
			{
				//get the position of the light and calculate the 
				//distance between the object and the lifght
				p = light[j].Position;
				l = p - m_transformed[ m_polys[i].Indices[0] ].Position;
				distance = l.Length();

				//calculate the attenuation value
				att = 1 / (a + ( distance * bb ) + ( distance * distance ) * c );
				if ( att < 0)
					att = 0;
				
				temp.X = light[j].Colour.GetR();
				temp.Y = light[j].Colour.GetG();
				temp.Z = light[j].Colour.GetB();
				
				// get the normalized value of the polygon normals
				//n = m_polys[i]._normalN;
				//n.Normalize();

				// calculate the diffuse value
				dif = max( l.DotProduct( m_polys[i].NormalN ), 0.0f ) * att;
				// multiply dif with materials

				// calculate the speculation
				//Vector4 toEye = m_transformed[ m_polys[i]._indices[0] ]._position - camera;
				//Vector4 reflect = ( n - l ) * ( 2 * ( n.DotProduct( l ) ) );
				//toEye.Normalize();
				//reflect.Normalize();
				//float specPower = 1.0f;
				//float spec = pow( max( reflect.DotProduct( toEye ), 0.0f ), specPower ) * att;

				Vector4 toEye = m_transformed[ m_polys[i].Indices[0] ].Position - camera;
				Vector4 half = camera + p / 2;
				toEye.Normalize();
				half.Normalize();
				float specPower = 1.0f;
				float spec = pow( max( n.DotProduct( half ), 0.0f ), specPower ) * att;

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

				result += temp;
			}

			//set colour
			if ( result.X > 255.0f ) result.X = 255;
			if ( result.Y > 255.0f ) result.Y = 255;
			if ( result.Z > 255.0f ) result.Z = 255;
			if ( result.X < 0.0f ) result.X = 0;
			if ( result.Y < 0.0f ) result.Y = 0;
			if ( result.Z < 0.0f ) result.Z = 0;
			r = (BYTE)result.X;
			g = (BYTE)result.Y;
			b = (BYTE)result.Z;

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

示例12: Normalize

	/* Normalize */
	Vector4 Normalize(Vector4 toNorm) {
		toNorm.Normalize();
		return toNorm;
	}
开发者ID:CaptKH,项目名称:IceBreaker,代码行数:5,代码来源:Vector4.cpp

示例13: acos

/* AngleBetween */
float Vector4::AngleBetween(Vector4& vec) {
	return acos(DotProduct(vec)/(Magnitude() * vec.Magnitude()));
}
开发者ID:CaptKH,项目名称:IceBreaker,代码行数:4,代码来源:Vector4.cpp

示例14: GShape

bool Asteroid::update() {

	toWorld = translation * toWorld;
	float x = toWorld.m[3][0];
	float y = toWorld.m[3][1];
	float z = toWorld.m[3][2];

	if (x < -251 || x > 251 || y < -251 || y > 251 || z < -251 || z > 251) {
		return false;
	}

	SolarSystem * solar = &Globals::solarSystem;

	for (list<SolarPlanet*>::iterator it = solar->planets.begin();
	it != solar->planets.end(); it++) {

		Matrix4 newToWorld;
		Vector3 newPoint;
		Vector3 newDiff;

		SolarPlanet* planet = (*it);
		Vector3 pos = planet->position;
		Vector3 asteroid_pos = toWorld.getTranslate().toVector3();
		Vector3 diff = asteroid_pos - pos;
		float mag = diff.magnitude();

		if(!collided){
			if (mag < planet->radius) {

				planet->changeColor();

				collided = true;

				unsigned long range = 268435455;
				float genSeed = ((float)rand() / (float)RAND_MAX)  * range;
				gShape = new GShape((unsigned long)genSeed);

				Vector4 dir = toWorld.getTranslate() - pos.toVector4(0);
				Vector3 newDir = dir.toVector3();
				Vector3 face = Vector3(0, 0, 1);
				float angle = face.angle(newDir);

				Vector3 axis = face.cross(newDir).normalize();
				Matrix4 rot;
				rot = rot.makeRotateArbitrary(axis, angle);

				toWorld.m[3][0] = pos[0];
				toWorld.m[3][1] = pos[1];
				toWorld.m[3][2] = pos[2];

				toWorld = toWorld * rot;
				toWorld.m[3][0] = asteroid_pos[0];
				toWorld.m[3][1] = asteroid_pos[1];
				toWorld.m[3][2] = asteroid_pos[2];
				translation.identity();

				float xT = dir[0] / (planet->radius * 2);
				float yT = dir[1] / (planet->radius * 2);
				float zT = dir[2] / (planet->radius * 2);

				/*xT = xT / 200;
				yT = yT / 200;
				zT = zT / 200;*/

				translation = translation.makeTranslate(xT, yT, zT);
				justReverted = true;
				break;
			}
			//return false;
		}
		else {

			Vector3 basePos = gShape->baseToWorld.getTranslate().toVector3();
			Vector3 leftPos = gShape->leftToWorld.getTranslate().toVector3();
			Vector3 rightPos = gShape->rightToWorld.getTranslate().toVector3();

			float baseRadius = gShape->A_size * 1.7;
			float leftRadius = gShape->B_size * 1.7;
			float rightRadius = gShape->C_size * 1.7;

			diff = basePos - pos;
			if (diff.magnitude() <= baseRadius + planet->radius) {

				newToWorld = toWorld * translation;
				newPoint = newToWorld.getTranslate().toVector3();
				newDiff = newPoint - pos;

				if (newDiff.magnitude() > diff.magnitude()) {
					break;
				}
				else {
					if (!justReverted) {
						genColorz(gShape->baseBoundSphereColor);
						translation.m[3][0] = -translation.m[3][0];
						translation.m[3][1] = -translation.m[3][1];
						translation.m[3][2] = -translation.m[3][2];
						justReverted = true;
					}
					
					break;
//.........这里部分代码省略.........
开发者ID:tylerpitz,项目名称:CSE167-FinalProj,代码行数:101,代码来源:Asteroid.cpp

示例15: SetAttribute

bool XMLElement::SetVector4(const String& name, const Vector4& value)
{
    return SetAttribute(name, value.ToString());
}
开发者ID:RobertoMalatesta,项目名称:AtomicGameEngine,代码行数:4,代码来源:XMLElement.cpp


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