本文整理汇总了C++中LPDIRECT3DINDEXBUFFER9::GetDesc方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DINDEXBUFFER9::GetDesc方法的具体用法?C++ LPDIRECT3DINDEXBUFFER9::GetDesc怎么用?C++ LPDIRECT3DINDEXBUFFER9::GetDesc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DINDEXBUFFER9
的用法示例。
在下文中一共展示了LPDIRECT3DINDEXBUFFER9::GetDesc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateMeshContainer
MeshContainer* XFileLoader::CreateMeshContainer()
{
HRESULT hr;
MeshContainer* meshContainer = NULL;
Graphics* graphics = Graphics::GetInstance();
IDirect3DDevice9Ptr pD3DDevice = graphics->GetDirect3DDevice();
if( !(m_pD3DMesh->GetFVF() & D3DFVF_NORMAL) )
{
LPD3DXMESH tmpMesh = NULL;
// 柔軟な頂点フォーマット (FVF) コードを使ってメッシュのコピーを作成する
hr = m_pD3DMesh->CloneMeshFVF(
m_pD3DMesh->GetOptions(),
m_pD3DMesh->GetFVF() | D3DFVF_NORMAL,
pD3DDevice,
&tmpMesh); // ←ここにコピー
if(FAILED(hr))
{
goto exit;
}
// メッシュに含まれる各頂点の法線を計算して、設定する
//D3DXComputeNormals( tmpMesh, reinterpret_cast<DWORD*>(pAdjacencyBuf->GetBufferPointer()) );
D3DXComputeNormals( tmpMesh, NULL );
m_pD3DMesh->Release();
m_pD3DMesh = tmpMesh;
}
D3DVERTEXELEMENT9 pDecl[MAX_FVF_DECL_SIZE];
hr = m_pD3DMesh->GetDeclaration(pDecl);
if( FAILED(hr) )
{
goto exit;
}
DWORD vertexNum = m_pD3DMesh->GetNumVertices();
DWORD faceNum = m_pD3DMesh->GetNumFaces();
DWORD attrNum = 0;
m_pD3DMesh->GetAttributeTable(NULL, &attrNum);
DWORD size = m_pD3DMesh->GetNumBytesPerVertex();
BYTE* pD3DVertice = NULL;
m_pD3DMesh->LockVertexBuffer( 0,(LPVOID*)&pD3DVertice );
sVertex* vertices = new sVertex[vertexNum];
for( DWORD vertIdx = 0;vertIdx<vertexNum;vertIdx++ )
{
sVertex* vertex = &vertices[vertIdx];
vertex->uv = D3DXVECTOR2(0.0f,0.0f);
vertex->color = 0xFFFFFFFF;
for( DWORD i=0;i<MAX_FVF_DECL_SIZE;i++ )
{
D3DVERTEXELEMENT9& decl = pDecl[i];
if( decl.Stream==0xFF )
{
break;
}
switch( decl.Usage )
{
case D3DDECLUSAGE_POSITION:
vertex->position = *(D3DXVECTOR3*)(pD3DVertice+vertIdx*size+decl.Offset);
vertex->position = vertex->position * m_scale;
break;
case D3DDECLUSAGE_NORMAL:
vertex->normal = *(D3DXVECTOR3*)(pD3DVertice+vertIdx*size+decl.Offset);
break;
case D3DDECLUSAGE_TEXCOORD:
vertex->uv = *(D3DXVECTOR2*)(pD3DVertice+vertIdx*size+decl.Offset);
break;
case D3DDECLUSAGE_COLOR:
vertex->color = *(DWORD*)(pD3DVertice+vertIdx*size+decl.Offset);
break;
}
}
}
m_pD3DMesh->UnlockVertexBuffer();
LPDIRECT3DINDEXBUFFER9 pIndexBuffer = NULL;
m_pD3DMesh->GetIndexBuffer( &pIndexBuffer );
D3DINDEXBUFFER_DESC desc;
pIndexBuffer->GetDesc( &desc );
pIndexBuffer->Release();
DWORD* indices = new DWORD[faceNum*3];
if( desc.Format==D3DFMT_INDEX16 )
{
WORD* pD3DIndices = NULL;
m_pD3DMesh->LockIndexBuffer(0,(LPVOID*)&pD3DIndices );
for( DWORD i=0;i<faceNum*3;i++ )
//.........这里部分代码省略.........
示例2: checkIntersect
bool GStillEntity::checkIntersect ( const D3DXVECTOR4& vPos, /*世界坐标系中的点 */ const D3DXVECTOR4& vDir, /*世界坐标系中的向量 */ bool bInsectInfo /*是 裥枰鲎残畔?*/ )
{
HRESULT hr = S_FALSE;
//将Pos和Dir转换到物体本地坐标系中
D3DXMATRIX matWorld = getTrans()->getLocalD3D();
D3DXMatrixInverse ( &matWorld, NULL, &matWorld );
D3DXVec4Transform ( ( D3DXVECTOR4 * ) &vDir, ( D3DXVECTOR4 * ) &vDir, &matWorld );
D3DXVec3Normalize ( ( D3DXVECTOR3* ) &vDir, ( D3DXVECTOR3* ) &vDir );
D3DXVec4Transform ( ( D3DXVECTOR4 * ) &vPos, ( D3DXVECTOR4 * ) &vPos, &matWorld );
if ( mMeshForInsect == NULL )
{
recreateInsectMesh();
}
BOOL bHit = FALSE;
hr = D3DXIntersect (
mMeshForInsect, ( D3DXVECTOR3* ) &vPos, ( D3DXVECTOR3* ) &vDir, &bHit,
&m_InsectInfo.dwFaceIndex, &m_InsectInfo.u, &m_InsectInfo.v, &m_InsectInfo.fDist,
NULL, NULL
);
mNodeState.setBit ( eObjState_Picked, ( bool ) bHit );
dDebugMsgBox ( hr, "碰撞失败!" );
if ( FAILED ( hr ) )
{
return false;
}
if ( bInsectInfo && mNodeState[eObjState_Picked] )
{
D3DXVECTOR3 v[3];
DWORD dwIndex[3];
//先要获取索引缓冲区格式
LPDIRECT3DINDEXBUFFER9 pI = NULL;
mMeshForInsect->GetIndexBuffer ( &pI );
D3DINDEXBUFFER_DESC indexDesc;
dMemoryZero ( &indexDesc, sizeof ( D3DINDEXBUFFER_DESC ) );
if ( pI != NULL )
{
pI->GetDesc ( &indexDesc );
}
if ( indexDesc.Format== D3DFMT_INDEX16 )
{
WORD *pIndexData16;
hr = mMeshForInsect->LockIndexBuffer ( D3DLOCK_READONLY, ( void** ) &pIndexData16 );
dwIndex[0] = pIndexData16[m_InsectInfo.dwFaceIndex * 3 + 0];
dwIndex[1] = pIndexData16[m_InsectInfo.dwFaceIndex * 3 + 1];
dwIndex[2] = pIndexData16[m_InsectInfo.dwFaceIndex * 3 + 2];
}
else
{
DWORD *pIndexData32;
hr = mMeshForInsect->LockIndexBuffer ( D3DLOCK_READONLY, ( void** ) &pIndexData32 );
dwIndex[0] = pIndexData32[m_InsectInfo.dwFaceIndex * 3 + 0];
dwIndex[1] = pIndexData32[m_InsectInfo.dwFaceIndex * 3 + 1];
dwIndex[2] = pIndexData32[m_InsectInfo.dwFaceIndex * 3 + 2];
}
mMeshForInsect->UnlockIndexBuffer();
D3DXVECTOR3 *pVertexData;
hr = mMeshForInsect->LockVertexBuffer ( D3DLOCK_READONLY, ( void** ) &pVertexData );
v[0] = pVertexData[dwIndex[0]];
v[1] = pVertexData[dwIndex[1]];
v[2] = pVertexData[dwIndex[2]];
mMeshForInsect->UnlockVertexBuffer();
D3DXVECTOR4 vNormal ( ZEROFLOAT, ZEROFLOAT, ZEROFLOAT, ZEROFLOAT );
D3DXVECTOR4 vHitPos ( ZEROFLOAT, ZEROFLOAT, ZEROFLOAT, ZEROFLOAT );
D3DXVECTOR3 vTmp1, vTmp2;
vTmp1 = v[1] - v[0];
vTmp2 = v[2] - v[0];
vHitPos = ( D3DXVECTOR4 ) v[0] + m_InsectInfo.u * ( D3DXVECTOR4 ) vTmp1 + m_InsectInfo.v * ( D3DXVECTOR4 ) vTmp2;
vHitPos.w = 1;
updateWorld ();
D3DXVec4Transform ( &vHitPos, &vHitPos, &getTrans()->getLocalD3D() );
m_InsectInfo.vHitPos = D3DXVECTOR3 ( vHitPos.x, vHitPos.y, vHitPos.z );
D3DXVec3Cross ( ( D3DXVECTOR3* ) &vNormal, &vTmp1, &vTmp2 );
//.........这里部分代码省略.........
示例3: InititialisePhysics
//.........这里部分代码省略.........
}
//if (dwFVF & D3DFVF_NORMAL)
//{
// //don't care the NORMAL data
// pPointer += sizeof(D3DVECTOR);
//}
//if (dwFVF & D3DFVF_TEX1)
//{
// pPointer += 8;
//}
pPointer += dwBytes - sizeof(D3DVECTOR);
}
pVB->Unlock();
pVB->Release();
//
triMesh.vertices = verts;
neTriangle * tri = new neTriangle[triMesh.triangleCount];
s32 * triindex = new s32[triMesh.triangleCount * 3];
//
LPDIRECT3DINDEXBUFFER9 pIB;
lpterrainD3Dmesh->GetIndexBuffer(&pIB);
D3DINDEXBUFFER_DESC kDesc;
pIB->GetDesc(&kDesc);
dwBytes = 0;
if (kDesc.Format & D3DFMT_INDEX16)
{
dwBytes = 2 * sizeof(byte);
}
else if (kDesc.Format & D3DFMT_INDEX32)
{
dwBytes = 4 * sizeof(byte);
}
pIB->Lock(0, 0, (void**)&pBuffer, 0);
pPointer = pBuffer;
while ((pPointer - pBuffer) < kDesc.Size)
{
if (dwBytes == 2*sizeof(byte))
{
//16bit
triindex[(pPointer-pBuffer)/dwBytes] = *((s16*)pPointer);
}
else if (dwBytes == 4*sizeof(byte))
{
//32bit
triindex[(pPointer-pBuffer)/dwBytes] = *((s32*)pPointer);
}
pPointer += dwBytes;
}
pIB->Unlock();
pIB->Release();
示例4: DeallocateGeometry
//.........这里部分代码省略.........
pd3dDevice->Release();
// Failure
return false;
}
// Iterate through all of the materials and copy vertex/index data, and assign material
// information for the mesh.
for (DWORD subset = 0; subset < subsets; subset++)
{
// Use D3DX to convert this subset into a nicely indexed form
DWORD numStripIndices;
LPDIRECT3DINDEXBUFFER9 pSubsetIB;
if (APP_ERROR(D3DXConvertMeshSubsetToSingleStrip(d3dxMesh, subset, D3DXMESH_SYSTEMMEM, &pSubsetIB, &numStripIndices))("Couldn't convert mesh subset into indexable strip"))
{
// Erase any geometry we made
DeallocateGeometry(subsetGeometry);
// Get rid of the mesh
d3dxMesh->UnlockVertexBuffer();
d3dxMesh->Release();
// Free our device
pd3dDevice->Release();
// Return the error
return false;
}
D3DINDEXBUFFER_DESC desc;
GeometryIndex* pXIndices = NULL;
// Check the format of the indices and lock the strip index buffer
if (APP_ERROR(pSubsetIB->GetDesc(&desc))("Couldn't get .X mesh IB desc") || (desc.Format != D3DFMT_GEOMETRYINDEX) ||
APP_ERROR(pSubsetIB->Lock(0, 0, (VOID**)&pXIndices, D3DLOCK_READONLY))("Unable to lock the .X index buffer"))
{
// Erase any geometry we made
DeallocateGeometry(subsetGeometry);
// Get rid of the mesh
pSubsetIB->Release();
d3dxMesh->UnlockVertexBuffer();
d3dxMesh->Release();
// Free our device
pd3dDevice->Release();
// Error!
return false;
}
// This table pairs an index from the .X file to an index in the buffer that
// holds the vertices for this subset
XIndicesTable xIndicesTable;
// For each of the indices in the strip, puts its vertex ID into the indices
// table. Use the counter to determine which vertex this is.
{
GeometryIndex vertexCounter = 0;
for (DWORD e = 0; e < numStripIndices; ++e)
{
// Insert the entry [x-mesh index, subset index] into the table
XIndicesTableInsertResult result = xIndicesTable.insert(XIndicesEntry(pXIndices[e], vertexCounter));
// If the result was successful (this isn't a duplicated X-mesh index) increment the vertex counter
if (result.second)