Sign in to follow this  

A question about cube map

Recommended Posts

This is function copyed from "Special effects game programming with directx" chapter 23 : 3D Water HRESULT CMyD3DApplication::CubeMapRender() { // Set the projection matrix for a field of view of 90 degrees D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/2, 1.0f, 0.5f, 100.0f ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); // Get the current view matrix, to concat it with the cubemap view vectors D3DXMATRIX matViewDir = m_Camera.GetViewMatrix(); matViewDir._41 = 0.0f; matViewDir._42 = 0.0f; matViewDir._43 = 0.0f; D3DXPLANE plane; plane.a = plane.b = plane.c = plane.d = 0.0f; D3DXMATRIX matFlip; D3DXMatrixReflect(&matFlip, &plane); D3DXMatrixMultiply(&matViewDir, &matFlip, &matViewDir); // Store the current backbuffer and zbuffer LPDIRECT3DSURFACE8 pBackBuffer, pZBuffer; m_pd3dDevice->GetRenderTarget( &pBackBuffer ); m_pd3dDevice->GetDepthStencilSurface( &pZBuffer ); // Render to the six faces of the cube map for( DWORD i=0; i<6; i++ ) { // Set the view transform for this cubemap surface D3DXMATRIX matView; matView = D3DUtil_GetCubeMapViewMatrix( (D3DCUBEMAP_FACES)i ); D3DXMatrixMultiply( &matView, &matViewDir, &matView ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); // Set the rendertarget to the i'th cubemap surface LPDIRECT3DSURFACE8 pCubeMapFace; m_pCubeMap->GetCubeMapSurface( (D3DCUBEMAP_FACES)i, 0, &pCubeMapFace ); m_pd3dDevice->SetRenderTarget( pCubeMapFace, m_pCubeFaceZBuffer); pCubeMapFace->Release(); m_pd3dDevice->BeginScene(); m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); CoreRender( FALSE, matView ); m_pd3dDevice->EndScene(); } m_pd3dDevice->SetTransform( D3DTS_VIEW, &m_Camera.GetViewMatrix()); // Change the rendertarget back to the main backbuffer m_pd3dDevice->SetRenderTarget( pBackBuffer, pZBuffer ); pBackBuffer->Release(); pZBuffer->Release(); return S_OK; } For each cube face, three matrices are concatenated to produce a proper view matrix. The purpose of the first matrix is to reflect the scene about the ground plane. But I just can`t understand the plane used in the code : all of the 4 factors are 0. I know that a, b, c forms the plane normal, but if they are all 0, what the plane is?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this