Original Post
Hi. I still have some troubles with cubemapping. It seems not to be a difficoult bug but I really cant find it. Any suggestions are very appreciated This is how my cubemap should appear
And this is how it appears
Note how it seems deformed... you can clearly see the faces of the cubemap!! I use this piece of code for updating the map
And this is how it appears
Note how it seems deformed... you can clearly see the faces of the cubemap!! I use this piece of code for updating the map //-------------------------------------------------------------------------------
// Name: CD3D::ReflectionUpdate()
// Desc: Update a reflection
// Params: Index - Object index (IN)
// Position - Position where the reflection is calculated (IN). NOTE:
// this is usually the position of the object that reflects.
// Return: Operation result
//-------------------------------------------------------------------------------
HRESULT CD3D::ReflectionUpdate ( DWORD Index, D3DXVECTOR3 Position )
{
CReflection* pCRefl;
// Select the reflection
if ( ( Index >= 0 ) && ( Index < pReflectionList->ListCount() ) )
{
pReflectionList->Return ( &pCRefl, Index );
// Save transformation matrices of the device
D3DXMATRIX matProjSave, matViewSave;
pd3dDevice->GetTransform(D3DTS_VIEW, &matViewSave);
pd3dDevice->GetTransform(D3DTS_PROJECTION, &matProjSave);
// Store the current back buffer
LPDIRECT3DSURFACE9 pBackBuffer;
pd3dDevice->GetRenderTarget( 0, &pBackBuffer);
// The projection matrix has a FOV of 90 degrees and asp ratio of 1
D3DXMATRIXA16 mProj;
D3DXMatrixPerspectiveFovLH( &Matrices.matProj, D3DX_PI*0.5f, 1.0f, 1.f, Matrices.fViewDistance );
D3DXMATRIXA16 mViewDir = D3DXMATRIXA16( Matrices.matView );
mViewDir._41 = mViewDir._42 = mViewDir._43 = 0.0f;
// Loop through the six faces of the cube map
for( DWORD dwFace=0; dwFace<6; dwFace++ )
{
// Standard view that will be overridden below
D3DXVECTOR3 vEnvEyePt = Position;
D3DXVECTOR3 vLookDir, vUpDir;
switch(dwFace)
{
case D3DCUBEMAP_FACE_POSITIVE_X:
vLookDir = D3DXVECTOR3( 1.0f, 0.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
break;
case D3DCUBEMAP_FACE_NEGATIVE_X:
vLookDir = D3DXVECTOR3(-1.0f, 0.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
break;
case D3DCUBEMAP_FACE_POSITIVE_Y:
vLookDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
break;
case D3DCUBEMAP_FACE_NEGATIVE_Y:
vLookDir = D3DXVECTOR3( 0.0f,-1.0f, 0.0f );
vUpDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
break;
case D3DCUBEMAP_FACE_POSITIVE_Z:
vLookDir = D3DXVECTOR3( 0.0f, 0.0f, 1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
break;
case D3DCUBEMAP_FACE_NEGATIVE_Z:
vLookDir = D3DXVECTOR3( 0.0f, 0.0f,-1.0f );
vUpDir = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
break;
}
// Set the view transform for this cubemap surface
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH( &matView, &vEnvEyePt, &vLookDir, &vUpDir );
D3DXMatrixMultiply( &matView, &mViewDir, &matView );
pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
// Get pointer to surface in order to render to it
LPDIRECT3DSURFACE9 pFace;
pCRefl->pCubeMap->GetCubeMapSurface((D3DCUBEMAP_FACES)dwFace, 0, &pFace);
pd3dDevice->SetRenderTarget (0, pFace);
SAFE_RELEASE(pFace);
pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0L );
pd3dDevice->BeginScene();
// Render scene to texture
DWORD IndexArray[MAXREFLOBJNUM];
for( DWORD i = 0; i < pCRefl->dwNumReflMeshes; i++ )
IndexArray = *(pCRefl->ppReflMeshesIndexes);
MeshRender ( IndexArray, pCRefl->dwNumReflMeshes );
IndexArray[MAXREFLOBJNUM];
for( DWORD i = 0; i < pCRefl->dwNumReflBillboards; i++ )
IndexArray = *(pCRefl->ppReflBillboardsIndexes);
BillboardRender ( IndexArray, pCRefl->dwNumReflBillboards );
pd3dDevice->EndScene();
}
// Change the render target back to the main back buffer.
pd3dDevice->SetRenderTarget(0, pBackBuffer);
SAFE_RELEASE(pBackBuffer);
// Restore the original transformation matrices
pd3dDevice->SetTransform(D3DTS_VIEW, &matViewSave);
pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProjSave);
return S_OK;
}
return E_INVALIDARG;
}