本文整理汇总了C++中LPD3DXMESH::GetIndexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXMESH::GetIndexBuffer方法的具体用法?C++ LPD3DXMESH::GetIndexBuffer怎么用?C++ LPD3DXMESH::GetIndexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPD3DXMESH
的用法示例。
在下文中一共展示了LPD3DXMESH::GetIndexBuffer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ComputeNormalVector
bool CEntity::ComputeNormalVector(
LPD3DXMESH _pMesh, D3DXVECTOR3& _vNormal, D3DXVECTOR3& _vCol, CEntity* target)
{
BOOL isHit = false;
DWORD dwFaceIndex = 0;
float fDist = 0;
LPD3DXBUFFER ppAllhit;
DWORD pCountOfHits;
D3DXVECTOR3 vPos = m_vPos - target->GetPos();
D3DXVECTOR3 vtar = (-vPos);
D3DXVec3Normalize( &vtar, &vtar);
D3DXIntersect( _pMesh, &vPos, &vtar, &isHit,
&dwFaceIndex, NULL, NULL, &fDist, &ppAllhit, &pCountOfHits );
if ( !isHit || fDist > GetSize() )
return false;// Ãæµ¹ÀÌ ¾È‰ç°Å³ª °Å¸®°¡ ¸Ö´Ù¸é ¸®ÅÏ;
LPDIRECT3DVERTEXBUFFER9 pVB;
LPDIRECT3DINDEXBUFFER9 pIB;
_pMesh->GetVertexBuffer(&pVB);
_pMesh->GetIndexBuffer( &pIB );
WORD* pIndices;
D3DVERTEX* pVertices;
pIB->Lock( 0, 0, (void**)&pIndices, 0 );
pVB->Lock( 0, 0,(void**)&pVertices, 0);
D3DXVECTOR3 v0 = pVertices[pIndices[3*dwFaceIndex+0]].vPos;
D3DXVECTOR3 v1 = pVertices[pIndices[3*dwFaceIndex+1]].vPos;
D3DXVECTOR3 v2 = pVertices[pIndices[3*dwFaceIndex+2]].vPos;
D3DXPLANE plane;
D3DXPlaneFromPoints( &plane, &v0, &v1, &v2);
_vCol = (v0 + v1 + v2)/3.f;
_vCol += target->GetPos();
_vNormal.x = plane.a;
_vNormal.y = plane.b;
_vNormal.z = plane.c;
#ifdef _DEBUG
//Ãæµ¹ÁöÁ¡ Ç¥½Ã
_SINGLE(CDebug)->AddPosMark( _vCol, COLOR_BLACK);
#endif
pVB->Unlock();
pIB->Unlock();
Safe_Release(pVB);
Safe_Release(pIB);
return true;
}
示例2: DrawMeshContainer
/**
* \brief Called to render a mesh
* \param device - the Direct3D device object
* \param meshContainerBase - the mesh container
* \param frameBase - frame containing the mesh
* \author Keith Ditchburn \date 18 July 2005
*/
void CXFileEntity::DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase)
{
DWORD attrSize = 0;
// Cast to our extended frame type
D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase;
// Cast to our extended mesh container
D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase;
// Set the world transform
m_d3dDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix);
unsigned int pass;
if (effect) {
effect->SetMatrix("worldmat",&frame->exCombinedTransformationMatrix);
effect->Begin(&pass,0);
effect->BeginPass(0);
}
// Loop through all the materials in the mesh rendering each subset
for (unsigned int iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++)
{
// use the material in our extended data rather than the one in meshContainer->pMaterials[iMaterial].MatD3D
//m_d3dDevice->SetMaterial( &meshContainer->exMaterials[iMaterial] );
//m_d3dDevice->SetTexture( 0, meshContainer->exTextures[iMaterial] );
// Select the mesh to draw, if there is skin then use the skinned mesh else the normal one
LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh;
// Finally Call the mesh draw function
//pDrawMesh->DrawSubset(iMaterial);
pDrawMesh->GetVertexBuffer(&vb.vb);
pDrawMesh->GetIndexBuffer(&ib.ib);
//D3DVERTEXELEMENT9 pDecl[MAX_FVF_DECL_SIZE];
//pDrawMesh->GetDeclaration(pDecl);
//renderSystem->CreateVertexDeclaration(&pDecl[0],&vb.declaration);
// Получение данных о количестве вершин, индексов и полигонов
dwNumVerticies = pDrawMesh->GetNumVertices();
dwNumIndecies = pDrawMesh->GetNumFaces()*3;
dwNumFaces = pDrawMesh->GetNumFaces();
vb.vertexSize = (short)pDrawMesh->GetNumBytesPerVertex();
renderSystem->DrawIndexedPrimitive(vb,0,dwNumVerticies,ib,0,dwNumFaces);
}
if (effect) {
effect->EndPass();
effect->End();
}
}
示例3: checkPick
//------------------------------------------------------------------------------
//this is a check function
//------------------------------------------------------------------------------
void TriPickDemo::checkPick(LPD3DXMESH mesh, D3DXMATRIX matWorld)
{
HRESULT hr;
D3DXMATRIX mWorldViewProjection;
mWorldViewProjection = matWorld * g_Camera->viewProj();
HR(m_FX->SetTechnique("RenderScene"));
// send matrix to shader
HR(m_FX->SetMatrix("g_mWorldViewProjection", &mWorldViewProjection));
HR(m_FX->SetMatrix("g_mWorld", &matWorld));
UINT uPasses;
V(m_FX->Begin(&uPasses, 0));
g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
V(m_FX->BeginPass(0));
//get select ray
D3DXVECTOR3 originW(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 dirW(0.0f, 0.0f, 0.0f);
if (gDInput->mouseButtonDown(0))
{
getWorldPickingRay(originW, dirW, matWorld);
LPD3DXMESH pMesh;
mesh->CloneMeshFVF(D3DXMESH_MANAGED, D3DVERTEX::FVF, g_pDevice, &pMesh);
BOOL hit = 0;
DWORD faceIndex = -1;
float u = 0.0f;
float v = 0.0f;
float dist = 0.0f;
ID3DXBuffer* allhits = 0;
DWORD numHits = 0;
HR(D3DXIntersect(pMesh, &originW, &dirW, &hit,
&faceIndex, &u, &v, &dist, &allhits, &numHits));
SAFE_RELEASE(allhits);
//if hit
if (hit)
{
IDirect3DVertexBuffer9* vb = 0;
IDirect3DIndexBuffer9* ib = 0;
HR(pMesh->GetVertexBuffer(&vb));
HR(pMesh->GetIndexBuffer(&ib));
HR(g_pDevice->SetIndices(ib));
HR(g_pDevice->SetFVF(D3DVERTEX::FVF));
HR(g_pDevice->SetStreamSource(0, vb, 0, sizeof(D3DVERTEX)));
//render hit surface
HR(g_pDevice->DrawIndexedPrimitive(
D3DPT_TRIANGLELIST, 0, 0, pMesh->GetNumVertices(), faceIndex * 3, 1))
g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
SAFE_RELEASE(vb);
SAFE_RELEASE(ib);
SAFE_RELEASE(pMesh);
}
}
HR(m_FX->EndPass());
HR(m_FX->End());
}
示例4: DrawMesh
HRESULT EVERYMODULE::DrawMesh(LPD3DXMESH newmesh, UINT EPointSize)
{
if(!Mesh)
return E_FAIL;
HRESULT att=S_OK;
LPDIRECT3DVERTEXBUFFER9 vertexbuffer;
LPDIRECT3DINDEXBUFFER9 indexbuffer;
if(newmesh==NULL)
{
if(CreateAttrib==1)
{
Mesh->GetVertexBuffer(&vertexbuffer);
d3ddevice->SetStreamSource(0, vertexbuffer, 0, EachPointSize);
if(VertexShader && Declaration)
{
d3ddevice->SetVertexDeclaration(Declaration);
d3ddevice->SetVertexShader(VertexShader);
}
else
{
// d3ddevice->SetVertexDeclaration(NULL);
d3ddevice->SetVertexShader(NULL);
d3ddevice->SetFVF(m_FVF);
}
d3ddevice->SetMaterial(&Material);
d3ddevice->BeginScene();
if(FAILED(d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, VertexNum-2)))
att=E_FAIL;
d3ddevice->EndScene();
}
else if(CreateAttrib==2)
{
Mesh->GetVertexBuffer(&vertexbuffer);
Mesh->GetIndexBuffer(&indexbuffer);
d3ddevice->SetStreamSource(0, vertexbuffer, 0, EachPointSize);
d3ddevice->SetIndices(indexbuffer);
if(VertexShader && Declaration)
{
d3ddevice->SetVertexDeclaration(Declaration);
d3ddevice->SetVertexShader(VertexShader);
}
else
{
// d3ddevice->SetVertexDeclaration(NULL);
d3ddevice->SetVertexShader(NULL);
d3ddevice->SetFVF(m_FVF);
}
d3ddevice->SetMaterial(&Material);
d3ddevice->BeginScene();
if(FAILED(d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, VertexNum, 0, IndexVertexNum/3)))
att=E_FAIL;
d3ddevice->EndScene();
}
}
else
{
if(CreateAttrib==1)
{
newmesh->GetVertexBuffer(&vertexbuffer);
d3ddevice->SetStreamSource(0, vertexbuffer, 0, EPointSize);
if(VertexShader && Declaration)
{
d3ddevice->SetVertexDeclaration(Declaration);
d3ddevice->SetVertexShader(VertexShader);
}
else
{
// d3ddevice->SetVertexDeclaration(NULL);
d3ddevice->SetVertexShader(NULL);
d3ddevice->SetFVF(m_FVF);
}
d3ddevice->SetMaterial(&Material);
d3ddevice->BeginScene();
if(FAILED(d3ddevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, VertexNum-2)))
att=E_FAIL;
d3ddevice->EndScene();
}
else if(CreateAttrib==2)
{
newmesh->GetVertexBuffer(&vertexbuffer);
newmesh->GetIndexBuffer(&indexbuffer);
d3ddevice->SetStreamSource(0, vertexbuffer, 0, EPointSize);
d3ddevice->SetIndices(indexbuffer);
if(VertexShader && Declaration)
{
d3ddevice->SetVertexDeclaration(Declaration);
d3ddevice->SetVertexShader(VertexShader);
}
else
{
// d3ddevice->SetVertexDeclaration(NULL);
d3ddevice->SetVertexShader(NULL);
d3ddevice->SetFVF(m_FVF);
}
d3ddevice->SetMaterial(&Material);
d3ddevice->BeginScene();
if(FAILED(d3ddevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, VertexNum, 0, IndexVertexNum/3)))
att=E_FAIL;
d3ddevice->EndScene();
//.........这里部分代码省略.........
示例5: InitGeometry
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Load the mesh and build the material and texture arrays
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
LPD3DXBUFFER pD3DXMtrlBuffer;
LPDIRECT3DVERTEXBUFFER9 pMeshSourceVB;
LPDIRECT3DINDEXBUFFER9 pMeshSourceIB;
D3DVERTEX* pSrc;
D3DVERTEX* pDst;
// load the textures we are going to be using
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"cartoonpallet-white-to-black.bmp", &g_pTexture ) ) )
MessageBox(NULL, L"Texture Load Problem", NULL, NULL);
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"cartoonpallet-black-to-white.bmp", &g_pTexture2 ) ) )
MessageBox(NULL, L"Texture Load Problem", NULL, NULL);
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"marble.bmp", &marbleTexture ) ) )
MessageBox(NULL, L"Texture Load Problem", NULL, NULL);
if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, L"background.jpg", &backgroundTexture ) ) )
MessageBox(NULL, L"Texture Load Problem", NULL, NULL);
// Load the mesh from the specified file
if( FAILED( D3DXLoadMeshFromX( L"skull.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL,
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials,
&g_pMesh ) ) )
g_pd3dDevice->SetFVF(D3DFVF_D3DVERTEX );
g_dwNumVertices = g_pMesh->GetNumVertices();
g_dwNumFaces = g_pMesh->GetNumFaces();
//Clone the mesh to set the FVF
LPD3DXMESH pTempSysMemMesh = NULL;
if( FAILED( g_pMesh->CloneMeshFVF( D3DXMESH_SYSTEMMEM, D3DFVF_D3DVERTEX,
g_pd3dDevice, &pTempSysMemMesh ) ) )
MessageBox(NULL,L"Mesh clone problem",NULL,NULL);
g_pMesh->Release();
g_pMesh = pTempSysMemMesh;
//Compute normals in case the meshes have them
if( g_pMesh )
D3DXComputeNormals( g_pMesh, NULL );
//Meshes cloned
if( FAILED(g_pd3dDevice->CreateVertexBuffer( g_dwNumVertices * sizeof(D3DVERTEX),
D3DUSAGE_WRITEONLY, 0, D3DPOOL_MANAGED,
&g_pMeshVB, NULL )))
MessageBox(NULL,L"Vertex buffer create problem",NULL,NULL);
if( FAILED(g_pd3dDevice->CreateIndexBuffer( g_dwNumFaces * 3 * sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED,
&g_pMeshIB, NULL )))
MessageBox(NULL,L"Index buffer create problem",NULL,NULL);
g_pMesh->GetVertexBuffer(&pMeshSourceVB);
g_pMeshVB->Lock( 0, 0, (void**)&pDst, 0 );
pMeshSourceVB->Lock( 0, 0, (void**)&pSrc, 0 );
memcpy( pDst, pSrc, g_dwNumVertices * sizeof(D3DVERTEX) );
g_pMeshVB->Unlock();
pMeshSourceVB->Unlock();
pMeshSourceVB->Release();
g_pMesh->GetIndexBuffer(&pMeshSourceIB);
g_pMeshIB->Lock( 0, 0, (void**)&pDst, 0 );
pMeshSourceIB->Lock( 0, 0, (void**)&pSrc, 0 );
memcpy( pDst, pSrc, g_dwNumFaces * 3 * sizeof(WORD));
g_pMeshIB->Unlock();
pMeshSourceIB->Unlock();
pMeshSourceIB->Release();
//// Done with the material buffer
pD3DXMtrlBuffer->Release();
return S_OK;
}