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


C++ D3DXMatrixTranslation函数代码示例

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


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

示例1: D3DXMatrixIdentity

//***************************************************************
//	描画
//	引数
//	LPDIRECT3DDEVICE9 pDevice:デバイスポインタ
//	戻り値
//	なし
//***************************************************************
void	CCoin::Draw(LPDIRECT3DDEVICE9 pDevice)
{
	//マトリックス変数宣言
	D3DXMATRIX	mTrans,mScale,mRotate;		//左から座標、大きさ、回転

	//テクスチャ取得変数
	LPDIRECT3DTEXTURE9	Texture = CTexture::GetTexture(m_nTex);

	//ライト無効化
	CLight::SetOffLight(pDevice);

	//描画タイプの変更
	CRenderer::SetRenderType(CRenderer::NOMAL);

			//マトリックス初期化
			D3DXMatrixIdentity(&m_mtxWorld);

			//大きさ設定
			D3DXMatrixScaling(&mScale, 1.0f,1.0f,1.0f);

			//合成
			D3DXMatrixMultiply(&m_mtxWorld,&m_mtxWorld,&mScale);

			//角度設定
			D3DXMatrixRotationYawPitchRoll(&mRotate, m_Vertex_3d.Rot_vtx.y,0.0f,0.0f);

			//合成
			D3DXMatrixMultiply(&m_mtxWorld,&m_mtxWorld,&mRotate);

			//座標設定
			D3DXMatrixTranslation(&mTrans, m_Vertex_3d.vtx.x,CScene3d::GetHeight(m_Vertex_3d.vtx) + 1.0f + m_Vertex_3d.vtx.y,m_Vertex_3d.vtx.z);

			//合成
			D3DXMatrixMultiply(&m_mtxWorld,&m_mtxWorld,&mTrans);

			//セッティング
			pDevice->SetTransform(D3DTS_WORLD,&m_mtxWorld);

		//メッシュ読み込み
		LPD3DXMATERIAL pMaterial = (LPD3DXMATERIAL)m_pD3DXMatBuff->GetBufferPointer();


			//描画開始
			for(unsigned int i = 0 ; i < m_nNumMat ; i++)
			{
				//マテリアルセット
				pDevice->SetMaterial(&pMaterial[i].MatD3D);

				if(Texture)
				{
					//テクスチャ貼り付け
					pDevice->SetTexture(0,
						Texture);
				}

				//描画
				m_pMesh->DrawSubset(i);
			}
			
		//マテリアルを元に戻す
		pMaterial->MatD3D.Diffuse = D3DXCOLOR(1.0f,1.0f,1.0f,0.0f);
		pMaterial->MatD3D.Ambient = D3DXCOLOR(0.0f,0.0f,0.0f,0.0f);
		pMaterial->MatD3D.Emissive = D3DXCOLOR(0.0f,0.0f,0.0f,0.0f);
		pDevice->SetMaterial(&pMaterial->MatD3D);

		//ライトを元に戻す
		CLight::SetOnLight(pDevice);
}
开发者ID:ProjectTest001,项目名称:TenkuuProject,代码行数:75,代码来源:coin.cpp

示例2: BeginState

