Game Development Reference
In-Depth Information
hr = DXUTGetD3D11Device()->CreateBuffer( &bd, &InitData, &m_pVertexBuffer );
SAFE_DELETE(pVertices);
if( FAILED( hr ) )
return hr;
// Loop through the grid squares and calc the values
// of each index. Each grid square has two triangles:
//
//
A-B
//
|/|
//
C-D
WORD *pIndices = GCC_NEW WORD[m_sides *2*3];
WORD *current = pIndices;
for (DWORD i=0; i<m_sides; ++i)
{
// Triangle #1 ACB
*(current) = WORD(i*4);
*(current+1) = WORD(i*4 + 2);
*(current+2) = WORD(i*4 + 1);
// Triangle #2 BCD
*(current+3) = WORD(i*4 + 1);
*(current+4) = WORD(i*4 + 2);
*(current+5) = WORD(i*4 + 3);
current+=6;
}
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(WORD) * m_sides *2*3; //// each side has 2 triangles
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = pIndices;
hr = DXUTGetD3D11Device()->CreateBuffer( &bd, &InitData, &m_pIndexBuffer );
SAFE_DELETE_ARRAY(pIndices);
if( FAILED( hr ) )
return hr;
return S_OK;
}
The vertex buffer is created first using the rotation transformations; then the index
buffer is created. This code is actually very similar to what you saw in Chapter 14
to create the index buffer for the grid object. If you have trouble visualizing it, it
Search WWH ::




Custom Search