一个关于DirectX 变换的问题(进者有分)
我下载了DirectX 9的SDK,安装完毕后在Microsoft DirectX 9.0 SDK (December 2004)\Samples\C++\Direct3D\Tutorials\Tut02_Vertices有一个如何绘制三角形的例子以及Tut03_Matrices如何设置变换矩阵。但是我看完第二个例子后,想直接在上面增加变换矩阵即
void SetMatrix()
{
HRESULT result;
D3DXMATRIXA16 matWorld;
D3DXMatrixTranslation(&matWorld, 50, 50, 0);
result = g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);
assert(result == D3D_OK);
D3DXMATRIXA16 matView;
D3DXVECTOR3 vEyePt(0, 0, 6);
D3DXVECTOR3 vLookatPt(0, 0, -5);
D3DXVECTOR3 vUpVec(0, 1, 0);
D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
在绘制函数里面加上了对SetMatrix的调用
VOID Render()
{
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
SetMatrix();
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2);
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
困扰我的就是不管我怎么设置这些变换矩阵,最终的显示结果都一样好像就没有设置过这些变换一样,我想请问大虾我哪里做错了或者少添加了什么东西?