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


C++ D3DXVECTOR4函数代码示例

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


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

示例1: memset

bool ParticleSystemClass::UpdateBuffers(ID3D11DeviceContext* deviceContext)//is called every frame and rebuilds the entire dynamic vertexbuffer with the updated position of all the particles in the particle system
{
	int index, i;
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	VertexType* verticesPtr;

	//initialize vertex array to zeroes at first
	memset(m_vertices, 0, (sizeof(VertexType) *m_vertexCount));

	//build the vertex array from the particle list array. each particle is a quad of two tris
	index = 0;

	for(i=0; i<m_currentParticleCount; i++)
	{
		//bottom left
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX - m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
		
		m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(-m_particleList[i].positionX, -m_particleList[i].positionY, -m_particleList[i].positionZ));

		D3DXVec3TransformCoord(
			&m_vertices[index].position,
			&m_vertices[index].position,	
			&RotateParticle(
				D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ),
				m_vertices[index].position,
				m_particleList[i].m_rotationX,
				m_particleList[i].m_rotationY,
				m_particleList[i].m_rotationZ)
				);

		m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ));

		
		m_vertices[index].texture = D3DXVECTOR2(0.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		//top left
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX - m_particleSize, m_particleList[i].positionY + m_particleSize, m_particleList[i].positionZ);
				m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(-m_particleList[i].positionX, -m_particleList[i].positionY, -m_particleList[i].positionZ));

		D3DXVec3TransformCoord(
			&m_vertices[index].position,
			&m_vertices[index].position,
			&RotateParticle(
				D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ),
				m_vertices[index].position,
				m_particleList[i].m_rotationX,
				m_particleList[i].m_rotationY,
				m_particleList[i].m_rotationZ)
				);

		m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ));


		m_vertices[index].texture = D3DXVECTOR2(0.0f, 0.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		//bottom right
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX + m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
				m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(-m_particleList[i].positionX, -m_particleList[i].positionY, -m_particleList[i].positionZ));

		D3DXVec3TransformCoord(
			&m_vertices[index].position,
			&m_vertices[index].position,
			&RotateParticle(
				D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ),
				m_vertices[index].position,
				m_particleList[i].m_rotationX,
				m_particleList[i].m_rotationY,
				m_particleList[i].m_rotationZ)
				);

		m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ));

		m_vertices[index].texture = D3DXVECTOR2(1.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		//bottom right
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX + m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
				m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(-m_particleList[i].positionX, -m_particleList[i].positionY, -m_particleList[i].positionZ));

		D3DXVec3TransformCoord(
			&m_vertices[index].position,
			&m_vertices[index].position,
			&RotateParticle(
				D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ),
				m_vertices[index].position,
				m_particleList[i].m_rotationX,
				m_particleList[i].m_rotationY,
				m_particleList[i].m_rotationZ)
				);

		m_vertices[index].position = m_vertices[index].position.operator+(D3DXVECTOR3(m_particleList[i].positionX, m_particleList[i].positionY, m_particleList[i].positionZ));

		m_vertices[index].texture = D3DXVECTOR2(1.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
//.........这里部分代码省略.........
开发者ID:NukePie,项目名称:Engine,代码行数:101,代码来源:ParticleSystemClass.cpp

示例2: slides_render

void slides_render(float t)
{
	Sleep(10);

	if(slides_current_texture!=slides_texture)
	{
		if(slides_tex)
		{
			slides_tex->Release();
			slides_tex=NULL;
		}
		slides_current_texture=slides_texture;

		CreateThread(NULL, 0, slides_decode, NULL, 0, NULL);
	}


	g_pd3dDevice->BeginScene();
	g_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff000000, 1.0f, 0L );

    // Render the secondary color surface to the screen
    struct VERTEX { D3DXVECTOR4 p; FLOAT tu, tv; 
	};
    VERTEX v[4];
    v[0].p = D3DXVECTOR4( SX(  0) - 0.5f, SY( 48) - 0.5f, 0, 1 );  v[0].tu =   0; v[0].tv =   0;
    v[1].p = D3DXVECTOR4( SX(640) - 0.5f, SY( 48) - 0.5f, 0, 1 );  v[1].tu = 1; v[1].tv =   0;
    v[2].p = D3DXVECTOR4( SX(640) - 0.5f, SY(432) - 0.5f, 0, 1 );  v[2].tu = 1; v[2].tv =1;
    v[3].p = D3DXVECTOR4( SX(  0) - 0.5f, SY(432) - 0.5f, 0, 1 );  v[3].tu =   0; v[3].tv = 1;
	m_pd3dDevice->SetFVF( D3DFVF_XYZRHW|D3DFVF_TEX1);

    m_pd3dDevice->SetTexture( 0, slides_tex );
	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0);
	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);

	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR );
	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
    m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU,  D3DTADDRESS_CLAMP );
    m_pd3dDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV,  D3DTADDRESS_CLAMP );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER , D3DTEXF_LINEAR);
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER , D3DTEXF_LINEAR);

	int color=CLAMP(fade)*255;
	m_pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, 0xff<<24|(0x010101*color));

	m_pd3dDevice->SetRenderState( D3DRS_ZENABLE,   FALSE );
    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
	g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO );
    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);

	if(slides_tex)
	    WRAP(m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, 2, v, 6*sizeof(FLOAT) ));

    m_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE);
    m_pd3dDevice->SetTexture( 0, NULL );


	g_pd3dDevice->EndScene();


	//   g_pd3dDevice->Present( NULL, NULL, NULL, NULL );


}
开发者ID:Gargaj,项目名称:doomsday-w32,代码行数:66,代码来源:slides.cpp

