本文整理汇总了C++中LPDIRECT3DINDEXBUFFER9类的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DINDEXBUFFER9类的具体用法?C++ LPDIRECT3DINDEXBUFFER9怎么用?C++ LPDIRECT3DINDEXBUFFER9使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPDIRECT3DINDEXBUFFER9类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateIndexBuffer
LPDIRECT3DINDEXBUFFER9 CreateIndexBuffer( LPDIRECT3DDEVICE9 device, OvByte* buffer, OvSize bufsize )
{
if ( device && buffer && bufsize )
{
LPDIRECT3DINDEXBUFFER9 streamBuffer = NULL;
HRESULT hr = device->CreateIndexBuffer
( bufsize
, 0
, D3DFMT_INDEX16
, D3DPOOL_MANAGED
, &streamBuffer
, NULL
);
if ( SUCCEEDED(hr) && streamBuffer )
{
void* copyDest = NULL;
if ( SUCCEEDED(streamBuffer->Lock( 0, bufsize, ©Dest, 0)) && copyDest)
{
memcpy( copyDest, buffer, bufsize );
streamBuffer->Unlock();
return streamBuffer;
}
}
}
return NULL;
}
示例2: GetDevice
LPDIRECT3DINDEXBUFFER9 OvRenderer::CreateIndexStream( void* buffer, UINT stride, UINT count )
{
OvDevice device = GetDevice();
if ( device )
{
LPDIRECT3DINDEXBUFFER9 streamBuffer = NULL;
UINT streamSize = count * stride;
HRESULT hr = device->CreateIndexBuffer
( streamSize
, 0
, D3DFMT_INDEX16
, D3DPOOL_MANAGED
, &streamBuffer
, NULL
);
if ( SUCCEEDED(hr) && streamBuffer )
{
void* copyDest = NULL;
if ( SUCCEEDED(streamBuffer->Lock( 0, streamSize, ©Dest, 0)) && copyDest)
{
memcpy( copyDest, buffer, streamSize );
streamBuffer->Unlock();
return streamBuffer;
}
}
}
return NULL;
}
示例3: D3DXVec3Normalize
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;
}
示例4: minPos
void GdsNode::CreateOctree()
{
RENDER_OBJECT_CONTAINER::iterator it = m_list_RenderObject.begin();
for ( ; it != m_list_RenderObject.end() ; ++it )
{
VOID* pVB;
GdsRenderObject* rendertoken = it->first;
LPDIRECT3DVERTEXBUFFER9 vb = rendertoken->GetVertexBuffer();
if ( SUCCEEDED( vb->Lock( 0 , rendertoken->GetVertexMaxCount() * sizeof( GDSVERTEX ) , (void**)&pVB , 0 ) ) )
{
D3DXVECTOR3 minPos( 0,0,0 );
D3DXVECTOR3 maxPos( 0,0,0 );
for ( int i=0 ; i < rendertoken->GetVertexMaxCount() ; i++ )
{
GDSVERTEX* v = (GDSVERTEX*)pVB + i;
if ( minPos.x > v->p.x )
minPos.x = v->p.x;
if ( minPos.y > v->p.y )
minPos.y = v->p.y;
if ( minPos.z > v->p.z )
minPos.z = v->p.z;
if ( maxPos.x < v->p.x )
maxPos.x = v->p.x;
if ( maxPos.y < v->p.y )
maxPos.y = v->p.y;
if ( maxPos.z < v->p.z )
maxPos.z = v->p.z;
}
m_pOctreeRootNode = NULL;
m_pVert = (GDSVERTEX*)pVB;
if ( m_pOctreeRootNode == NULL )
m_pOctreeRootNode = new Node( rendertoken->GetIndexMaxCount() , minPos , maxPos );
VOID* pI;
LPDIRECT3DINDEXBUFFER9 pIB = rendertoken->GetIndexBuffer();
pIB->Lock( 0 , rendertoken->GetIndexMaxCount() * sizeof( GDSINDEX ) , (void**)&pI , 0 );
memcpy( m_pOctreeRootNode->m_pFace , pI , sizeof( GDSINDEX ) * rendertoken->GetIndexMaxCount() );
pIB->Unlock();
m_pOctreeRootNode->m_iNumOfChild = 0;
build( m_pOctreeRootNode );
}
vb->Unlock();
}
m_bUseOctree = true;
m_iCountOfOctreeNode = 0;
}
示例5: ComputeNormals
void ComputeNormals(LPDIRECT3DVERTEXBUFFER9 vtxBuff, int vtxSize, LPDIRECT3DINDEXBUFFER9 idxBuff, int faceSize)
{
Vertex* vertices;
vtxBuff->Lock( 0, sizeof(Vertex), (void**)&vertices, 0);
WORD *indices = NULL;
idxBuff->Lock(0, 0, (void**)&indices, 0);
for (int i=0; i < faceSize*3; i+=3)
{
Vector3 p1 = vertices[ indices[ i]].p;
Vector3 p2 = vertices[ indices[ i+1]].p;
Vector3 p3 = vertices[ indices[ i+2]].p;
Vector3 v1 = p2 - p1;
Vector3 v2 = p3 - p1;
v1.Normalize();
v2.Normalize();
Vector3 n = v1.CrossProduct(v2);
n.Normalize();
if (vertices[ indices[ i]].n.IsEmpty())
{
vertices[ indices[ i]].n = n;
}
else
{
vertices[ indices[ i]].n += n;
vertices[ indices[ i]].n /= 2.f;
}
if (vertices[ indices[ i+1]].n.IsEmpty())
{
vertices[ indices[ i+1]].n = n;
}
else
{
vertices[ indices[ i+1]].n += n;
vertices[ indices[ i+1]].n /= 2.f;
}
if (vertices[ indices[ i+2]].n.IsEmpty())
{
vertices[ indices[ i+2]].n = n;
}
else
{
vertices[ indices[ i+2]].n += n;
vertices[ indices[ i+2]].n /= 2.f;
}
}
vtxBuff->Unlock();
idxBuff->Unlock();
}
示例6: Graphics
void cSubDivSurf::Draw( matrix4& mat )
{
LPDIRECT3DDEVICE9 lpDevice = Graphics()->GetDevice();
Graphics()->SetWorldMatrix( mat );
HRESULT hr;
// The index buffer
LPDIRECT3DINDEXBUFFER9 pIndexBuffer = 0;
// Create the index buffer
lpDevice->CreateIndexBuffer(
m_nTris * 3 * sizeof( WORD ), // Size in bytes of buffer
D3DUSAGE_WRITEONLY, // Will only be writing to the buffer
D3DFMT_INDEX16, // 16 bit indices
D3DPOOL_DEFAULT, // Default memory pooling
&pIndexBuffer, // Address of the buffer pointer
NULL ); // Reserved. set to NULL
// Pointer to the index buffer data
WORD* pData = 0;
// Lock the index buffer
pIndexBuffer->Lock( 0, 0, (void**)&pData, 0 );
// Copy the index data into the index buffer
CopyMemory( pData, m_d3dTriList, m_nTris * 3 * sizeof( WORD ) );
// Unlock the index buffer
pIndexBuffer->Unlock();
// Tell Direct3D to use the index buffer
lpDevice->SetIndices( pIndexBuffer );
// Attach the vertex buffer to rendering stream 0
lpDevice->SetStreamSource( 0, m_pVertexBuffer, 0, sizeof( sVertex ) );
// Draw the primitive
hr = lpDevice->DrawIndexedPrimitive(
D3DPT_TRIANGLELIST,
0,
0,
m_nVerts,
0,
m_nTris );
if( FAILED( hr ) )
{
DP0("[cSubDivSurf::Draw]: DrawIndexedPrimitive failed!\n");
}
pIndexBuffer->Release();
}
示例7:
HRESULT CameraWorkBase::SetIB( LPDIRECT3DINDEXBUFFER9 _pIB, LPVOID _indices, INT _nIndex, INT _Size )
{
LPVOID pIndices;
if( FAILED( _pIB->Lock( 0, _nIndex * _Size, (VOID**)&pIndices, 0 ) ) )
{
MessageBox( NULL, L"CameraWorkBase::m_pIB->Lock() failed.", NULL, MB_OK );
return E_FAIL;
}
memcpy( pIndices, _indices, _nIndex * _Size );
_pIB->Unlock();
return S_OK;
}
示例8: ConvertVertex
//===============================================
//頂点情報のコンバート
//===============================================
//[input]
// pD3DX9:Direct3Dデバイス
//[return]
// HREULT値
//===============================================
bool CXMesh::ConvertVertex(LPDIRECT3DDEVICE9 pD3DX9)
{
LPD3DXBUFFER pD3DXMtrlBuffer = NULL;
/*Vertex Bufferにコピーする*/
D3DVERTEX* pSrc;
D3DVERTEX* pDest;
LPDIRECT3DINDEXBUFFER9 pSrcIndex;
WORD* pISrc;
WORD* pIDest;
/*VertexBuffer情報取得*/
LPDIRECT3DVERTEXBUFFER9 pVB;
MeshData.pMesh->GetVertexBuffer(&pVB);
D3DVERTEXBUFFER_DESC Desc;
pVB->GetDesc( &Desc );
DWORD nMeshVertices = MeshData.pMesh->GetNumVertices();
DWORD nMeshFaces = MeshData.pMesh->GetNumFaces();
/*頂点バッファを作成*/
pD3DX9->CreateVertexBuffer( Desc.Size, 0, MeshData.pMesh->GetFVF(), D3DPOOL_MANAGED, &m_pMeshVB, NULL );
/*インデックスバッファを作成*/
pD3DX9->CreateIndexBuffer( nMeshFaces * 3 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pMeshIndex, NULL );
/*頂点バッファをコピー*/
pVB->Lock(0,0,(void**)&pSrc,0);
m_pMeshVB->Lock(0,0,(void**)&pDest,0);
CopyMemory( pDest, pSrc, Desc.Size );
pVB->Unlock();
pVB->Release();
m_pMeshVB->Unlock();
/*インデックスのコピー*/
MeshData.pMesh->GetIndexBuffer( &pSrcIndex );
pSrcIndex->Lock( 0, 0, (void**)&pISrc, 0 );
m_pMeshIndex->Lock( 0, 0, (void**)&pIDest, 0 );
CopyMemory( pIDest, pISrc, nMeshFaces * 3 * sizeof( WORD ) );
pSrcIndex->Unlock();
m_pMeshIndex->Unlock();
pSrcIndex->Release();
return true;
}
示例9: GenOctreeFaceIndex
void GdsNode::GenOctreeFaceIndex()
{
if ( !m_bUseOctree )
return;
RENDER_OBJECT_CONTAINER::iterator it = m_list_RenderObject.begin();
for ( ; it != m_list_RenderObject.end() ; ++it )
{
LPDWORD pIB;
GdsRenderObject* rendertoken = it->first;
LPDIRECT3DINDEXBUFFER9 pI = rendertoken->GetIndexBuffer();
if( SUCCEEDED( pI->Lock( 0 , 0 , (void**)&pIB , 0 ) ) )
{
int iMaxCountIndex = genTriIndex( m_pOctreeRootNode , pIB , 0 );
rendertoken->SetIndexMaxCount( iMaxCountIndex );
}
pI->Unlock();
}
}
示例10: D3DXCreateMeshFVF
//
// Creates a DirectX mesh
void DirectX::Mesh::create( void* vertexBuffer, void* indexBuffer, unsigned long FVF, unsigned int nVertices, unsigned int nFaces, unsigned long options )
{
// Calculate vertex stride
int vertexStride =
((FVF|D3DFVF_XYZ) == FVF) * 12 +
((FVF|D3DFVF_XYZRHW) == FVF) * 12 +
((FVF|D3DFVF_XYZB1) == FVF) * 12 +
((FVF|D3DFVF_XYZB2) == FVF) * 12 +
((FVF|D3DFVF_XYZB3) == FVF) * 12 +
((FVF|D3DFVF_XYZB4) == FVF) * 12 +
((FVF|D3DFVF_XYZB5) == FVF) * 12 +
((FVF|D3DFVF_XYZW) == FVF) * 12 +
((FVF|D3DFVF_NORMAL) == FVF) * 12 +
((FVF|D3DFVF_DIFFUSE) == FVF) * 4 +
((FVF|D3DFVF_SPECULAR) == FVF) * 4 +
((FVF|D3DFVF_TEX1) == FVF) * 8 +
((FVF|D3DFVF_TEX2) == FVF) * 8 +
((FVF|D3DFVF_TEX3) == FVF) * 8 +
((FVF|D3DFVF_TEX4) == FVF) * 8 +
((FVF|D3DFVF_TEX5) == FVF) * 8 +
((FVF|D3DFVF_TEX6) == FVF) * 8 +
((FVF|D3DFVF_TEX7) == FVF) * 8 +
((FVF|D3DFVF_TEX8) == FVF) * 8;
// Create mesh of sufficient size to store vertex/index buffer data
HRESULT hr = D3DXCreateMeshFVF( nFaces, nVertices, options, FVF, DirectX::Manager::instance( )->getD3DDev( ), &m_mesh );
if( hr ) MessageBox( NULL, L"Call to D3DXCreateMeshFVF has failed.", L"DirectX Engine", NULL );
LPDIRECT3DVERTEXBUFFER9 vb; LPDIRECT3DINDEXBUFFER9 ib; m_mesh->GetVertexBuffer( &vb ); m_mesh->GetIndexBuffer( &ib );
// Lock the ibuffer and load the indices
char* pVertices; vb->Lock( NULL, NULL, (void**)&pVertices, D3DLOCK_DISCARD );
memcpy( pVertices, vertexBuffer, nVertices*vertexStride ); vb->Unlock( );
// Lock the vbuffer and load the vertices
char* pIndices; ib->Lock( NULL, NULL, (void**)&pIndices, D3DLOCK_DISCARD );
memcpy( pIndices, indexBuffer, nFaces*3*sizeof(short) ); ib->Unlock( );
// Register with the manager
if( !(options&D3DXMESH_SYSTEMMEM) )
DirectX::Manager::instance( )->addResource( this );
}
示例11: InitIB
/**-----------------------------------------------------------------------------
* 인덱스 버퍼 초기화
*------------------------------------------------------------------------------
*/
HRESULT InitIB()
{
if( FAILED( g_pd3dDevice->CreateIndexBuffer( (g_cxHeight-1)*(g_czHeight-1)*2 * sizeof(MYINDEX), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIB, NULL ) ) )
{
return E_FAIL;
}
MYINDEX i;
MYINDEX* pI;
if( FAILED( g_pIB->Lock( 0, (g_cxHeight-1)*(g_czHeight-1)*2 * sizeof(MYINDEX), (void**)&pI, 0 ) ) )
return E_FAIL;
for ( DWORD z = 0; z < g_czHeight - 1; z++ )
{
for ( DWORD x = 0; x < g_cxHeight - 1; x++ )
{
i._0 = static_cast<WORD>( z*g_cxHeight + x );
i._1 = static_cast<WORD>( z*g_cxHeight + x + 1 );
i._2 = static_cast<WORD>( ( z + 1 )*g_cxHeight + x );
*pI++ = i;
i._0 = static_cast<WORD>( ( z + 1 )*g_cxHeight + x );
i._1 = static_cast<WORD>( z*g_cxHeight + x + 1 );
i._2 = static_cast<WORD>( ( z + 1 )*g_cxHeight + x + 1 );
*pI++ = i;
}
}
g_pIB->Unlock();
return S_OK;
}
示例12: ObjectInit
/************************************************************************
* Objects such as vertex buffer, index buffer, fonts are initialized here
************************************************************************/
bool ObjectInit(HWND hwnd)
{
PlaySound(_T("阿兰 - 浴火重生.wav"), nullptr, SND_ASYNC | SND_FILENAME | SND_LOOP);
srand(unsigned(time(NULL)));
D3DXCreateFont(gPD3DDevice, 40, 0, 0, 0, 0, 0, 0, 0, 0, _T("楷体"), &gPFont);
//////////////////////////////////////////////////////////////////////////
// Fill in the vertex struct
//////////////////////////////////////////////////////////////////////////
CUSTOM_VERTEX vertices[17];
vertices[0].x = 400.0f;
vertices[0].y = 300.0f;
vertices[0].z = 0.0f;
vertices[0].rhw = 1.0f;
vertices[0].color = D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256);
for (int i = 1; i < 17; i++)
{
vertices[i].x = gRadius*cos(PI*(i - 1)/ 8) + vertices[0].x;
vertices[i].y = gRadius*sin(PI*(i - 1)/ 8) + vertices[0].y;
vertices[i].z = 0.0f;
vertices[i].rhw = 1.0f;
vertices[i].color = D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256);
}
gPD3DDevice->CreateVertexBuffer(17 * sizeof(CUSTOM_VERTEX), 0, D3DFVF_CUSTOM_VERTEX, D3DPOOL_DEFAULT,
&gPVertexBuffer, nullptr);
void* pVertices{0};
gPVertexBuffer->Lock(0, 17 * sizeof(CUSTOM_VERTEX), (void**)&pVertices, 0);
memcpy(pVertices, vertices, 17 * sizeof(CUSTOM_VERTEX));
gPVertexBuffer->Unlock();
//////////////////////////////////////////////////////////////////////////
// Fill in the index struct
//////////////////////////////////////////////////////////////////////////
int indexes[48];
for (int i = 0; i < 16; i++)
{
indexes[i * 3] = 0;
indexes[i * 3 + 1] = i + 1;
indexes[i * 3 + 2] = i + 2;
}
indexes[47] = 1;
gPD3DDevice->CreateIndexBuffer(48 * sizeof(int), 0, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &gPIndexBuffer, nullptr);
int* pIndexes{0};
gPIndexBuffer->Lock(0, 0, (void**)&pIndexes, 0);
memcpy(pIndexes, indexes, 48 * sizeof(int));
gPIndexBuffer->Unlock();
return true;
}
示例13: ProcessFrustumCull
/**-----------------------------------------------------------------------------
* Frustum Culling을 사용해서 그려질 인덱스 생성
*------------------------------------------------------------------------------
*/
HRESULT ProcessFrustumCull()
{
DWORD i[4]; // 임시로 저장할 인덱스 정보
BOOL b[4]; // 임시로 저장할 frustum culling결과값
MYINDEX idx;
MYINDEX* pI;
if ( FAILED( g_pIB->Lock( 0, ( g_cxHeight - 1 )*( g_czHeight - 1 ) * 2 * sizeof( MYINDEX ), (void**)&pI, 0 ) ) )
{
return E_FAIL;
}
g_nTriangles = 0;
for( DWORD z = 0 ; z < g_czHeight-1 ; z++ )
{
for( DWORD x = 0 ; x < g_cxHeight-1 ; x++ )
{
i[0] = (z*g_cxHeight+x); // 좌측 상단
i[1] = (z*g_cxHeight+x+1); // 우측 상단
i[2] = ((z+1)*g_cxHeight+x); // 좌측 하단
i[3] = ((z+1)*g_cxHeight+x+1); // 우측 하단
b[0] = g_pFrustum->IsIn( &g_pvHeightMap[ i[0] ] ); // 좌측상단 정점이 Frustum안에 있는가?
b[1] = g_pFrustum->IsIn( &g_pvHeightMap[ i[1] ] ); // 우측상단 정점이 Frustum안에 있는가?
b[2] = g_pFrustum->IsIn( &g_pvHeightMap[ i[2] ] ); // 좌측하단 정점이 Frustum안에 있는가?
if ( b[0] | b[1] | b[2] ) // 셋중에 하나라도 frustum안에 있으면 렌더링한다.
{
idx._0 = static_cast<WORD>( i[0] );
idx._1 = static_cast<WORD>( i[1] );
idx._2 = static_cast<WORD>( i[2] );
*pI++ = idx;
g_nTriangles++; // 렌더링할 삼각형 개수 증가
}
b[2] = g_pFrustum->IsIn( &g_pvHeightMap[ i[2] ] ); // 좌측하단 정점이 Frustum안에 있는가?
b[1] = g_pFrustum->IsIn( &g_pvHeightMap[ i[1] ] ); // 우측상단 정점이 Frustum안에 있는가?
b[3] = g_pFrustum->IsIn( &g_pvHeightMap[ i[3] ] ); // 우측하단 정점이 Frustum안에 있는가?
if ( b[2] | b[1] | b[3] ) // 셋중에 하나라도 frustum안에 있으면 렌더링한다.
{
idx._0 = static_cast<WORD>( i[2] );
idx._1 = static_cast<WORD>( i[1] );
idx._2 = static_cast<WORD>( i[3] );
*pI++ = idx;
g_nTriangles++;
}
}
}
g_pIB->Unlock();
return S_OK;
}
示例14: init_graphics
// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(g_Sim.numPoints()*sizeof(CUSTOMVERTEX),
D3DUSAGE_WRITEONLY,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);
d3ddev->CreateVertexBuffer(5*sizeof(CUSTOMVERTEX),
D3DUSAGE_WRITEONLY,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_bordbuffer,
NULL);
d3ddev->CreateIndexBuffer(g_Sim.numConstraints() * 2 * sizeof(short),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&i_buffer,
NULL);
HRESULT hr = D3DXCreateFont(d3ddev, 17, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier New"), &font );
CUSTOMVERTEX* verts;
v_bordbuffer->Lock(0, 0, (void**)&verts, 0);
verts[0].X = MINX;
verts[0].Y = MINY;
verts[1].X = MINX;
verts[1].Y = MAXY;
verts[2].X = MAXX;
verts[2].Y = MAXY;
verts[3].X = MAXX;
verts[3].Y = MINY;
verts[4].X = MINX;
verts[4].Y = MINY;
verts[0].Z = verts[1].Z = verts[2].Z = verts[3].Z = verts[4].Z = 0.0f;
verts[0].COLOR = verts[1].COLOR = verts[2].COLOR = verts[3].COLOR = verts[4].COLOR = D3DCOLOR_XRGB(127, 127, 127);
v_bordbuffer->Unlock();
short* indices;
i_buffer->Lock(0, 0, (void**)&indices, 0);
for (unsigned i = 0; i < g_Sim.numConstraints(); i++) {
const std::pair<unsigned, unsigned>& p = g_Sim.constraint(i);
indices[2 * i] = p.first;
indices[2 * i + 1] = p.second;
}
i_buffer->Unlock();
}
示例15: LoadMesh
void LoadMesh(const PMDLoader::DATA *_data)
{
LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device;
HRESULT hr;
// 頂点バッファの作成
m_MaxVertex = _data->vert_count.u;
hr = device->CreateVertexBuffer(
sizeof(Vertex3D::VERTEX) * _data->vert_count.u,
D3DUSAGE_WRITEONLY, // 頂点バッファの使用方法
Vertex3D::FVF, // 使用する頂点フォーマット
D3DPOOL_MANAGED, // バッファを保持するメモリクエストを指定
&m_VertexBuffer, // 頂点のバッファの先頭アドレス
NULL );
Vertex3D::VERTEX *vtx;
hr = m_VertexBuffer->Lock(0,0,(void**)&vtx,0);
for( unsigned int i = 0; i < _data->vert_count.u ; i++)
{
vtx[i].pos.x = _data->vertex[i].pos[0].f;
vtx[i].pos.y = _data->vertex[i].pos[1].f;
vtx[i].pos.z = -_data->vertex[i].pos[2].f;
vtx[i].nor.x = _data->vertex[i].normal_vec[0].f;
vtx[i].nor.y = _data->vertex[i].normal_vec[1].f;
vtx[i].nor.z = -_data->vertex[i].normal_vec[2].f;
vtx[i].tex.x = _data->vertex[i].uv[0].f;
vtx[i].tex.y = _data->vertex[i].uv[1].f;
}
hr = m_VertexBuffer->Unlock();
// インデックスバッファの作成
m_MaxIndex = _data->face_vert_count.u;
hr = device->CreateIndexBuffer(
sizeof( WORD ) * m_MaxIndex, // バッファサイズ
D3DUSAGE_WRITEONLY, // 頂点バッファの使用方法
D3DFMT_INDEX16, // 使用する頂点フォーマット
D3DPOOL_MANAGED, // バッファを保持するメモリクエストを指定
&m_IndexBuffer, // 頂点インデックスのバッファの先頭アドレス
NULL );
WORD *idx;
hr = m_IndexBuffer->Lock(0,0,(void**)&idx,0);
for( unsigned int i=0; i < _data->face_vert_count.u ; i++)
{
idx[i] = _data->face_vert_index[i].u;
}
hr = m_IndexBuffer->Unlock();
}