bool ZEffectBillboardTexAniList::Draw()
{
	if(!m_pVB) return false;

	if( size()==0 ) return true;

	BeginState();

	RSetFog(FALSE);

	HRESULT	hr;

	DWORD	dwRemainNum = (DWORD)size();

	iterator itr = begin();

	while(dwRemainNum)
	{
		if(m_dwBase >= EFFECTBASE_DISCARD_COUNT)
			m_dwBase = 0;

		DWORD dwThisNum = min( dwRemainNum , BILLBOARD_FLUSH_COUNT );

		dwThisNum = min( dwThisNum , EFFECTBASE_DISCARD_COUNT - m_dwBase );	

		BYTE *pVertices;

		if( FAILED( hr = m_pVB->Lock( m_dwBase * sizeof(ZEFFECTCUSTOMVERTEX) * 4, dwThisNum * sizeof(ZEFFECTCUSTOMVERTEX) * 4,
			(VOID**)&pVertices, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		BYTE *pInd;
		if( FAILED( hr = m_pIB->Lock( m_dwBase * sizeof(WORD) * 6, dwThisNum * sizeof(WORD) * 6,
			(VOID**)&pInd, m_dwBase ? D3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD ) ) )
		{
			return false;
		}

		int nRenderCnt = 0;

		ZCharacter* pChar = NULL;

		for(DWORD j=0;j<dwThisNum;j++)
		{
			ZEFFECTBILLBOARDTEXANIITEM *p = (ZEFFECTBILLBOARDTEXANIITEM*)*itr;

			if(p->fElapsedTime < p->fAddTime ) {
				itr++;
				continue;
			}

			pChar = ZGetCharacterManager()->Find(p->CharUID);

			if( pChar ) {
				if( pChar->m_pVMesh ) {
					if( pChar->m_pVMesh->m_bIsRender==false) {//부모가 안그려졌으면 skip...
						itr++;
						continue;
					}
				}
			}

			nRenderCnt++;

			// Transform
			rmatrix matTranslation;
			rmatrix matScaling;
			rmatrix matWorld;

			rvector dir = p->normal;

			rvector up=p->up;
			rvector right;

			if(IS_EQ(dir.z,1.f)) up=rvector(1,0,0);

			D3DXVec3Cross(&right, &up, &dir);
			D3DXVec3Normalize(&right, &right);

			D3DXVec3Cross(&up, &right, &dir);
			D3DXVec3Normalize(&up, &up);

			rmatrix mat;
			D3DXMatrixIdentity(&mat);
			mat._11=right.x;mat._12=right.y;mat._13=right.z;
			mat._21=up.x;mat._22=up.y;mat._23=up.z;
			mat._31=dir.x;mat._32=dir.y;mat._33=dir.z;

			rvector pos=p->position;

//			float fScale=p->fStartSize * p->fOpacity + p->fEndSize * (1.f - p->fOpacity);

			float fInt = min(1,max(0,(p->fLifeTime - p->fElapsedTime)/p->fLifeTime));
			float fScale=p->fStartSize * fInt + p->fEndSize * (1.f - fInt);

			D3DXMatrixScaling(&matScaling,fScale*m_Scale.x,fScale*m_Scale.y,fScale*m_Scale.z);
			D3DXMatrixTranslation(&matTranslation, pos.x, pos.y, pos.z);

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

示例3: vLeft

void CAXModel::UpdateMatrix(void)
{
	D3DXMATRIX matPosition;
	D3DXMATRIX matSize;
	D3DXMATRIX matRotate;
	D3DXMATRIX matAnchorPoint;
	D3DXMATRIX matComplate;
	
	D3DXMATRIX mT;
	{
		AVector3 vLeft(1.0f, 0.0f, 0.0f);
		AVector3 vUp(0.0f, 1.0f, 0.0f);
		AVector3 vLook(0.0f, 0.0f, 1.0f);
		AVector3 vUpNew, vLeftNew, vLookNew;
		D3DXMATRIX mX, mY, mZ;

		D3DXMatrixRotationX(&mX, m_fRotX);
		D3DXMatrixRotationY(&mY, m_fRotY);
		D3DXMatrixRotationZ(&mZ, -m_fRotZ);

		D3DXMatrixTranslation(&mT, vUp.x, vUp.y, vUp.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vUpNew = AVector3(mT._41, mT._42, mT._43);

		D3DXMatrixTranslation(&mT, vLeft.x, vLeft.y, vLeft.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vLeftNew = AVector3(mT._41, mT._42, mT._43);

		D3DXMatrixTranslation(&mT, vLook.x, vLook.y, vLook.z);
		mT *= mX; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mY; D3DXMatrixTranslation(&mT, mT._41, mT._42, mT._43);
		mT *= mZ; vLookNew = AVector3(mT._41, mT._42, mT._43);

		mT._11 = vLeftNew.x;   mT._12 = vLeftNew.y;   mT._13 = vLeftNew.z;   mT._14 = 0.0f;		// Left Vector
		mT._21 = vUpNew.x;     mT._22 = vUpNew.y;     mT._23 = vUpNew.z;     mT._24 = 0.0f;		// Up Vector
		mT._31 = vLookNew.x;   mT._32 = vLookNew.y;   mT._33 = vLookNew.z;   mT._34 = 0.0f;		// Front Vector
		mT._41 = 0.0f;         mT._42 = 0.0f;         mT._43 = 0.0f;         mT._44 = 1.0f;		// Translation
	}

	D3DXMatrixTranslation(&matAnchorPoint, m_vAnchorPoint.x, m_vAnchorPoint.y, m_vAnchorPoint.z);
	D3DXMatrixScaling(&matSize, m_vSize.x, m_vSize.y, m_vSize.z);
	D3DXMatrixTranslation(&matPosition, m_vPosition.x, m_vPosition.y, m_vPosition.z);

	m_matComplate = matAnchorPoint * matSize * mT * matPosition;
	
	m_bUpdateMatrix = false;
}
开发者ID:Kawoou,项目名称:cau-oop14-billiards,代码行数:49,代码来源:AXModel.cpp

示例4: D3DXMatrixRotationZ

bool DirectGraphicsSprite::RenderSpriteRotated(float x, float y, float Winkel, int Anim, D3DCOLOR Color, bool mirror)
{
	float l,  r,  o,  u;					// Vertice Koordinaten
	float tl, tr, to, tu;					// Textur Koordinaten

	// Ausschnitt einstellen
	Anim %= 255;
	itsRect = itsPreCalcedRects [Anim];

	// normal
	//
	if (mirror == false)
	{
		l = x-0.5f;									// Links
		r = x+(itsRect.right-itsRect.left-1)+0.5f;	// Rechts

		Winkel = 360 - Winkel;
	}

	// oder gespiegelt
	//
	else
	{
		r = x+0.5f;									// Links
		l = x+(itsRect.right-itsRect.left-1)-0.5f;	// Rechts		
	}

	o = y-0.5f;									// Oben
	u = y+(itsRect.bottom-itsRect.top-1)+0.5f;	// Unten

	to = itsRect.top   /itsYSize;	// Oben
	tu = itsRect.bottom/itsYSize;	// Unten
	tl = itsRect.left  /itsXSize;	// Links
	tr = itsRect.right /itsXSize;	// Rechts

	TriangleStrip[0].color = TriangleStrip[1].color = TriangleStrip[2].color = TriangleStrip[3].color = Color;
	TriangleStrip[0].z     = TriangleStrip[1].z		= TriangleStrip[2].z	 = TriangleStrip[3].z	  = 0.0f;

	TriangleStrip[0].x		= l;		// Links oben
	TriangleStrip[0].y		= o;
	TriangleStrip[0].tu		= tl;
	TriangleStrip[0].tv		= to;

	TriangleStrip[1].x		= r;		// Rechts oben
	TriangleStrip[1].y		= o;
	TriangleStrip[1].tu		= tr;
	TriangleStrip[1].tv		= to;

	TriangleStrip[2].x		= l;		// Links unten
	TriangleStrip[2].y		= u;
	TriangleStrip[2].tu		= tl;
	TriangleStrip[2].tv		= tu;

	TriangleStrip[3].x		= r;		// Rechts unten
	TriangleStrip[3].y		= u;
	TriangleStrip[3].tu		= tr;
	TriangleStrip[3].tv		= tu;

	lpD3DDevice->SetTexture (0, itsTexture);							// Textur setzen

//----- Sprite rotieren

	D3DXMATRIX	matRot, matTrans, matTrans2;

	// Winkel angleichen, damit er immer zwischen 0° und 360° bleibt
	if (Winkel > 360) Winkel -= 360;
	if (Winkel < 0)	  Winkel += 360;

	// Rotationsmatrix
	D3DXMatrixRotationZ  (&matRot, float(PI * Winkel / 180));

	// Transformation zum Ursprung
	D3DXMatrixTranslation(&matTrans,-x-(itsRect.right  - itsRect.left)/2.0f,
									-y-(itsRect.bottom - itsRect.top )/2.0f, 0.0f);

	// Transformation wieder zurück
	D3DXMatrixTranslation(&matTrans2,x+(itsRect.right  - itsRect.left)/2.0f,
									 y+(itsRect.bottom - itsRect.top )/2.0f, 0.0f);

	D3DXMatrixMultiply	 (&matWorld, &matWorld, &matTrans);		// Verschieben
	D3DXMatrixMultiply	 (&matWorld, &matWorld, &matRot);		// rotieren
	D3DXMatrixMultiply	 (&matWorld, &matWorld, &matTrans2);	// und wieder zurück verschieben
	lpD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

	DirectGraphics.SetFilterMode (true);

    // Sprite zeichnen
    DirectGraphics.RendertoBuffer (D3DPT_TRIANGLESTRIP, 2,&TriangleStrip[0]);

	DirectGraphics.SetFilterMode (false);

	// Normale Projektions-Matrix wieder herstellen
	D3DXMatrixRotationZ (&matWorld, 0.0f);
	lpD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);

	return true;
}
开发者ID:RobDangerous,项目名称:Hurrican,代码行数:97,代码来源:DX8Sprite.cpp

示例5: D3DXMatrixRotationYawPitchRoll

void Rect3D2::render(DWORD curTime)
{
   DWORD elapsedTime;
   D3DXMATRIX matWorld, matTemp;
   D3DXMATRIX matRot, matTranslate, matScale;
   float t, halfTSqrd;

   //  calculate time elapsed and store current time for next cycle      
   if (m_oldTime == 0)
   {
      m_oldTime = curTime;
      elapsedTime = 0;
   }
   else
   {
      elapsedTime = curTime - m_oldTime;
      m_oldTime = curTime;
   }   
   
   t = elapsedTime * 0.001f;   //  convert time to seconds and store
   halfTSqrd = 0.5f * t * t;   //  store half of time squared

   // calculate rotations
   // d = d + v * t + (1/2)at^2
   // v = v + at;
   m_yaw += m_dYaw * t + halfTSqrd * m_ddYaw;
   m_dYaw += m_ddYaw * t;

   m_pitch += m_dPitch * t + halfTSqrd * m_ddPitch;
   m_dPitch += m_ddPitch * t;

   m_roll += m_dRoll * t + halfTSqrd * m_ddRoll;
   m_dRoll += m_ddRoll * t;

   // MATRICES   these take effect for drawing primitives until they are reset
   // so to draw objects with different orientation, just
   // use the matrices, draw, then reset again
   // in the case of multiple objects
   // each object sets the matrices for its use, renders, then the next sets..
   // renders.. and so on
   D3DXMatrixRotationYawPitchRoll( &matRot, m_yaw, m_pitch, m_roll);
   D3DXMatrixTranslation( &matTranslate, m_posX, m_posY, m_posZ );
   D3DXMatrixScaling( &matScale, m_width, m_height, m_depth );

   D3DXMatrixMultiply( &matTemp, &matScale, &matRot);
   D3DXMatrixMultiply( &matWorld, &matTemp, &matTranslate);

   m_device->SetTransform( D3DTS_WORLD, &matWorld );
   
   // for now all we have to do is set the texture
   // there are a lot of options to set for textures 
   // when different forms of pixel shading are involved, for now it always
   // looks the same
   m_device->SetTexture(0, m_texture);

   // SCENE RENDERING
   // Begin the scene
   m_device->BeginScene();

   m_device->SetStreamSource( 0, m_vertBuffer, 0, sizeof(CUSTOMVERTEX) );   // set vertex stream..

   m_device->SetFVF( D3DFVF_CUSTOMVERTEX );
//   m_device->SetVertexShader( D3DFVF_CUSTOMVERTEX );   // set vertex shader options

   m_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);

   m_device->EndScene();
}
开发者ID:pnchang,项目名称:advgraphics,代码行数:68,代码来源:Rect3D2.cpp

示例6: render

void  render (float timeDelta)
{
		//设置取景变换
	if (snake->ifDead ()==false)
	{
		gametime += timeDelta ;//计算游戏时间

		D3DXMATRIX V;
		Camera.SetViewMatrix(&V);
		Device->SetTransform  (D3DTS_VIEW,&V);
		KeyboardAndMouse(&Camera ,timeDelta);	
		D3DXMATRIX TerrainWorld;
		D3DXMatrixTranslation(&TerrainWorld,0.0f,00.0f,0.0f);

		//*************更新区域*********************
		
		props->upDateProps (timeDelta);
		groundobject->updateBird (timeDelta);
		snow->update(timeDelta);//掉落蓝色的花
		snake->changeWallRange (groundobject);
		D3DXVECTOR3 position;
		position.x =0.0f,position.y =0.0f,position.z =0.0f;
		groundobject->createWall (position);

		//为啥要把蛇的更新函数放在这里呢?因为里面包含了渲染字体的操作...
		snake->upDateSanke (timeDelta,DInput); 
		
		//开启深度缓存
		//开启深度缓存
		Device->SetRenderState (D3DRS_ZENABLE,true);
		Device->SetRenderState (D3DRS_ZFUNC,D3DCMP_LESS);
		Device->SetRenderState (D3DRS_ZWRITEENABLE,true);

		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(100,155,255), 1.0f, 0);
		
		//开始绘制
		Device->BeginScene ();

		//渲染地形
		terrain->draw (&TerrainWorld,false);

		//渲染天空盒
		skybox->RenderSkyBox();
	
	
		//渲染地面物体
		groundobject->renderGround ();
		
		//绘制雪花
		snow->render();
		gameui->RenderUI ();
		RECT rect;
		rect.left=120,rect.top=50,rect.right=800,rect.bottom=600;
		gameui->RenderFont(rect,snake->getScore());
		snake->Render();
		float i;
		groundobject->getWallRange(&i);
		if(snake->isDangerous (i))
			gameui2->RenderUI();

		//绘制道具
		props->RenderProps ();

		Device->EndScene ();
		Device->Present(0, 0, 0, 0);//提交后台缓存示翻转)
	}
	else 
	{
		//绘制游戏得分
		RECT rect;
		rect.left=280,rect.top=195,rect.right=800,rect.bottom=600;
		gameui->RenderFont (rect,snake->getScore());

		//绘制时间
		rect.left=280,rect.top=140,rect.right=800,rect.bottom=600;
		gameui->RenderFont (rect,d3d::IntToWchart(gametime));

		//绘制道具得分
		rect.left=280,rect.top=240,rect.right=800,rect.bottom=600;
		int propscore =props->getpropscore();
		gameui->RenderFont(rect ,d3d::IntToWchart(propscore));

		rect.left = 280,rect.top=422,rect.right=800,rect.bottom=600;
		int finnalscore=snake->getscore()+gametime +propscore*10;
		gameui->RenderFont (rect,d3d::IntToWchart(finnalscore));
		
	}
		//关闭深度缓存
		Device->SetRenderState (D3DRS_ZENABLE,false);
		Device->SetRenderState (D3DRS_ZFUNC,D3DCMP_LESS);
		Device->SetRenderState (D3DRS_ZWRITEENABLE,false);
}
开发者ID:huanzheWu,项目名称:3D-Tank-Battle,代码行数:92,代码来源:GameMain.cpp

示例7: Display

bool Display(float timeDelta)
{
    if (Device)
    {
        // Update the scene: update camera position.
        static float angle = (3.0f * D3DX_PI) / 2.0f;
        static float height = 5.0f;

        if (::GetAsyncKeyState(VK_LEFT) & 0x8000f)
            angle -= 0.5f * timeDelta;

        if (::GetAsyncKeyState(VK_RIGHT) & 0x8000f)
            angle += 0.5f * timeDelta;

        if (::GetAsyncKeyState(VK_UP) & 0x8000f)
            height += 5.0f * timeDelta;

        if (::GetAsyncKeyState(VK_DOWN) & 0x8000f)
            height -= 5.0f * timeDelta;

        D3DXVECTOR3 position(cosf(angle) * 7.0f, height, sinf(angle) * 7.0f);
        D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
        D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
        D3DXMATRIX V;
        D3DXMatrixLookAtLH(&V, &position, &target, &up);

        Device->SetTransform(D3DTS_VIEW, &V);


        static float x0 = 0.0f;
        static float y0 = 2.0f;
        static float z0 = 0.0f;
        if (::GetAsyncKeyState('A') & 0x8000f)
            x0 -= 2.0f * timeDelta;
        if (::GetAsyncKeyState('D') & 0x8000f)
            x0 += 2.0f * timeDelta;
        if (::GetAsyncKeyState('W') & 0x8000f)
            z0 += 2.0f * timeDelta;
        if (::GetAsyncKeyState('S') & 0x8000f)
            z0 -= 2.0f * timeDelta;
        if (::GetAsyncKeyState(VK_SPACE) & 0x8000f)
            y0 += 2.0f * timeDelta;
        if (::GetAsyncKeyState(VK_SHIFT) & 0x8000f)
            y0 -= 2.0f * timeDelta;
        D3DXMatrixTranslation(&Worlds[0], x0, y0, z0);


        // Draw the scene:
        Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
        Device->BeginScene();

        for (int i = 0; i < 4; i++)
        {
            // set material and world matrix for ith object, then render
            // the ith object.
            Device->SetMaterial(&Mtrls[i]);
            Device->SetTransform(D3DTS_WORLD, &Worlds[i]);
            Objects[i]->DrawSubset(0);
        }

        Device->EndScene();
        Device->Present(0, 0, 0, 0);
    }
    return true;
}
开发者ID:travishan,项目名称:mydirectXhan,代码行数:65,代码来源:DirLight.cpp

示例8: Setup

//
// Framework Functions
//
bool Setup()
{
	//
	// Create the objects.
	//

	D3DXCreateTeapot(
		Device,
		&Objects[0],
		0);

	D3DXCreateBox(
		Device,
		2.0f, // width
		2.0f, // height
		2.0f, // depth
		&Objects[1],
		0);

	// cylinder is built aligned on z-axis
	D3DXCreateCylinder(
		Device,
		1.0f, // radius at negative z end
		1.0f, // radius at positive z end
		3.0f, // length of cylinder
		10,   // slices
		10,   // stacks
		&Objects[2],
		0);

	D3DXCreateTorus(
		Device,
		1.0f, // inner radius
		3.0f, // outer radius
		10,   // sides
		10,   // rings
		&Objects[3],
		0);

	D3DXCreateSphere(
		Device,
		1.0f, // radius
		10,   // slices
		10,   // stacks
		&Objects[4],
		0);

	//
	// Build world matrices - position the objects in world space.
	// For example, ObjWorldMatrices[1] will position Objects[1] at
	// (-5, 0, 5).  Likewise, ObjWorldMatrices[2] will position
	// Objects[2] at (5, 0, 5).
	//

	D3DXMatrixTranslation(&ObjWorldMatrices[0],  0.0f, 0.0f,  0.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[1], -5.0f, 0.0f,  5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[2],  5.0f, 0.0f,  5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[3], -5.0f, 0.0f, -5.0f);
	D3DXMatrixTranslation(&ObjWorldMatrices[4],  5.0f, 0.0f, -5.0f);

	//
	// Set the projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI * 0.5f, // 90 - degree
			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	//
	// Switch to wireframe mode.
	//

	Device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	return true;
}
开发者ID:xeonv3,项目名称:Direct3D,代码行数:84,代码来源:d3dInit.cpp

示例9: timeGetTime

void CDirectXFramework::Render()
{
	timeGetTime();
	RECT rect;
	// If the device was not created successfully, return
	if(!m_pD3DDevice)
	{
		return;
	}

	//*************************************************************************

	//////////////////////////////////////////////////////////////////////////
	// All draw calls between swap chain's functions, and pre-render and post- 
	// render functions (Clear and Present, BeginScene and EndScene)
	//////////////////////////////////////////////////////////////////////////
	
	// Clear the back buffer, call BeginScene()
	m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
	m_pD3DDevice->BeginScene();
	system->update();
			//////////////////////////////////////////////////////////////////////////
			// Draw 3D Objects (for future labs - not used in Week #1)
			//////////////////////////////////////////////////////////////////////////

			//////////////////////////////////////////////////////////////////////////
			// Draw 2D sprites
			//////////////////////////////////////////////////////////////////////////
			// Note: You should only be calling the sprite object's begin and end once, 
			// with all draw calls of sprites between them

			// Call Sprite's Begin to start rendering 2D sprite objects
				m_pD3DSprite->Begin(NULL);
				//////////////////////////////////////////////////////////////////////////
				// Matrix Transformations to control sprite position, scale, and rotate
				// Set these matrices for each object you want to render to the screen
				//////////////////////////////////////////////////////////////////////////
				// Scaling
				// Rotation on Z axis, value in radians, converting from degrees
				// Translation
				// Multiply scale and rotation, store in scale
				// Multiply scale and translation, store in world
				// Set Transform

				D3DXMATRIX transMat, rotMat, scaleMat, worldMat;
				D3DXMatrixIdentity(&transMat);
				D3DXMatrixIdentity(&scaleMat);
				D3DXMatrixIdentity(&rotMat);
				D3DXMatrixIdentity(&worldMat);
				D3DXMatrixRotationZ(&rotMat, D3DXToRadian(0));
				D3DXMatrixRotationZ(&rotMat, D3DXToRadian(0));
				D3DXMatrixTranslation(&transMat, Menu.xp, Menu.yp, 0.0f);
				D3DXMatrixScaling(&scaleMat, 0.5f, 0.5f, 0.0f);
				D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);
				D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);
				m_pD3DSprite->SetTransform(&worldMat);

				if(Menu.onSTART == true)
				{
			    	m_pD3DSprite->Draw(m_StartText, 0, &D3DXVECTOR3(m_StartImage.Width * 0.5f, 
					m_StartImage.Height * 0.5f, 0.0f), 0,
					D3DCOLOR_ARGB(255, 255, 255, 255));

					if(controlDown & ARROW_DOWN)
					{
						Menu.onSTART = false;
						Menu.onCREDITS = true;
						
					}
					if(controlDown & ENTER_KEY)
					{
						Menu.onSTART = false;
						Menu.onMovie = true;
						if(Menu.onMovie = true)
							{
							m_pMediaControl->Run();

							long evCode;
							m_pMediaEvent->WaitForCompletion(INFINITE, &evCode);

							m_pMediaControl->Stop();
							Menu.onMovie = false;
							Menu.onGAME = true;
							}
						
					}
				}
				else if(Menu.onCREDITS == true)
				{
					m_pD3DSprite->Draw(m_CreditText, 0, &D3DXVECTOR3(m_CreditImage.Width * 0.5f, 
					m_CreditImage.Height * 0.5f, 0.0f), 0,
					D3DCOLOR_ARGB(255, 255, 255, 255));

					if(controlDown & ARROW_DOWN)
					{
						Menu.onEXIT = true;
						Menu.onCREDITS = false;
						
					}
					if(controlDown & ENTER_KEY)
//.........这里部分代码省略.........
开发者ID:WillBowden,项目名称:DX9_Pong,代码行数:101,代码来源:DirectXFramework.cpp

示例10: SetupMatrices

//-----------------------------------------------------------------------------
// Name: SetupMatrices()
// Desc: Sets up the world, view, and projection transform matrices.
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
    // For our world matrix, we will just rotate the object about the y-axis.
    D3DXMATRIXA16 matWorld1, matWorld2, matWorld3, matWorld ;

    // Set up the rotation matrix to generate 1 full rotation (2*PI radians) 
    // every 1000 ms. To avoid the loss of precision inherent in very high 
    // floating point numbers, the system time is modulated by the rotation 
    // period before conversion to a radian angle.
    
	UINT  iTime  = timeGetTime() % 1000;
    FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
    
	D3DXMatrixRotationX( &matWorld1, fAngle );	
	D3DXMatrixRotationY( &matWorld2, fAngle );	
	D3DXMatrixMultiply(          
		&matWorld,
		&matWorld1,
		&matWorld2
	);

	D3DXMatrixTranslation(&matWorld3,
		iTime * (2.0f * D3DX_PI) / 5000.0f,
		0,
		0
	);

	D3DXMatrixMultiply(          
		&matWorld,
		&matWorld,
		&matWorld3
	);


    g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
	
	
	
	
	

    // Set up our view matrix. A view matrix can be defined given an eye point,
    // a point to lookat, and a direction for which way is up. Here, we set the
    // eye five units back along the z-axis and up three units, look at the
    // origin, and define "up" to be in the y-direction.
    D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-3.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).
    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

}
开发者ID:arlukin,项目名称:dev,代码行数:67,代码来源:Matrices.cpp

示例11: while

void Map::LoadMap(char* fileName, ResourceManager& resMan) {
	////////////////////////////////////////////////////////////////FILE I/O STUFF
	std::stringstream ss;
	std::ifstream file;
	char lineType;
	Terrain tempTerrain;
	D3DVECTOR pos, corner1, corner2, size;
	float rot;
	int zone;
	PrimStruct *tempPrim;
	PrimObj tempObj;
	sPoint tempSpawn;
	tempObj.mat = &mat;
	tempObj.Tex = resMan.loadTexture("uvtest.png",0,0,0,0,D3DFMT_UNKNOWN,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(255,0,255),0);
	file.open(fileName);
	if(file.is_open()) {
		while(!file.eof()) {
			lineType = ' ';
			file>>lineType;
			if(lineType == '#') {
				//comment line
				file.ignore(256,'\n');
			} else if(lineType == 'f'||lineType == 'F') {
				//floor
				//get top left
				file>>size.x;
				file>>size.z;
				file>>size.y;
				//get bottom right
				file>>pos.x;
				file>>pos.y;
				file>>pos.z;
				//zone
				file>>zone;
				ss<<"Floor"<<size.x<<"x"<<size.y<<"x"<<size.z;

				tempPrim = resMan.loadPrim(ss.str().c_str(),size.y,size.x,size.z);
				D3DXMatrixIdentity(&tempObj.matrix);
				D3DXMatrixTranslation(&tempObj.matrix,pos.x,pos.y,pos.z);
				tempObj.primInfo = tempPrim;
				renderInfo.push_back(tempObj);

				tempTerrain.Init(pos,tempPrim,FLOOR);

				AddFloor(tempTerrain);

				floorZone.push_back(zone);
				file.ignore();
			} else if(lineType == 'w' || lineType == 'W') {
				//walls
				//get top left
				file>>size.x;
				file>>size.z;
				file>>size.y;
				//get bottom right
				file>>pos.x;
				file>>pos.y;
				file>>pos.z;
				//zone
				file>>zone;

				ss<<"Wall"<<size.x<<"x"<<size.y<<"x"<<size.z;

				tempPrim = resMan.loadPrim(ss.str().c_str(),size.y,size.x,size.z);
				D3DXMatrixIdentity(&tempObj.matrix);
				D3DXMatrixTranslation(&tempObj.matrix,pos.x,pos.y,pos.z);
				tempObj.primInfo = tempPrim;
				renderInfo.push_back(tempObj);

				tempTerrain.Init(pos,tempPrim,WALL);

				AddWall(tempTerrain);
				wallZone.push_back(zone);
				file.ignore();
			} else if(lineType == 's' || lineType == 'S'){
开发者ID:sadaust,项目名称:Eevee-Hound-Final,代码行数:75,代码来源:Map.cpp

示例12: D3DXMatrixScaling

//**************渲染道具函数*************************
void Props::RenderProps ()
{
	std ::list <PROPS >::iterator i;
	for(i=_allprops.begin ();i!=_allprops.end ();i++)
	{
		if(i->_isalive==true)
		{
			//设置世界变换
			D3DXMATRIX position,scaling,V;
			D3DXMatrixScaling(&scaling,0.5f,0.3f,0.5f);
			D3DXMatrixTranslation(&position,i->_position.x ,i->_position.y ,i->_position.z);
			position=scaling*position;
			Camera.SetViewMatrix(&V);
			if(i->_id==1)
			{
				prop1->RanderBorad ( &V,position);
			}
			if(i->_id==2)
			{
				prop2->RanderBorad (&V,position);
			}
			if(i->_id==3)
			{
				prop3->RanderBorad(&V,position);
			}
			if(i->_id==4)
			{
				D3DXMatrixScaling(&scaling,1.0f,1.0f,1.0f);
				position=scaling*position;
				prop4->RanderBorad (&V,position);
			}
			switch (i->_id)
			{
				case 5:
					{
						prop5TimeExit +=0.1;
						if(prop5TimeLeft-(int)prop5TimeExit >0)
						{
							//指定时间出现的位置
							RECT rect;
							rect.left=400,rect.top=50,rect.right=800,rect.bottom=600;
							//渲染时间
							RenderTime(prop5TimeLeft-(int) prop5TimeExit,rect );
							//渲染动态纹理
							RenderDynaminc(prop5tex,position,V);
						}
						else //这里表示时间到了 没吃到那个道具
						{
							isaddscore=false;	//表示没有吃到那个道具
							i->_isalive=false;	//道具消失
							i->_timeHappen=0;	//道具出现时间置零
							prop5TimeExit=0;	//道具5时间绘制置零
						}
						break;
					}
				case 6:
					{
						RenderDynaminc(prop6tex,position,V);
						break;
					}
				case 7:
					{
						if(prop7TimeLeft-prop7TimeExit>0)
						{
							RenderDynaminc (prop7tex,position,V);
							prop7TimeExit += 0.1;
						}
						else 
						{
							prop7TimeExit =0;
							i->_isalive=false;
							i->_timeHappen=0;
						}
						break;
					}
			}

		}
	}
}
开发者ID:huanzheWu,项目名称:3D-Tank-Battle,代码行数:81,代码来源:Props.cpp

示例13: D3DXMatrixTranslation

void node::translate( float x, float y, float z){
	D3DXMATRIX tmp;
	D3DXMatrixTranslation(&tmp, x, y, z);
	matModelView = tmp * matModelView;
}
开发者ID:windkey,项目名称:KATAMARI,代码行数:5,代码来源:node.cpp

示例14: assert

//----[  buildAnimatedBones  ]-------------------------------------------------
void AnimatedMeshRenderer::buildAnimatedBones(
    const D3DXMATRIX* root_transform,
    AnimatedMeshIndex animated_mesh,
    AnimatedMeshAnimationTrack* animation_track,
    D3DXMATRIX* bone_matrices) const {
  assert(animated_mesh < animated_meshes_.size());
  assert(animation_track);
  assert(bone_matrices);

  const RenderableAnimatedMesh& renderable_animated_mesh
    = animated_meshes_.at(animated_mesh);
  AnimatedMeshAnimationTrackElement* internal_animation_track =
    reinterpret_cast<AnimatedMeshAnimationTrackElement*>(animation_track);
  RenderableAnimatedMesh::Frame* frames = renderable_animated_mesh.frames;
  size_t number_of_frames = renderable_animated_mesh.number_of_frames;
  RenderableAnimatedMesh::Bone* bones = renderable_animated_mesh.bones;
  size_t number_of_bones = renderable_animated_mesh.number_of_bones;

  // Build the frames using the data in the animation track
  D3DXMATRIXA16 matrix;
  for (size_t frame_index = 0; frame_index < number_of_frames; ++frame_index) {
    RenderableAnimatedMesh::Frame* frame = &frames[frame_index];
    AnimatedMeshAnimationTrackElement* track_element
      = &internal_animation_track[frame_index];
    AnimatedMeshAnimationTrackElement::FrameTransform* frame_transform
      = &track_element->frame_transform;

    // Build the transform matrix from the scale/rotate/translate settings
    //D3DXMatrixTransformation(&matrix,
    //                         NULL,
    //                         NULL,
    //                         frame_transform->scaling(),
    //                         NULL,
    //                         frame_transform->rotation(),
    //                         frame_transform->translation());

    // This method of constructing the transform matrices is necessary because
    // it allows us to transpose the quaternion's matrix during the build.
    D3DXMATRIXA16 cumulative, builder;
    D3DXMatrixScaling(&cumulative,
                      frame_transform->s[0],
                      frame_transform->s[1],
                      frame_transform->s[2]);

    D3DXQUATERNION quat;
    D3DXQuaternionNormalize(&quat, frame_transform->rotation());
    D3DXMatrixRotationQuaternion(&builder, &quat);
    D3DXMatrixTranspose(&builder, &builder);

    D3DXMatrixMultiply(&cumulative, &cumulative, &builder);
    D3DXMatrixTranslation(&builder,
                          frame_transform->t[0],
                          frame_transform->t[1],
                          frame_transform->t[2]);
    D3DXMatrixMultiply(&matrix, &cumulative, &builder);



    // Use the frame hierarchy to construct this frame's final transformation
    size_t parent_frame_index = frame->parent_frame_index;
    assert(!frame_index || (parent_frame_index < frame_index));
    const D3DXMATRIX* parent_frame_matrix
      = frame_index == 0 ? root_transform
                         : internal_animation_track[parent_frame_index]
                             .frameMatrix();
    D3DXMatrixMultiply(track_element->frameMatrix(),
                       &matrix,
                       parent_frame_matrix);
  }

  // Construct the bone transformations for this framte state
  for (size_t bone_index = 0; bone_index < number_of_bones; ++bone_index) {
    D3DXMATRIX* bone_matrix = bone_matrices + bone_index;
    const RenderableAnimatedMesh::Bone* bone = bones + bone_index;
    const D3DXMATRIXA16* frame_matrix
      = (internal_animation_track + bone->frame_index)->frameMatrix();
    D3DXMatrixMultiply(bone_matrix,
                       &bone->inverse_offset,
                       frame_matrix);
  }
}
开发者ID:karlgluck,项目名称:Evidyon,代码行数:82,代码来源:animatedmeshrenderer.cpp

示例15: RenderFrame

// This is the function used to render a single frame
void RenderFrame( void )
{
    
	
	CBUFFER cBuffer;

    cBuffer.LightVector = D3DXVECTOR4( 1.0f, 1.0f, 1.0f, 0.0f );
    cBuffer.LightColor = D3DXCOLOR(	   0.5f, 0.5f, 0.5f, 1.0f );
    cBuffer.AmbientColor = D3DXCOLOR(  0.2f, 0.2f, 0.2f, 1.0f );

	
    D3DXMATRIX matRotateY, matRotateZ, matView, matProjection, matOrtho, matScale, matTranslate[2];
    D3DXMATRIX matFinal;
	
    static float Time = 0.0f; 
	//Time += 0.0003f;
	//Time = 9.5f;
	Time = 0;
	D3DXMatrixTranslation( &matTranslate[0], moveX, moveY, moveZ );
	D3DXMatrixScaling( &matScale, 120.0, 120.0, 0.0f );

    // Create a world matrices
    D3DXMatrixRotationY( &matRotateY, Time );
	D3DXMatrixRotationZ( &matRotateZ, -1.58f );
	
	// Create a view matrix
    D3DXMatrixLookAtLH( &matView,
                        &D3DXVECTOR3( 0.0f, 3.0f, 5.0f ),    // The camera position
                        &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),    // The look-at position
                        &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ));   // The up direction

    // Create a projection matrix
    D3DXMatrixPerspectiveFovLH( &matProjection,
                               ( FLOAT )D3DXToRadian( 45 ),                    // Field of view
                               ( FLOAT )SCREEN_WIDTH / ( FLOAT )SCREEN_HEIGHT, // Aspect ratio
                                1.0f,                                          // Near view-plane
                                100.0f );                                      // Far view-plane
	
	// Create an orthographic matrix
	D3DXMatrixOrthoLH(
						&matOrtho,
						( FLOAT )SCREEN_WIDTH,		// Set the width to the window's width
						( FLOAT )SCREEN_HEIGHT,    // Set the height to the window's height
						1.0f,				// The closest an object can be on the depth buffer is 0.0
						100.0f );				// The farthest an object can be on the depth buffer is 1.0
	
	D3D11_DEPTH_STENCIL_DESC depthDisabledStencilDesc;
	// Clear the second depth stencil state before setting the parameters.
	ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc));

	// Now create a second depth stencil state which turns off the Z buffer for 2D rendering.  The only difference is 
	// that DepthEnable is set to false, all other parameters are the same as the other depth stencil state.
	depthDisabledStencilDesc.DepthEnable = false;
	depthDisabledStencilDesc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
	depthDisabledStencilDesc.DepthFunc = D3D11_COMPARISON_LESS;
	depthDisabledStencilDesc.StencilEnable = true;
	depthDisabledStencilDesc.StencilReadMask = 0xFF;
	depthDisabledStencilDesc.StencilWriteMask = 0xFF;
	depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_INCR;
	depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
	depthDisabledStencilDesc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_DECR;
	depthDisabledStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
	depthDisabledStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;


    // Load the matrices into the constant buffer
   // cBuffer.Final =    matScale * matTranslate[0] * matRotateY * matRotateZ * matView * matOrtho;//matProjection;
   // cBuffer.Rotation = matRotateY;
	 cBuffer.Final =    matTranslate[0] * matScale * matRotateY * matRotateZ * matView * matOrtho;//matProjection;
     cBuffer.Rotation = matRotateY * matRotateZ;
	


    // Set the various states
    devcon->RSSetState( pRS );
    devcon->PSSetSamplers( 0, 1, &pSS );
    devcon->OMSetBlendState( pBS, 0, 0xffffffff );
	

    // Clear the back buffer to a deep blue
    devcon->ClearRenderTargetView( backbuffer, D3DXCOLOR( 0.0f,0.0f,0.0f,1.0f));//0.0f, 0.2f, 0.4f, 1.0f ));

    // Clear the depth buffer
    devcon->ClearDepthStencilView( zbuffer, D3D11_CLEAR_DEPTH, 1.0f, 0 );

        // Select which vertex buffer to display
        UINT stride = sizeof( VERTEX );
        UINT offset = 0;
        devcon->IASetVertexBuffers( 0, 1, &pVBuffer, &stride, &offset );
        devcon->IASetIndexBuffer( pIBuffer, DXGI_FORMAT_R32_UINT, 0 );

        // Select which primtive type we are using
        devcon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

		
		// Draw Our sprites here
//.........这里部分代码省略.........
开发者ID:cam01589,项目名称:3DProg,代码行数:101,代码来源:WinMain.cpp


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