示例3: D3DXMatrixScaling

//-------------------------------------------------------------
// Name: Render()
// Desc: 화면 렌더
//-------------------------------------------------------------
HRESULT CMyD3DApplication::Render()
{
    D3DXMATRIX m, mT, mR, mView, mProj;
	D3DXMATRIX mWorld;
	D3DXVECTOR4 v, light_pos, eye_pos;
	DWORD i;

	//---------------------------------------------------------
	// 렌더
	//---------------------------------------------------------
    if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
    {
		// 렌더링 타겟 클리어
		m_pd3dDevice->Clear(0L, NULL
						, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER
						, 0x0060c0, 1.0f, 0L);

		//-----------------------------------------------------
		// 지형렌더
		//-----------------------------------------------------
		// 월드행렬
		D3DXMatrixScaling( &m,  3.0f, 3.0f, 3.0f );
		D3DXMatrixRotationY( &mR,  D3DX_PI );
		D3DXMatrixTranslation( &mT, 0.0f,-2.0f ,0.0f );
		mWorld = m * mR * mT;

		// 행렬설정
		m_pd3dDevice->SetTransform( D3DTS_WORLD,  &mWorld);
		m_pd3dDevice->SetTransform( D3DTS_VIEW,  &m_mView );
		m_pd3dDevice->SetTransform( D3DTS_PROJECTION,  &m_mProj );

		TSS( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
		TSS( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		m_pMeshBg->Render( m_pd3dDevice );

		if( m_pEffect != NULL ) 
		{
			//-------------------------------------------------
			// 셰이더 설정
			//-------------------------------------------------
			m_pEffect->SetTechnique( m_hTechnique );
			m_pEffect->Begin( NULL, 0 );
			m_pEffect->Pass( 0 );
			

			//-------------------------------------------------
			// 주전자 렌더
			//-------------------------------------------------
			
			

			// 월드행렬(회전)
			D3DXMatrixRotationY( &mWorld,  m_fTime );

			// 로컬-투영 변환행렬
			m = mWorld * m_mView * m_mProj;
			m_pEffect->SetMatrix( m_hmWVP, &m );

			// 광원의 방향(로컬좌표계)
			light_pos = D3DXVECTOR4( -0.577f, -0.577f, -0.577f,0);
			D3DXMatrixInverse( &m, NULL, &mWorld);
			D3DXVec4Transform( &v, &light_pos, &m );
			D3DXVec3Normalize( (D3DXVECTOR3 *)&v, (D3DXVECTOR3 *)&v );
			v.w = -0.7f;		// 환경광 강도
			m_pEffect->SetVector( m_hvLightDir, &v );
			
			// 시점(로컬좌표계)
			m = mWorld * m_mView;
			D3DXMatrixInverse( &m, NULL, &m);
			v = D3DXVECTOR4( 0, 0, 0, 1);
			D3DXVec4Transform( &v, &v, &m );
			m_pEffect->SetVector( m_hvEyePos, &v );

			// 법선맵
			m_pEffect->SetTexture( m_htNormalMap, m_pNormalMap );
			// 정점선언
			m_pd3dDevice->SetVertexDeclaration( m_pDecl );

			D3DMATERIAL9 *pMtrl = m_pMesh->m_pMaterials;
			for( i=0; i<m_pMesh->m_dwNumMaterials; i++ ) {
				v.x = pMtrl->Diffuse.r;
				v.y = pMtrl->Diffuse.g;
				v.z = pMtrl->Diffuse.b;
				m_pEffect->SetVector( m_hvColor, &v );
				m_pEffect->SetTexture( m_htDecaleTex, m_pMesh->m_pTextures[i] );
				m_pMesh->m_pLocalMesh->DrawSubset( i );  // 렌더
				pMtrl++;
			}

			m_pEffect->End();
		}

         // 도움말 출력
        RenderText();

		// 렌더종료
//.........这里部分代码省略.........
开发者ID:jjuiddong,项目名称:Dx9-Shader,代码行数:101,代码来源:main.cpp

示例4: D3DXVECTOR4

void DxManager::RenderShadowMap()
{
	// Set sun-settings
	this->Shader_DeferredLightning->SetBool("UseSun", this->useSun);
	if(this->useSun)
	{
		this->Shader_DeferredLightning->SetStructMemberAsFloat4("sun", "Direction", D3DXVECTOR4(this->sun.direction, 0.0f));
		this->Shader_DeferredLightning->SetStructMemberAsFloat4("sun", "LightColor", D3DXVECTOR4(this->sun.lightColor, 0.0f));
		this->Shader_DeferredLightning->SetStructMemberAsFloat("sun", "LightIntensity", this->sun.intensity);
		//Shader_ShadowMap->Apply(0);		// Dont know why the fuck this has to be here, but it does, otherwise textures wont be sent when rendering objects. **Texture error**
	}
	// If special circle is used
	if(this->specialCircleParams.x) //if inner radius > 0, then send/set data
	{
		this->Shader_DeferredLightning->SetFloat4("dataPPHA", this->specialCircleParams);
	}

	// Generate and send shadowmaps to the main-shader
	if(!this->lights.size())
	{
		for (int l = 0; l < this->lights.size(); l++)
		{
			Dx_DeviceContext->OMSetRenderTargets(0, 0, this->lights[l]->GetShadowMapDSV());
			D3D11_VIEWPORT wp = this->lights[l]->GetShadowMapViewPort();
			Dx_DeviceContext->RSSetViewports(1, &wp);
			Dx_DeviceContext->ClearDepthStencilView(this->lights[l]->GetShadowMapDSV(), D3D11_CLEAR_DEPTH, 1.0f, 0);

			//Static meshes
			for(int i = 0; i < this->objects.size(); i++)
			{
				if(!this->objects[i]->IsUsingInvisibility())
				{
					MaloW::Array<MeshStrip*>* strips = this->objects[i]->GetStrips();
					D3DXMATRIX wvp = this->objects[i]->GetWorldMatrix() * this->lights[l]->GetViewProjMatrix();
					this->Shader_ShadowMap->SetMatrix("LightWVP", wvp);
				
					for(int u = 0; u < strips->size(); u++)
					{
						Object3D* obj = strips->get(u)->GetRenderObject();
						Dx_DeviceContext->IASetPrimitiveTopology(obj->GetTopology());
						Buffer* verts = obj->GetVertBuff();
						if(verts)
							verts->Apply();
						Shader_ShadowMap->SetBool("textured", false);

						Buffer* inds = obj->GetIndsBuff();
						if(inds)
							inds->Apply();

						Shader_ShadowMap->Apply(0);

					
						//Draw
						if(inds)
							Dx_DeviceContext->DrawIndexed(inds->GetElementCount(), 0, 0);
						else
							Dx_DeviceContext->Draw(verts->GetElementCount(), 0);
					}
				}
			}
		
			//Animated meshes
			for(int i = 0; i < this->animations.size(); i++)
			{
				if(!this->animations[i]->IsUsingInvisibility())
				{
					KeyFrame* one = NULL;
					KeyFrame* two = NULL;
					float t = 0.0f;
					this->animations[i]->SetCurrentTime(this->Timer);
					this->animations[i]->GetCurrentKeyFrames(&one, &two, t);
					MaloW::Array<MeshStrip*>* stripsOne = one->strips;
					MaloW::Array<MeshStrip*>* stripsTwo = two->strips;

					//set shader data (per object)
					D3DXMATRIX wvp = this->animations[i]->GetWorldMatrix() * this->lights[l]->GetViewProjMatrix();
					this->Shader_ShadowMapAnimated->SetMatrix("LightWVP", wvp);
					this->Shader_ShadowMapAnimated->SetFloat("t", t);

					for(int u = 0; u < stripsOne->size(); u++) 
					{
						Object3D* objOne = stripsOne->get(u)->GetRenderObject();
						Object3D* objTwo = stripsTwo->get(u)->GetRenderObject();

						this->Dx_DeviceContext->IASetPrimitiveTopology(objOne->GetTopology()); 

						Buffer* vertsOne = objOne->GetVertBuff();
						Buffer* vertsTwo = objTwo->GetVertBuff();

						ID3D11Buffer* vertexBuffers [] = {vertsOne->GetBufferPointer(), vertsTwo->GetBufferPointer()};
						UINT strides [] = {sizeof(Vertex), sizeof(Vertex)};
						UINT offsets [] = {0, 0};

						this->Dx_DeviceContext->IASetVertexBuffers(0, 2, vertexBuffers, strides, offsets);

						Shader_ShadowMapAnimated->Apply(0);
						this->Dx_DeviceContext->Draw(vertsOne->GetElementCount(), 0);
					}
				}
			}
//.........这里部分代码省略.........
开发者ID:Edaenge,项目名称:NDYGFX,代码行数:101,代码来源:DxManagerRender.cpp

示例5: 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

示例6: CalcZAxisRotate

void CIFControl::UpdateRotateBuffer( float fAngle )
{
	float xs, ys;
	float tx1, ty1, tx2, ty2;
	int id;
	int texIdx;
	int texSizeX;
	int texSizeY;
	int curIdx;
	DWORD color;

	float width= (float)m_info[0].sizeY * 0.5f;
	float x, y;
	vec3_t molt, molb, mort, morb;

	molt[0] = -width;	molt[1] = -width;		molt[2] = 0.0f;
	mort[0] = width;	mort[1] = -width;		mort[2] = 0.0f;
	morb[0] = width;	morb[1] = width;		morb[2] = 0.0f;
	molb[0] = -width;	molb[1] = width;		molb[2] = 0.0f;

	CalcZAxisRotate( fAngle , molt, mort );				
	CalcZAxisRotate( fAngle , molb, morb );				

	molt[0] += width;
	molt[1] += width;
	mort[0] += width;
	mort[1] += width;
	morb[0] += width;
	morb[1] += width;
	molb[0] += width;
	molb[1] += width;

	x = (float)m_info[0].clientX;
	y = (float)m_info[0].clientY;

	molt[0]	+= x;
	molt[1]	+= y;
	mort[0]	+= x;
	mort[1]	+= y;
	morb[0]	+= x;
	morb[1]	+= y;
	molb[0]	+= x;
	molb[1]	+= y;

	curIdx = m_current;
	
	texIdx = m_info[m_current].texIndex;
	id = m_info[curIdx].ID;

	if( texIdx >=0 )
	{
		texSizeX = g_ifMng->m_texInfo[texIdx].texSizeX;
		texSizeY = g_ifMng->m_texInfo[texIdx].texSizeY;
	}
	else
	{
		texSizeX = 1;
		texSizeY = 1;
	}

	xs = (float)m_info[m_current].sizeX;
	ys = (float)m_info[m_current].sizeY;

	tx1 = (float)m_info[m_current].texCoordX;
	ty1 = (float)m_info[m_current].texCoordY;

	tx2 = (float)m_info[m_current].texCoordX + xs;
	ty2 = (float)m_info[m_current].texCoordY + ys;

	tx1 /= (float)texSizeX;
	ty1 /= (float)texSizeY;
	tx2 /= (float)texSizeX;
	ty2 /= (float)texSizeY;

	if( id != -1 )
	{
		if( g_ifMng->m_iBackPos[id].clientX == IF_POSITION_FULL ) xs = (float)g_ifMng->m_clientWidth;
		if( g_ifMng->m_iBackPos[id].clientY == IF_POSITION_FULL ) ys = (float)g_ifMng->m_clientHeight;
	}

	IFTEXTUREVERTEX *pVertices = NULL;

	pVertices = (IFTEXTUREVERTEX *)m_vexbuf->Lock();

	if( m_info[m_current].texIndex != -1 ) color = 0xffffffff;
	else color = 0xff000000;

	if( texIdx == -2 ) 
	{
		color = 0xc0000000;
	}

	float tempzpos = 0.0f;
	float tempwpos = 1.0f;
	
	pVertices[0].position = D3DXVECTOR4( molb[0] - 0.5f, molb[1] - 0.5f, tempzpos, tempwpos );
	pVertices[0].color = color;
	pVertices[0].tu = tx1;
	pVertices[0].tv = ty2;

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

示例7: Render

//*************************************************************************************************************
void Render(float alpha, float elapsedtime)
{
	static float time = 0;

	D3DXMATRIX		view, proj, vp;
	D3DXMATRIX		world;
	D3DXMATRIX		inv;

	D3DXVECTOR4		amblight(0.2f, 0.2f, 0.2f, 1);
	D3DXVECTOR4		intensity(0.8f, 0.8f, 0.8f, 1);
	D3DXVECTOR4		zero(0, 0, 0, 1);

	D3DXVECTOR3		lightpos(0, 0, -10);
	D3DXVECTOR3		eye(0, 0, -5.2f);
	D3DXVECTOR3		look(0, 0.5f, 0);
	D3DXVECTOR3		up(0, 1, 0);
	D3DXVECTOR3		p1, p2;
	D3DXVECTOR2		orient	= cameraangle.smooth(alpha);
	D3DXVECTOR2		light	= lightangle.smooth(alpha);

	time += elapsedtime;

	// setup light
	D3DXMatrixRotationYawPitchRoll(&view, light.x, light.y, 0);
	D3DXVec3TransformCoord(&lightpos, &lightpos, &view);

	// TODO: no need to calculate every frame
	for( int i = 0; i < NUM_OBJECTS; ++i )
	{
		FindSilhouette(objects[i], (D3DXVECTOR3&)lightpos);
		ExtrudeSilhouette(objects[i], (D3DXVECTOR3&)lightpos);
	}

	// setup camera
	D3DXMatrixRotationYawPitchRoll(&view, orient.x, orient.y, 0);
	D3DXVec3TransformCoord(&eye, &eye, &view);

	D3DXMatrixLookAtLH(&view, &eye, &look, &up);
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4, (float)screenwidth / (float)screenheight, 0.1f, 20);

	// put far plane to infinity
	proj._33 = 1;
	proj._43 = -0.1f;

	D3DXMatrixMultiply(&vp, &view, &proj);
	D3DXMatrixScaling(&world, 5, 0.1f, 5);

	// specular effect uniforms
	specular->SetMatrix("matViewProj", &vp);
	specular->SetVector("eyePos", (D3DXVECTOR4*)&eye);
	specular->SetVector("lightPos", (D3DXVECTOR4*)&lightpos);
	specular->SetVector("ambient", &zero); // it's a fuck-up
	specular->SetVector("lightColor", &intensity); // lazy to tonemap
	
	ambient->SetMatrix("matViewProj", &vp);
	ambient->SetVector("ambient", &amblight);

	if( SUCCEEDED(device->BeginScene()) )
	{
		device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0xff6694ed, 1.0f, 0);

		// STEP 1: z pass
		ambient->SetTechnique("ambientlight");
		ambient->SetMatrix("matViewProj", &vp);

		DrawScene(ambient);

		// STEP 2: draw shadow with depth fail method
		device->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
		device->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

		device->SetRenderState(D3DRS_STENCILENABLE, TRUE);
		device->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
		device->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
		device->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
		device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_INCR);
		device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW);

		extrude->SetTechnique("extrude");
		extrude->SetMatrix("matViewProj", &vp);

		extrude->Begin(0, 0);
		extrude->BeginPass(0);
		{
			for( int i = 0; i < NUM_OBJECTS; ++i )
				DrawShadowVolume(objects[i]);

			device->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_DECR);
			device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);

			for( int i = 0; i < NUM_OBJECTS; ++i )
				DrawShadowVolume(objects[i]);
		}
		extrude->EndPass();
		extrude->End();

		device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_RED|D3DCOLORWRITEENABLE_GREEN|D3DCOLORWRITEENABLE_BLUE|D3DCOLORWRITEENABLE_ALPHA);

		// STEP 3: multipass lighting
//.........这里部分代码省略.........
开发者ID:IwishIcanFLighT,项目名称:Asylum_Tutorials,代码行数:101,代码来源:main.cpp

示例8: D3DXVECTOR4

void LightClass::SetDiffuseColor(float red, float green, float blue, float alpha)
{
	m_diffuseColor = D3DXVECTOR4(red, green, blue, alpha);
	return;
}
开发者ID:kvlar,项目名称:Haeigan,代码行数:5,代码来源:LightClass.cpp

示例9: SetShader

void object::render()
{
	SetShader();
	d3ddevice->SetVertexShaderConstant( 0, &D3DXVECTOR4(0,0,0,0), 1 );
	d3ddevice->SetVertexShaderConstant( 1, &D3DXVECTOR4(1,1,1,1), 1 );
	d3ddevice->SetVertexShaderConstant( 80, &D3DXVECTOR4(0.5f,0.5f,0.5f,0.5f), 1 );

	D3DXMATRIX mat;
	D3DXMATRIX matworldview;
	D3DXMATRIX temp;
	D3DXVECTOR4 light_vec;
	//D3DXVECTOR4 eye_vec;

	D3DXMatrixIdentity(&matworld);
	D3DXMatrixTranslation(&temp,radius_of_rotation,0,0);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );
	D3DXMatrixRotationY(&temp,angle);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );
	D3DXMatrixTranslation(&temp,center_pos.x,center_pos.y,center_pos.z);
	D3DXMatrixMultiply( &matworld, &matworld, &temp );
	
	D3DXMatrixMultiply( &matworldview, &matworld, &matView );
	
	D3DXMatrixMultiply( &mat, &matworldview, &matProj );
	D3DXMatrixTranspose( &mat, &mat );
	d3ddevice->SetVertexShaderConstant( 2, &mat, 4 );
	D3DXMatrixInverse(&temp,NULL,&matworld);
	light_vec.x = light_pos[0];
	light_vec.y = light_pos[1];
	light_vec.z = light_pos[2];
	light_vec.w = 1;
	
	eye_pos.x = 0;
	eye_pos.y = 0;
	eye_pos.z = -15;
	eye_pos.w = 1;

	D3DXVec4Transform(&light_vec,&light_vec,&temp);
	D3DXVec4Transform(&eye_pos,&eye_pos,&temp);
	//D3DXVec3Normalize(&light_vec,&light_vec);
	//D3DXMatrixTranspose( &temp, &temp );
	//d3ddevice->SetVertexShaderConstant( 6, &temp, 4 );

// Declare and define the constant vertex color.
	D3DXVECTOR4 diff_color;
	diff_color = color;
	diff_color *= diffuse_amount;
	diff_color.w = 1;
	d3ddevice->SetVertexShaderConstant( 10, &color, 1 );
	d3ddevice->SetPixelShaderConstant( 2, &diff_color, 1 );
	D3DXVECTOR4 spec_color;
	spec_color = color;
	spec_color += D3DXVECTOR4(1,1,1,1);
	spec_color *= 0.5;
	spec_color *= specular_amount;
	spec_color.w = 1;
	d3ddevice->SetPixelShaderConstant( 4, &spec_color, 1 );

	d3ddevice->SetVertexShaderConstant( 11, &light_vec, 1 );
	d3ddevice->SetVertexShaderConstant( 13, &eye_pos, 1 );
	d3ddevice->SetVertexShaderConstant( 12, &ambient, 1 );
	
	D3DXVECTOR4 amb_color;
	amb_color = diff_color+spec_color;
	amb_color *= 0.1f;
	//amb_color.x *= color[0];
	//amb_color.y *= color[1];
	//amb_color.z *= color[2];
	amb_color.w = 1;

	d3ddevice->SetPixelShaderConstant( 3, &amb_color, 1 );

	//d3ddevice->SetPixelShaderConstant( 5, &D3DXVECTOR4(0,0,0,0), 1 );

//set texture
	if(texture != NULL)
		d3ddevice->SetTexture(0,texture);
	if(power_texture != NULL)
		d3ddevice->SetTexture(1,power_texture);

	
	d3ddevice->SetStreamSource( 0, vertex_buffer, sizeof(CUSTOMVERTEX) );
	d3ddevice->SetIndices(index_buffer,0);
	d3ddevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0,size, 0,size2);

	//mesh->DrawSubset(1);
	
}
开发者ID:duhone,项目名称:Old3DWork,代码行数:88,代码来源:object.cpp

