Original Post
I have got a snippet of code here from Microsoft sample program of cubic mapping. It looks too confusing to me. One major thing is that it sets different view and projection matrices when rendering the cube maps, why do they need to do that? Isn''t that true every model shares the same view and projection matrices? can any one explain the code to me in a little bit more detail?
I will be very gratful for any help!!!
HRESULT CMyD3DApplication::RenderSceneIntoEnvMap()
{
HRESULT hr;
// Set the projection matrix for a field of view of 90 degrees
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI * 0.5f, 1.0f, 0.5f, 1000.0f );
// Get the current view matrix, to concat it with the cubemap view vectors
D3DXMATRIX matViewDir( m_matView );
matViewDir._41 = 0.0f; matViewDir._42 = 0.0f; matViewDir._43 = 0.0f;
// Render the six cube faces into the environment map
if( m_pCubeMap )
hr = m_pRenderToEnvMap->BeginCube( m_pCubeMap );
else
hr = m_pRenderToEnvMap->BeginSphere( m_pSphereMap );
if(FAILED(hr))
return hr;
for( UINT i = 0; i < 6; i++ )
{
m_pRenderToEnvMap->Face( (D3DCUBEMAP_FACES) i );
// Set the view transform for this cubemap surface
D3DXMATRIX matView;
matView = D3DUtil_GetCubeMapViewMatrix( (D3DCUBEMAP_FACES) i );
D3DXMatrixMultiply( &matView, &matViewDir, &matView );
// Render the scene (except for the teapot)
RenderScene( &matView, &matProj, FALSE );
}
m_pRenderToEnvMap->End();
return S_OK;
}