Original Post
Hello forum! I’m trying to get reflections to work in DX9 and I’m having a bit of a problem. Right now my test code is in a modified D3D sample app. I’m using a right handed coordinate system with Z up and all I’m interested in is getting the little triangle to render both reflected and not reflected. When that’s done I’ll set up the render target and everything else but for now I just want to see the little polygon get reflected :). This is how I’m setting up the reflection. I call this once with reflect true and then draw the triangle, then again with reflect false and render it again. The non reflected poly is drawn spinning around the Y-Axis which is pointing away from the near plane. The reflected poly is not drawn at all. If I set the reflection plane to D3DXPLANE plane(0.0f, 1.0f, 0.0f, 0.0f); I see the reflected poly but its definitely not correct. What is wrong with this picture? Isn’t the plane I want to reflect around the XY plane with normal 0,0,1?
void SetupMatrices( bool reflect )
{
UINT iTime = timeGetTime() % 10000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 10000.0f;
D3DXMATRIXA16 matWorld;
D3DXMatrixRotationY( &matWorld, fAngle );
D3DXVECTOR3 vEyePt( 0.0f, -10.0f, 3.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 0.0f, 1.0f );
D3DXMATRIXA16 matView;
D3DXMatrixLookAtRH( &matView, &vEyePt, &vLookatPt, &vUpVec );
if(reflect)
{
D3DXPLANE plane(0.0f, 0.0f, 1.0f, 0.0f);
D3DXMATRIXA16 matReflect;
D3DXMatrixReflect(&matReflect, &plane);
matView = matView * matReflect;
}
D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovRH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
// Turn off culling, so we see both original and reflected triangle
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
}