显卡渲染时,要先擦后画
void CD3DInit::Render() { if(NULL == g_pD3DDevice) return; //--将填充后台缓冲区置为黑色 g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0); g_pD3DDevice->BeginScene(); //--开始通知显卡要进行渲染 //SetItem(); g_Texture->Render(); g_pD3DDevice->EndScene(); //--结束图形的渲染 g_pD3DDevice->Present(NULL, NULL, NULL, NULL);//--翻页 }
if (SUCCEEDED(this->InitD3D(hWnd))) { //do something }
物体绕指定轴旋转
void CTexture::setupRotation() { D3DXMATRIX matWorld, matTrans, matTrans1; D3DXMatrixTranslation(&matTrans, 0,0, 3.0f); D3DXMatrixRotationY(&matWorld, timeGetTime()/1000.0f); D3DXMatrixTranslation(&matTrans1, 0,0, 5.0f); D3DXMatrixMultiply(&matWorld,&matTrans,&matWorld ); D3DXMatrixMultiply(&matWorld,&matWorld,&matTrans1 ); m_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); }
恢复矩阵设置
void CTexture::deafultMatrix() { D3DXMATRIX matWorld, matTrans, matTrans1; D3DXMatrixTranslation(&matTrans, 0,0, 0.0f); D3DXMatrixRotationY(&matWorld, 0.0f); D3DXMatrixTranslation(&matTrans1, 0,0, 0.0f); D3DXMatrixMultiply(&matWorld,&matTrans,&matWorld ); D3DXMatrixMultiply(&matWorld,&matWorld,&matTrans1 ); m_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); }