|
|
That is special case for my research about Adpative Shadow Maps.
I must do that first. But I encounter a problem the result is not like the one I want. I think maybe my code has some mistakes. Could somebody take some time to my source code.
- struct ASM_VERTEX
- {
- D3DXVECTOR3 p, n;
- float u;
- float v;
- };
-
- ASM_VERTEX* m_pVertices;
- DWORD m_dwNumFaces;
- WORD* pIndices;
- LPD3DXMESH pMesh;
- DWORD nFVF;
- DWORD dwNumFaces;
- nFVF=m_MeshShip.GetLocalMesh()->GetFVF();//D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1
- FAILED(m_MeshShip.GetLocalMesh()->CloneMeshFVF(
- D3DXMESH_SYSTEMMEM,
- nFVF,
- pd3dDevice,
- &pMesh
- ));
- dwNumFaces=pMesh->GetNumFaces();
- m_dwNumFaces = 4*dwNumFaces;
- ASM_VERTEX * pVertices;
- D3DXVECTOR3 *vNormal;
-
- m_pVertices = new ASM_VERTEX[3*m_dwNumFaces];
- vNormal = new D3DXVECTOR3[dwNumFaces];
- // lock buffers
- pMesh->LockVertexBuffer( 0L, (LPVOID*)&pVertices );
- pMesh->LockIndexBuffer ( 0L, (LPVOID*)&pIndices );
- for(DWORD i=0; i< dwNumFaces; i++ )
- {
- D3DXVECTOR3 v0 = pVertices[pIndices[3*i+0]].p;
- D3DXVECTOR3 v1 = pVertices[pIndices[3*i+1]].p;
- D3DXVECTOR3 v2 = pVertices[pIndices[3*i+2]].p;
- // calculate normal
- D3DXVECTOR3 vCross1(v1-v0);
- D3DXVECTOR3 vCross2(v2-v1);
- D3DXVec3Cross( &vNormal[i], &vCross1, &vCross2 );
- D3DXVec3Normalize(&vNormal[i],&vNormal[i]);
- // store a face
- m_pVertices[pIndices[3*i+0]].p = v0;
- m_pVertices[pIndices[3*i+1]].p = v1;
- m_pVertices[pIndices[3*i+2]].p = v2;
- m_pVertices[pIndices[3*i+0]].n = vNormal[i];
- m_pVertices[pIndices[3*i+1]].n = vNormal[i];
- m_pVertices[pIndices[3*i+2]].n = vNormal[i];
- }
- pMesh->UnlockVertexBuffer();
- pMesh->UnlockIndexBuffer();
- pMesh->Release();
- //render
- pd3dDevice->SetFVF(nFVF);
- pd3dDevice->DrawPrimitiveUP(
- D3DPT_TRIANGLELIST,
- m_dwNumFaces,
- m_pVertices,
- sizeof(ASM_VERTEX)
- );
- SAFE_DELETE(m_pVertices);
- SAFE_DELETE(vNormal);
复制代码
I print the result of right and error as below website:
http://www.game.csie.ndhu.edu.tw/~akira/else/space_ok.jpg
http://www.game.csie.ndhu.edu.tw/~akira/else/space_err.jpg |
|