2024年1月10日发(作者:)
{ D3DXCreateTextureFromFile(m_pD3DDevice9,_T(""),&m_pD3DTexture9);
CUSTOMVERTEX1 vertices1[32]; vertices1[0].position=D3DXVECTOR3(-1.0f,0.0f,0.0f); vertices1[0].normal=D3DXVECTOR3(-1.0f,0.0f,0.0f); vertices1[0].fu=0.0f; vertices1[0].fv=0.5f; for (int i=1;i<32;i++) { float theat=(i-1)*2*D3DX_PI/30.0f; vertices1[i].position=D3DXVECTOR3(1.0f,sinf(theat),cosf(theat)); vertices1[i].normal=D3DXVECTOR3(0.0f,sinf(theat),cosf(theat)); float m=sqrtf(5.0f); float beta=(0.5f-1.0f/m+(i-1.0f)/15.0f/m)*D3DX_PI; vertices1[i].fu=0.5*sinf(beta); vertices1[i].fv=0.5-0.5*cosf(beta); } m_pD3DDevice9->CreateVertexBuffer( sizeof(vertices1), 0, D3DFVF_CUSTOMVERTEX1, D3DPOOL_DEFAULT, &m_pVB1, NULL); VOID* pVertices=NULL; m_pVB1->Lock( 0, sizeof(vertices1), &pVertices, 0); memcpy(pVertices,vertices1,sizeof(vertices1)); m_pVB1->Unlock(); CUSTOMVERTEX2 vertices2[32]; vertices2[0].position=D3DXVECTOR3(1.0f,0.0f,0.0f); vertices2[0].normal=D3DXVECTOR3(1.0f,0.0f,0.0f); for (int i=1;i<32;i++) { float theat=(i-1)*2*D3DX_PI/30.0f; vertices2[i].position=vertices1[32-i].position; vertices2[i].normal=D3DXVECTOR3(1.0f,0.0f,0.0f); } m_pD3DDevice9->CreateVertexBuffer( sizeof(vertices2), 0, D3DFVF_CUSTOMVERTEX2, D3DPOOL_DEFAULT, &m_pVB2, NULL); m_pVB2->Lock( 0, sizeof(vertices2), &pVertices,
0); memcpy(pVertices,vertices2,sizeof(vertices2)); m_pVB2->Unlock();}13. 设置左边变换void CD3DDlg::SetupMatrices(void){ D3DXMATRIX matWorld; float angle=m_nRotateY*D3DX_PI/180; D3DXMatrixRotationY(&matWorld,angle ); m_pD3DDevice9->SetTransform(D3DTS_WORLD,&matWorld); D3DXVECTOR3 eye(0.0f,3.0f,-5.0f); D3DXVECTOR3 lookAt(0.0f,0.0f,0.0f); D3DXVECTOR3 up(0.0f,1.0f,0.0f); D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView,&eye,&lookAt,&up); m_pD3DDevice9->SetTransform(D3DTS_VIEW,&matView); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH(&matProj,D3DX_PI/4,1.0f,1.0f,100.0f); m_pD3DDevice9->SetTransform(D3DTS_PROJECTION,&matProj);}14. 设置材料1void CD3DDlg::SetMaterial1(void){ D3DMATERIAL9 mtrl; ZeroMemory(&mtrl,sizeof(D3DMATERIAL9)); e.r=t.r=1.0f; e.g=t.g=1.0f; e.b=t.b=1.0f; e.a=t.a=1.0f; m_pD3DDevice9->SetMaterial(&mtrl);}15. 设置材料2void CD3DDlg::SetMaterial2(void){ D3DMATERIAL9 mtrl; ZeroMemory(&mtrl,sizeof(D3DMATERIAL9)); e.r=t.r=1.0f; e.g=t.g=1.0f; e.b=t.b=0.0f; e.a=t.a=1.0f; m_pD3DDevice9->SetMaterial(&mtrl);}
void CD3DDlg::Render(void){ m_pD3DDevice9->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0); m_pD3DDevice9->BeginScene(); SetupMatrices(); SetLight(); SetMaterial1(); m_pD3DDevice9->SetTexture(0,m_pD3DTexture9); m_pD3DDevice9->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE); m_pD3DDevice9->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE); m_pD3DDevice9->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE); m_pD3DDevice9->SetFVF(D3DFVF_CUSTOMVERTEX1); m_pD3DDevice9->SetStreamSource(0,m_pVB1,0,sizeof(CUSTOMVERTEX1)); m_pD3DDevice9->DrawPrimitive(D3DPT_TRIANGLEFAN,0,30); m_pD3DDevice9->SetTexture(0,NULL); m_pD3DDevice9->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DISABLE); SetMaterial2(); m_pD3DDevice9->SetFVF(D3DFVF_CUSTOMVERTEX2); m_pD3DDevice9->SetStreamSource(0,m_pVB2,0,sizeof(CUSTOMVERTEX2)); m_pD3DDevice9->DrawPrimitive(D3DPT_TRIANGLEFAN,0,30); m_pD3DDevice9->EndScene(); m_pD3DDevice9->Present(NULL,NULL,NULL,NULL);}18. 释放资源void CD3DDlg::CleanUp(void){ m_pVB1->Release(); m_pVB2->Release(); m_pD3DTexture9->Release(); m_pD3DDevice9->Release(); m_pD3D9->Release();}19. 终于该公有函数了 初始化


发布评论