示例10: D3DXVECTOR4

void D3DLight::SetDiffuseColor(float red, float green, float blue, float alpha)
{
	diffuseColor = D3DXVECTOR4(red, green, blue, alpha);
}
开发者ID:mindmastre,项目名称:DX11-Framework,代码行数:4,代码来源:D3DLight.cpp

示例11: D3DXVECTOR3

bool TerrainClass::InitializeBuffers(ID3D11Device* device)
{
    VertexType* vertices;
    unsigned long* indices;
    int index, i, j;
    float positionX, positionZ;
    D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc;
    D3D11_SUBRESOURCE_DATA vertexData, indexData;
    HRESULT result;


    // Calculate the number of vertices in the terrain mesh.
    m_vertexCount = (m_terrainWidth - 1) * (m_terrainHeight - 1) * 8;

    // Set the index count to the same as the vertex count.
    m_indexCount = m_vertexCount;

    // Create the vertex array.
    vertices = new VertexType[m_vertexCount];
    if(!vertices)
    {
        return false;
    }

    // Create the index array.
    indices = new unsigned long[m_indexCount];
    if(!indices)
    {
        return false;
    }

    // Initialize the index to the vertex array.
    index = 0;

    // Load the vertex and index arrays with the terrain data.
    for(j=0; j<(m_terrainHeight-1); j++)
    {
        for(i=0; i<(m_terrainWidth-1); i++)
        {
            // LINE 1
            // Upper left.
            positionX = (float)i;
            positionZ = (float)(j+1);

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // Upper right.
            positionX = (float)(i+1);
            positionZ = (float)(j+1);

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // LINE 2
            // Upper right.
            positionX = (float)(i+1);
            positionZ = (float)(j+1);

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // Bottom right.
            positionX = (float)(i+1);
            positionZ = (float)j;

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // LINE 3
            // Bottom right.
            positionX = (float)(i+1);
            positionZ = (float)j;

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // Bottom left.
            positionX = (float)i;
            positionZ = (float)j;

            vertices[index].position = D3DXVECTOR3(positionX, 0.0f, positionZ);
            vertices[index].color = D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f);
            indices[index] = index;
            index++;

            // LINE 4
            // Bottom left.
            positionX = (float)i;
            positionZ = (float)j;
//.........这里部分代码省略.........
开发者ID:ClauStan,项目名称:StarLight,代码行数:101,代码来源:terrainclass.cpp

示例12: timeGetTime

void noisemaker::render(const D3DXMATRIXA16 *mProjector)
{
	this->mProjector = *mProjector;

	if (RenderToSurface->BeginScene(rendered_texture_surface,NULL))
	{

		DWORD itime = timeGetTime() & ((1<<23) - 1);

		device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
		device->Clear(0, NULL, D3DCLEAR_TARGET , D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
		anim_effect->Begin(NULL,NULL);
		anim_effect->Pass(0);

		double r_scale	= prm->params[p_fScale].fData,
			r_timemulti = prm->params[p_fAnimspeed].fData,
			r_strength = 1.0f,
			r_falloff = prm->params[p_fFalloff].fData;
		// normalize r_strength
		float sum=0;
		for(int i=0; i<octaves; i++)
		{
			sum += r_strength;
			r_strength *= r_falloff;
		}
		r_strength = 1.0f / sum;

		for(i=0; i<octaves; i++)
		{
			unsigned int image[3];
			float amount[3];
			double dImage, fraction = modf((double)itime*r_timemulti,&dImage);
			int iImage = (int)dImage;
			amount[0] = pow(sin((fraction+2)*PI/3),2)/1.5;
			amount[1] = pow(sin((fraction+1)*PI/3),2)/1.5;
			amount[2] = pow(sin((fraction)*PI/3),2)/1.5;
			image[0] = (iImage) & (animlength-1);
			image[1] = (iImage+1) & (animlength-1);
			image[2] = (iImage+2) & (animlength-1);


			anim_effect->SetFloat("a",amount[0]);
			anim_effect->SetFloat("b",amount[1]);
			anim_effect->SetFloat("c",amount[2]);
			anim_effect->SetFloat("scale",r_scale);
			anim_effect->SetFloat("strength",r_strength);

			anim_effect->SetVector("tc_offset_a", &D3DXVECTOR4(offsets[image[0]].x,offsets[image[0]].y,0,1));
			anim_effect->SetVector("tc_offset_b", &D3DXVECTOR4(offsets[image[1]].x,offsets[image[1]].y,0,1));
			anim_effect->SetVector("tc_offset_c", &D3DXVECTOR4(offsets[image[2]].x,offsets[image[2]].y,0,1));

			anim_effect->SetTexture("NoiseTex",source_texture);
			anim_effect->SetMatrix("mProjector",mProjector);
			device->SetStreamSource( 0, VB, 0, sizeof(NOISEVERTEX) );
			device->SetFVF( D3DFVF_NOISEVERTEX );
			device->SetIndices( IB );
			device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 	
				0,			
				0,
				(patches_x+1)*(patches_y+1),
				0,
				2*patches_x*patches_y-1 );

			r_scale *= 2;
			r_timemulti *= 1.5;
			r_strength *= r_falloff;		
		}
		RenderToSurface->EndScene(0);
		device->SetTexture(0,NULL);
		device->SetTexture(1,NULL);
		device->SetTexture(2,NULL);
		anim_effect->End();
		device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ZERO);
	}
}
开发者ID:lenxyang,项目名称:sandbox_water,代码行数:76,代码来源:noisemaker.cpp

示例13: memset

bool ParticleSystemClass::UpdateBuffers(ID3D11DeviceContext* deviceContext)
{
	int index, i;
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	VertexType* verticesPtr;


	// Initialize vertex array to zeros at first.
	memset(m_vertices, 0, (sizeof(VertexType)* m_vertexCount));

	// Now build the vertex array from the particle list array.  Each particle is a quad made out of two triangles.
	index = 0;

	for (i = 0; i<m_currentParticleCount; i++)
	{
		// Bottom left.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX - m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(0.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		// Top left.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX - m_particleSize, m_particleList[i].positionY + m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(0.0f, 0.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		// Bottom right.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX + m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(1.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		// Bottom right.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX + m_particleSize, m_particleList[i].positionY - m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(1.0f, 1.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		// Top left.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX - m_particleSize, m_particleList[i].positionY + m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(0.0f, 0.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;

		// Top right.
		m_vertices[index].position = D3DXVECTOR3(m_particleList[i].positionX + m_particleSize, m_particleList[i].positionY + m_particleSize, m_particleList[i].positionZ);
		m_vertices[index].texture = D3DXVECTOR2(1.0f, 0.0f);
		m_vertices[index].color = D3DXVECTOR4(m_particleList[i].red, m_particleList[i].green, m_particleList[i].blue, 1.0f);
		index++;
	}

	// Lock the vertex buffer.
	result = deviceContext->Map(m_vertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if (FAILED(result))
	{
		return false;
	}

	// Get a pointer to the data in the vertex buffer.
	verticesPtr = (VertexType*)mappedResource.pData;

	// Copy the data into the vertex buffer.
	memcpy(verticesPtr, (void*)m_vertices, (sizeof(VertexType)* m_vertexCount));

	// Unlock the vertex buffer.
	deviceContext->Unmap(m_vertexBuffer, 0);

	return true;
}
开发者ID:LeonZhao84,项目名称:rastertek,代码行数:71,代码来源:particlesystemclass.cpp

示例14: D3DXVECTOR4

void CIFControl::UpdateBuffer( int zx, int zy )
{
	float x, y, xs, ys;
	float tx1, ty1, tx2, ty2;
	int id;
	int texIdx;
	int texSizeX;
	int texSizeY;
	int curIdx;

	DWORD color;

	curIdx = m_current;
	
	texIdx = m_info[m_current].texIndex;
	id = m_info[curIdx].ID;

	if( texIdx >=0 )
	{
		texSizeX = g_ifMng->m_texInfo[texIdx].texSizeX;
		texSizeY = g_ifMng->m_texInfo[texIdx].texSizeY;
	}
	else
	{
		texSizeX = 1;
		texSizeY = 1;
	}

	x = (float)m_info[curIdx].clientX;
	y = (float)m_info[curIdx].clientY;

	xs = (float)m_info[m_current].sizeX;
	ys = (float)m_info[m_current].sizeY;

	tx1 = (float)m_info[m_current].texCoordX;
	ty1 = (float)m_info[m_current].texCoordY;

	tx2 = (float)m_info[m_current].texCoordX + xs;
	ty2 = (float)m_info[m_current].texCoordY + ys;

	tx1 /= (float)texSizeX;
	ty1 /= (float)texSizeY;
	tx2 /= (float)texSizeX;
	ty2 /= (float)texSizeY;

	xs = zx;
	ys = zy;

	IFTEXTUREVERTEX *pVertices = NULL;

	pVertices = (IFTEXTUREVERTEX *)m_vexbuf->Lock();

	
	if( pVertices == NULL ) return;

	if( !m_fadeState )
	{
		if( m_info[m_current].texIndex != -1 ) color = 0xffffffff;
		else color = 0xff000000;
	}
	else 
	{
		color = m_fadeColor;
	}

	if( texIdx == -2 ) 
	{
		color = 0xc0000000;
	}

	float tempzpos = 0.0f;
	float tempwpos = 1.0f;

	
	pVertices[0].position = D3DXVECTOR4( x - 0.5f, y + ys - 0.5f, tempzpos, tempwpos );
	pVertices[0].color = color;
	pVertices[0].tu = tx1;
	pVertices[0].tv = ty2;

	pVertices[1].position = D3DXVECTOR4( x - 0.5f, y - 0.5f, tempzpos, tempwpos );
	pVertices[1].color = color;
	pVertices[1].tu = tx1;
	pVertices[1].tv = ty1;

	pVertices[2].position = D3DXVECTOR4( x + xs - 0.5f, y + ys - 0.5f, tempzpos, tempwpos );
	pVertices[2].color = color;
	pVertices[2].tu = tx2;
	pVertices[2].tv = ty2;

	pVertices[3].position = D3DXVECTOR4( x + xs - 0.5f, y - 0.5f, tempzpos, tempwpos );
	pVertices[3].color = color;
	pVertices[3].tu = tx2;
	pVertices[3].tv = ty1;

	pVertices[4].position = D3DXVECTOR4( x + xs - 0.5f, y + ys - 0.5f, tempzpos, tempwpos );
	pVertices[4].color = color;
	pVertices[4].tu = tx2;
	pVertices[4].tv = ty2;

	pVertices[5].position = D3DXVECTOR4( x - 0.5f, y - 0.5f, tempzpos, tempwpos );
//.........这里部分代码省略.........
开发者ID:gthgame,项目名称:gth,代码行数:101,代码来源:IFControl.cpp

示例15: sizeof

HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
                            const TCHAR* strText, DWORD dwFlags )
{
    if( m_pd3dDevice == NULL )
        return E_FAIL;

    // Setup renderstate
    m_pStateBlockSaved->Capture();
    m_pStateBlockDrawText->Apply();
    m_pd3dDevice->SetFVF( D3DFVF_FONT2DVERTEX );
    m_pd3dDevice->SetPixelShader( NULL );
    m_pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(FONT2DVERTEX) );

    // Set filter states
    if( dwFlags & D3DFONT_FILTERED )
    {
        m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
        m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
    }

    // Center the text block in the viewport
    if( dwFlags & D3DFONT_CENTERED_X )
    {
        D3DVIEWPORT9 vp;
        m_pd3dDevice->GetViewport( &vp );
        const TCHAR* strTextTmp = strText;
        float xFinal = 0.0f;

        while( *strTextTmp )
        {
            TCHAR c = *strTextTmp++;
    
            if( c == _T('\n') )
                break;  // Isn't supported.  
            if( (c-32) < 0 || (c-32) >= 128-32 )
                continue;

            FLOAT tx1 = m_fTexCoords[c-32][0];
            FLOAT tx2 = m_fTexCoords[c-32][2];
    
            FLOAT w = (tx2-tx1) *  m_dwTexWidth / m_fTextScale;
    
            xFinal += w - (2 * m_dwSpacing);
        }

        sx = (vp.Width-xFinal)/2.0f;
    }
    if( dwFlags & D3DFONT_CENTERED_Y )
    {
        D3DVIEWPORT9 vp;
        m_pd3dDevice->GetViewport( &vp );
        float fLineHeight = ((m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight);
        sy = (vp.Height-fLineHeight)/2;
    }

    // Adjust for character spacing
    sx -= m_dwSpacing;
    FLOAT fStartX = sx;

    // Fill vertex buffer
    FONT2DVERTEX* pVertices = NULL;
    DWORD         dwNumTriangles = 0;
    m_pVB->Lock( 0, 0, (void**)&pVertices, D3DLOCK_DISCARD );

    while( *strText )
    {
        TCHAR c = *strText++;

        if( c == _T('\n') )
        {
            sx = fStartX;
            sy += (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight;
        }

        if( (c-32) < 0 || (c-32) >= 128-32 )
            continue;

        FLOAT tx1 = m_fTexCoords[c-32][0];
        FLOAT ty1 = m_fTexCoords[c-32][1];
        FLOAT tx2 = m_fTexCoords[c-32][2];
        FLOAT ty2 = m_fTexCoords[c-32][3];

        FLOAT w = (tx2-tx1) *  m_dwTexWidth / m_fTextScale;
        FLOAT h = (ty2-ty1) * m_dwTexHeight / m_fTextScale;

        if( c != _T(' ') )
        {
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx1, ty2 );
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx2, ty1 );
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.9f,1.0f), dwColor, tx2, ty2 );
            *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.9f,1.0f), dwColor, tx1, ty1 );
            dwNumTriangles += 2;

            if( dwNumTriangles*3 > (MAX_NUM_VERTICES-6) )
            {
                // Unlock, render, and relock the vertex buffer
                m_pVB->Unlock();
                m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, dwNumTriangles );
//.........这里部分代码省略.........
开发者ID:hongxchen,项目名称:VR_Test,代码行数:101,代码来源:D3DFont.cpp


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