Graphics Reference
In-Depth Information
void* pVertices = NULL;
hr = pVB->Lock(0, 0, &pVertices, 0);
if(FAILED(hr))
{
SAFE_RELEASE(pVB);
return hr;
}
hr = D3DXComputeBoundingSphere((D3DXVECTOR3*)pVertices,
g_pMeshSysMem->GetNumVertices(),
D3DXGetFVFVertexSize(g_pMeshSysMem->GetFVF()), &g_vObjectCenter,
&g_fObjectRadius);
pVB->Unlock();
SAFE_RELEASE(pVB);
if(FAILED(hr))
return hr;
if(0 = = g_dwNumMaterials)
return E_INVALIDARG;
D3DXMatrixTranslation(&g_mCenterWorld, -g_vObjectCenter.x,
-g_vObjectCenter.y, -g_vObjectCenter.z);
//Change the current directory to the.x's directory so
//that the search can find the texture files.
GetCurrentDirectory(MAX_PATH, wszWorkingDir);
wszWorkingDir[MAX_PATH - 1] = L'\0';
SetCurrentDirectory(wszMeshDir);
//Get the array of materials out of the returned buffer, allocate a
//texture array, and load the textures
g_pMaterials = (D3DXMATERIAL*)g_pbufMaterials->GetBufferPointer();
g_ppTextures = new LPDIRECT3DTEXTURE9[g_dwNumMaterials];
for(UINT i = 0; i < g_dwNumMaterials; i++)
{
WCHAR strTexturePath[512] = Lā€ā€;
WCHAR* wszName;
WCHAR wszBuf[MAX_PATH];
wszName = wszBuf;
MultiByteToWideChar(CP_ACP, 0, g_pMaterials[i].pTextureFilename, -1,
wszBuf, MAX_PATH);
wszBuf[MAX_PATH - 1] = L'\0';
DXUTFindDXSDKMediaFileCch(strTexturePath, 512, wszName);
if(FAILED(D3DXCreateTextureFromFile(pd3dDevice, strTexturePath,
&g_ppTextures[i])))
g_ppTextures[i] = NULL;
}
SetCurrentDirectory(wszWorkingDir);
//Make sure there are normals, which are required for the
//tessellation enhancement.
if(!(g_pMeshSysMem->GetFVF() & D3DFVF_NORMAL))
{
ID3DXMesh* pTempMesh;
Search WWH ::




Custom Search